Re: Not Setting Format results in multichannel playback success
Re: Not Setting Format results in multichannel playback success
- Subject: Re: Not Setting Format results in multichannel playback success
- From: Doug Wyatt <email@hidden>
- Date: Sun, 9 Jul 2006 14:33:45 -0700
On Jul 8, 2006, at 09:17 , Mike Hanna wrote:
On 7-Jul-06, at 1:26 PM, Doug Wyatt wrote:
On Jul 6, 2006, at 23:24 , Mike Hanna wrote:
I finally have playback of multichannel audio with code based on
PlayFile.cpp.
Using AudioFileGetProperty(), I load a file into a buffer:
XThrowIfError (AudioFileGetProperty(fAudioFile,
kAudioFilePropertyDataFormat, &propsize, &fFileFormat),
"AudioFileGetProperty");
I could not get sound when playing a multichannel file; I thought
it was because I wasn't using SetFormat(), but it apparently it
causes an exception, of which kind I don't know:
http://paste.lisp.org/display/22194
/*** using SetFormat seems to cause an exception, any idea why? ***/
I finally decided to comment-out any code that calls
SetNumberChannels() or SetSampleRate(). Removing these results in
successful playback of multichannel audio, any idea why?
/*** commenting-out these lines results in successful playback of
multichannel audio, why? ***/
XThrowIfError( fFileAU.SetFormat( kAudioUnitScope_Input, 0,
fFileFormat ), "SetFormat" );
// printf ("makeGraph file in: ");
// XThrowIfError( fFileAU.SetFormat
( kAudioUnitScope_Output, 0, fFileFormat ), "SetFormat" );
// printf ("makeGraph file out: ");
These probably fail because fFileFormat is something other than
deinterleaved Float32.
I see, how do I convert the stream to deinterleaved Float32?
You don't have to worry about it; the conversion from the file's
format to deinterleaved native-endian Float32 happens internally to
AUFilePlayer (it uses ExtendedAudioFile).
// prepare the file AU for playback
// set its output channels
// XThrowIfError (fFileAU.SetNumberChannels
(kAudioUnitScope_Output, 0, fFileFormat.NumberChannels()),
"SetNumberChannels");
// set the output sample rate of the file AU to be the
same as the file:
// XThrowIfError (fFileAU.SetSampleRate
(kAudioUnitScope_Output, 0, fFileFormat.mSampleRate),
"SetSampleRate");
It's not clear why these should fail before connecting and
initialization. What's the error?
There is no error. If I leave these lines in, anything above 2-
channel audio plays silent.
What's the sample rate and channel count of the file? The hardware?
Sorry, I've misplaced your previous message -- what are you
connecting the file player to? Was it a time/pitch? If the file's
channel count does not match that of the AU you're connecting the
file player to, I'd expect to see an error in making that connection.
If it's a time/pitch, what happens if you remove it and connect the
file player directly to an output unit?
If there aren't any errors occurring, I'd probably debug this by
adding render callbacks to each of the AU's, including the output
unit, e.g. this excerpt from some code that'll be in the next SDK:
AudioUnitAddRenderNotify(theAU, RenderCallback, this);
static OSStatus RenderCallback( void * inRefCon,
AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList * ioData)
{
if (inBusNumber == 0 && (*ioActionFlags &
kAudioUnitRenderAction_PostRender)) {
CAAudioUnitOutputCapturer *This = (CAAudioUnitOutputCapturer *)
inRefCon;
ExtAudioFileWriteAsync(This->mExtAudioFile, inNumberFrames, ioData);
}
return noErr;
}
More simply you can inspect ioData -- print a few sample frames and
see what's there.
HTH,
Doug
--
Doug Wyatt
Core Audio, Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden