我在寫一個需要處理多個音頻輸入的程序。如何在覈心音頻中選擇音頻輸入設備?
我目前使用AudioQueues來獲取輸入,但這只是從默認的輸入設備。
有要麼什麼辦法:
- 選擇哪個輸入設備的AudioQueues使用。
- 更改默認輸入設備。
我知道我可以在Core-Audio中使用kAudioHardwarePropertyDevices獲取輸出設備的列表,是否有類似的輸入設備可用?
我在寫一個需要處理多個音頻輸入的程序。如何在覈心音頻中選擇音頻輸入設備?
我目前使用AudioQueues來獲取輸入,但這只是從默認的輸入設備。
有要麼什麼辦法:
我知道我可以在Core-Audio中使用kAudioHardwarePropertyDevices獲取輸出設備的列表,是否有類似的輸入設備可用?
kAudioHardwarePropertyDevices
用於輸出和輸入設備。器件可以有輸入和輸出通道,也可以只有輸入或輸出通道。
大部分AudioDevice ...函數都帶有布爾isInput參數,以便您可以查詢設備的輸入端。
我撞我的頭靠在如何做到這一點了一會兒,終於想通了:
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;
}
正如你所看到的,關鍵部分是使用ScopeInput/ScopeOutput參數值。
謝謝!我只是發現kAudioHardwarePropertyDefaultInputDevice應該很好地完成這項工作。 不幸的是,AudioDevice函數已被棄用,所以我必須改用AudioObjectGetPropertyData,但是它沒有isInput的布爾值。任何想法如何區分使用這種方法的輸入和輸出設備? – DanielGibbs 2010-07-08 21:11:45
查看[技術說明TN2223](http://developer.apple.com/mac/library/technotes/tn2010/tn2223.html)「移除已棄用的HAL API」。我想你會設置'AudioObjectPropertyScope'來選擇輸入或輸出。 – lucius 2010-07-09 18:57:52
爲了區分輸入和輸出,從'AudioStreamID'獲取'AudioStreamID(選擇器:kAudioDevicePropertyStreams)'獲取通道方向選擇器:'kAudioStreamPropertyDirection'。方向0表示輸出通道,1表示輸入通道。 – Raviprakash 2010-07-13 04:36:19