kAudioDevicePropertyStreamConfiguration returns incorrect buffer size
kAudioDevicePropertyStreamConfiguration returns incorrect buffer size
- Subject: kAudioDevicePropertyStreamConfiguration returns incorrect buffer size
- From: Heath Raftery <email@hidden>
- Date: Wed, 18 May 2005 03:39:47 +1000
I've been struggling to set up an AUHAL to record sound from the
default system input device. I've now discovered that my
EXC_BAD_ACCESS's were due to a too small AudioBufferList, which I
relied on kAudioDevicePropertyStreamConfiguration to provide.
Specifically, from what I've read I hoped the following would set up my
buffer list the way it should be:
<CODE>
AudioDeviceGetPropertyInfo(fInputDeviceID, 0, YES,
kAudioDevicePropertyStreamConfiguration, &theSize, NULL);
fBufferList = (AudioBufferList *)malloc(theSize);
AudioDeviceGetProperty(fInputDeviceID, 0, YES,
kAudioDevicePropertyStreamConfiguration, &theSize, fBufferList);
</CODE>
A connection between fInputDeviceID, the default system input device,
and fInputUnit, has been made earlier:
<CODE>
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
&theSize, &fInputDeviceID);
AudioUnitSetProperty(fInputUnit,
kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0,
&fInputDeviceID, sizeof(fInputDeviceID));
</CODE>
And fInputUnit has been set up prior to that using:
<CODE>
ComponentDescription desc;
Component comp;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_HALOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
comp = FindNextComponent(NULL, &desc);
OpenAComponent(comp, &fInputUnit);
</CODE>
Instead, the fInputUnit has this format:
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x0000002B)
32-bit big-endian float, deinterleaved
but fBufferList only gets enough memory allocation to hold one
AudioBuffer, whose mNumberChannels is set to 1. I realised eventually,
that 2 channel, deinterleaved data should actually have two
AudioBuffers in the AudioBufferList, each of which has mNumberChannels
== 1. Allocating such a structure manually seems to work smoothly.
Why didn't kAudioDevicePropertyStreamConfiguration give me the right
buffer list, and how am I supposed to set the buffer list up in the
general case? I thought I found the answer in that the second parameter
of AudioDeviceGetProperty is the "channel", and so thought maybe I was
only getting information on the "first" channel. But the header file
states that for kAudioDevicePropertyStreamFormat (which I'm not using),
that
// Since formats are stream level
// entities, the number of channels returned with this property
actually
// refers to the number of channels in the stream containing the
requested
// channel. Consequently, it only gives a partial picture of the
overall
// number of channels for the device. Use
kAudioDevicePropertyStreamConfiguration
// to get the information on how the channels are divied up across the
streams.
And kAudioDevicePropertyStreamConfiguration (which I am using) states
that
// This property returns the stream configuration of the device in
// an AudioBufferList (with the buffer pointers set to NULL) which
// describes the list of streams and the number of channels in each
// stream.
Which in my interpretation, means that
kAudioDevicePropertyStreamConfiguration should give me information
about all the channels. Am I assuming incorrectly, that the format of
the InputDevice and InputUnit will match? I know I had to set the
sample rate of the InputUnit to that of the InputDevice, which suggests
that maybe the channel configuration also need not match by default.
How else then, can I get an accurate AudioBufferList? Create it
manually based on my AudioUnit format?
FYI, I think the device it is using is the iSight. Built in Audio on
this iMac G4 is the only other thing it could be.
Heath
_______________________________________________
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