Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting input mic for Mac Audio Queue Services?

I am currently using the Mac OS X Audio Queue Services API for audio recording and sound analysis. Works fine using the default mic input.

If there is more than one microphone plugged into the Mac (USB, headset jack, etc.), is there a way to programmatically enumerate and select which mic is to be used for audio input within an application? (e.g. not have to send the user to the system preferences panel, which may affect a users other audio applications.) If so, which APIs should be used to select the mic input.

like image 752
hotpaw2 Avatar asked May 31 '11 08:05

hotpaw2


2 Answers

To enumerate available input devices please see my answer to AudioObjectGetPropertyData to get a list of input devices.

Once you've determined the input device you'd like to use, you can set the kAudioQueueProperty_CurrentDevice property to the device's UID.

like image 193
sbooth Avatar answered Sep 29 '22 09:09

sbooth


I fear, no, because AQ is hard-coded to use default input (to my best knowledge). AQ is fairly limited and only iOS gives more control via AutoSessions. However, you can use AUHAL to record from an arbitrary device:

http://developer.apple.com/library/mac/#technotes/tn2091/_index.html

You won't need listing 4 from above because you'll use the AudioDeviceID for the device you have chosen (presumably by getting the list of devices using AudioObjectGetPropertyDataSize and picking the one you want).

FWIW: if you decide that's too much, you can presumably still use AudioHardwareSetProperty to set kAudioHardwarePropertyDefaultInputDevice from your code - not what you wanted but certainly less work...

like image 25
Simon Urbanek Avatar answered Sep 29 '22 10:09

Simon Urbanek