设置AVAudioEngine输入和输出设备 [英] Set AVAudioEngine Input and Output Devices

查看:115
本文介绍了设置AVAudioEngine输入和输出设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用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具有成员

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输入和输出设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆