问题描述
我一直在使用Apple闪亮的新AVFoundation
库,但是到目前为止,我还无法设置AVAudioEngine
使用的输入或输出设备(例如USB声卡),我可以似乎在文档中找不到任何东西说甚至有可能.
I've been playing around with Apple's shiny new AVFoundation
library, but so far I've unable to set the input or output devices (e.g. a USB sound card) used by an AVAudioEngine
, and I can't seem to find anything in the documentation to say it's even possible.
有人对此有任何经验吗?
Does anyone have any experience with this?
推荐答案
好,在第十次重新阅读文档之后,我注意到AVAudioEngine
具有成员 inputNode 和 outputNode (不确定如何我错过了!).
Ok, after re-reading the docs for the 10th time, I noticed AVAudioEngine
has members inputNode and outputNode (not sure how I missed that!).
以下代码似乎可以完成这项工作:
The following code seems to do the job:
AudioDeviceID inputDeviceID = 53; // get this using AudioObjectGetPropertyData
AVAudioEngine *engine = [[AVAudioEngine alloc] init];
AudioUnit audioUnit = [[engine inputNode] audioUnit];
OSStatus error = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0,
&inputDeviceID,
sizeof(inputDeviceID));
我从 CAPlayThrough 示例.
这篇关于设置AVAudioEngine输入和输出设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!