我正在编写一个需要处理多个音频输入的程序。
我目前正在使用 AudioQueues 来获取输入,但这仅来自默认输入设备。
有没有办法:
- 选择 AudioQueue 使用的输入设备。
- 更改默认输入设备。
我知道我可以在 Core-Audio 中使用 kAudioHardwarePropertyDevices 来获取输出设备列表,是否有类似的设备可以用于输入设备?
我正在编写一个需要处理多个音频输入的程序。
我目前正在使用 AudioQueues 来获取输入,但这仅来自默认输入设备。
有没有办法:
我知道我可以在 Core-Audio 中使用 kAudioHardwarePropertyDevices 来获取输出设备列表,是否有类似的设备可以用于输入设备?
我苦苦思索了一阵子如何做到这一点,终于弄明白了:
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;
}
如您所见,关键部分是使用 ScopeInput/ScopeOutput 参数值。
kAudioHardwarePropertyDevices
用于输出和输入设备。设备可以同时具有输入和输出通道,也可以只有输入或输出通道。
大多数 AudioDevice... 函数采用布尔 isInput 参数,以便您可以查询设备的输入端。