如何在核心音频中选择音频输入设备?

时间:2010-07-07 21:54:21

标签: audio core-audio audiotoolbox

我正在编写一个需要处理多个音频输入的程序。

我目前正在使用AudioQueues来获取输入,但这只是来自默认输入设备。

有没有办法:

  • 选择AudioQueues使用的输入设备。
  • 更改默认输入设备。

我知道我可以在Core-Audio中使用kAudioHardwarePropertyDevices来获取输出设备列表,是否有类似的输入设备可用?

2 个答案:

答案 0 :(得分:2)

kAudioHardwarePropertyDevices用于输出和输入设备。设备可以同时具有输入和输出通道,也可以只有输入或输出通道。

大多数AudioDevice ...函数都使用布尔isInput参数,以便您查询设备的输入端。

答案 1 :(得分:1)

我猛烈地反对如何做这一段时间,最后想出来:

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参数值。