6

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:

  • 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?

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
DanielGibbs
  • 9,910
  • 11
  • 76
  • 121

2 Answers2

3

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.

voidref
  • 1,113
  • 11
  • 15
2

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.

lucius
  • 8,665
  • 3
  • 34
  • 41
  • 1
    Thanks! I just found kAudioHardwarePropertyDefaultInputDevice which should do the job nicely. Unfortunately the AudioDevice functions are deprecated so I have to use AudioObjectGetPropertyData instead, but that doesn't have a boolean for isInput. Any idea how to distinguish from input and output devices using this method? – DanielGibbs Jul 08 '10 at 21:11
  • 1
    Take a look at [Tech Note TN2223](http://developer.apple.com/mac/library/technotes/tn2010/tn2223.html) "Moving Off Deprecated HAL APIs". I think you'd set `AudioObjectPropertyScope` to select input or output. – lucius Jul 09 '10 at 18:57
  • 2
    To distinguish between input and output , get the `AudioStreamID(selector:kAudioDevicePropertyStreams)` from `AudioStreamID` get channel direction selector:`kAudioStreamPropertyDirection`. The direction 0 indicates output channel and 1 indicates input channel. – Raviprakash Jul 13 '10 at 04:36
  • The tech note mentioned by @lucius [has moved here](https://developer.apple.com/library/archive/technotes/tn2223/_index.html) – Grumdrig Aug 08 '19 at 21:57