DanielGibbs
DanielGibbs

Reputation: 10190

How do you select audio input device in core audio?

I am writing a program that needs to deal with multiple audio inputs.

I am currently using AudioQueues to get the input, but this is only from the default input device.

Is there any way to either:

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?

Upvotes: 6

Views: 4870

Answers (2)

voidref
voidref

Reputation: 1123

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.

Upvotes: 3

lucius
lucius

Reputation: 8685

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.

Upvotes: 2

Related Questions