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开发者_JAVA百科 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.
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.
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...
If you set up the Audio Queue to read from the default input device, then it will read from the mic that is selected as default in the System Preferences->Soubd->Input tab.
精彩评论