I am writing a program that needs to deal with multiple audio inputs.
I am currently using AudioQueues to get the input, but thi开发者_如何学运维s is only from the default input device.
Is there any way to either:
- Select which input device the AudioQueues use.
- Change the default input device.
I know that I can use kAudioHardwarePropertyDevices in Core-Audio to get a list of output devices, is there a similar one I can use for input devices?
I banged my head against how to do this for a while, and finally figured it out:
BOOL isMic = NO;
BOOL isSpeaker = NO;
AudioDeviceID device = audioDevices[i];
// Determine direction of the device by asking for the number of input or
// output streams.
propertyAddress.mSelector = kAudioDevicePropertyStreams;
propertyAddress.mScope = kAudioDevicePropertyScopeInput;
UInt32 dataSize = 0;
OSStatus status = AudioObjectGetPropertyDataSize(device,
&propertyAddress,
0,
NULL,
&dataSize);
UInt32 streamCount = dataSize / sizeof(AudioStreamID);
if (streamCount > 0)
{
isMic = YES;
}
propertyAddress.mScope = kAudioDevicePropertyScopeOutput;
dataSize = 0;
status = AudioObjectGetPropertyDataSize(device,
&propertyAddress,
0,
NULL,
&dataSize);
streamCount = dataSize / sizeof(AudioStreamID);
if (streamCount > 0)
{
isSpeaker = YES;
}
As you can see, the key part is to use the ScopeInput/ScopeOutput parameter values.
kAudioHardwarePropertyDevices
is used for both output and input devices. Devices can have both input and output channels, or can have only input or output channels.
Most of the AudioDevice... functions take a Boolean isInput parameter so that you ca query the input side of the device.
精彩评论