I'm opening the AudioOutputUnit and setting that up
to write the audio out to a file. So one of the steps in
that process (the last one below), is to get the number
of frames in the audio buffers, using a simple
AudioUnitGetProperty, but for one particularly user of
my code, doing so fails with the
error kAudioUnitErr_InvalidProperty.
Is there another way I should be figuring out how big
to make the AudioBufferList?
Code mostly in its entirety just incase it's
something I did along the way:
// Open the AudioOutputUnit
description.componentType
= kAudioUnitType_Output;
description.componentSubType
= kAudioUnitSubType_HALOutput;
description.componentManufacturer
= kAudioUnitManufacturer_Apple;
description.componentFlags
= 0;
description.componentFlagsMask
= 0;
if ((component = FindNextComponent(NULL,
&description))) {
err = OpenAComponent(component,
&mAudioOutputUnit);
...
}
// Enable input on the AUHAL
param
= 1;
err = AudioUnitSetProperty(mAudioOutputUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, ¶m, sizeof(UInt32));
// Disable Output on the AUHAL
param
= 0;
err = AudioUnitSetProperty(mAudioOutputUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, ¶m, sizeof(UInt32));
// Set the current device to the default input unit.
err = AudioUnitSetProperty(mAudioOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &mInputDeviceID, sizeof(AudioDeviceID));
// Get the audio format of the input device
param = sizeof(AudioStreamBasicDescription);
err = AudioUnitGetProperty(mAudioOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 1, &mDeviceFormat, ¶m);
// Set the format the AudioOutputUnit will output data
in
...
err = AudioUnitSetProperty(mAudioOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &mOutputFormat, sizeof(AudioStreamBasicDescription));
// Get the number of frames in the IO buffer(s)
param
= sizeof(UInt32);
err = AudioUnitGetProperty(mAudioOutputUnit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, 0, &numFramesInBuffer,
¶m);
/********* FAILS WITH
kAudioUnitErr_InvalidProperty *****/
I'm asking for the number of frames in the buffers
because I use that to calculate how big the buffers that
I allocate should be. (number of bytes per frame *
number of frames in buffer). That comes straight out of
the Apple sample code: