Selecting input mic for Mac Audio Queue Services?

2019-05-02 11:37发布

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.

3条回答
神经病院院长
2楼-- · 2019-05-02 12:12

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.

查看更多
Viruses.
3楼-- · 2019-05-02 12:13

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...

查看更多
Emotional °昔
4楼-- · 2019-05-02 12:28

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.

查看更多
登录 后发表回答