Mic*_*ael 3 avfoundation ios swift
我已阅读文档并了解使用detachNode"分离以前连接到音频引擎的音频节点".但是,我不确定分离音频节点的目的是什么.分离音频节点时会发生什么?它是什么意思?为什么需要分离音频节点?
有三种特定类型的节点:输出节点,混合器节点和播放器节点.
我们还有其他节点,但这些是初始构建块节点.
因此引擎是一个维护音频节点图形的对象.
您创建节点并将它们附加到引擎,然后使用引擎在这些不同的音频节点之间建立连接.
引擎将分析这些连接并确定哪些连接加入活动链.
然后,当您启动引擎时,音频将流经所有活动链.
引擎具有的一个强大功能是它允许您动态地重新配置这些节点.
这意味着在引擎渲染时,您可以添加新节点,然后将它们连接起来.
基本上你是动态地添加或删除链.
因此,引擎的典型工作流程是您创建引擎实例,创建要使用的所有节点的实例,将它们附加到引擎,以便引擎现在知道它们,然后将它们连接在一起,启动发动机.
这将创建一个活动的渲染线程,音频将流经所有活动链. 来自WWDC 2014
假设您想播放具有回声效果的声音,这就是代码的样子
var audioEngine = AVAudioEngine()
var echoNode = AVAudioUnitDelay()
echoNode.delayTime = NSTimeInterval(0.3)
var audioPlayerNode = AVAudioPlayerNode()
audioEngine.attachNode(audioPlayerNode)
// Attach the audio effect node corresponding to the user selected effect
audioEngine.attachNode(echoNode)
// Connect Player --> AudioEffect
audioEngine.connect(audioPlayerNode, to: echoNode, format: audioFile.processingFormat)
// Connect AudioEffect --> Output
audioEngine.connect(echoNode, to: audioEngine.outputNode, format: audioFile.processingFormat)
audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler:nil)
audioEngine.startAndReturnError(nil)
audioPlayerNode.play()
Run Code Online (Sandbox Code Playgroud)
然后,如果要使用混响效果播放音频:分离echo节点(使链无效),创建新的混响节点,再次连接节点以创建活动链.
audioEngine.detachNode(echoNode)
var reverbNode = AVAudioUnitReverb()
reverbNode.loadFactoryPreset( AVAudioUnitReverbPreset.Cathedral)
reverbNode.wetDryMix = 60
audioEngine.stop()
// Attach the audio effect node corresponding to the user selected effect
audioEngine.attachNode(reverbNode)
// Connect Player --> AudioEffect
audioEngine.connect(audioPlayerNode, to: reverbNode, format: audioFile.processingFormat)
// Connect AudioEffect --> Output
audioEngine.connect(reverbNode, to: audioEngine.outputNode, format: audioFile.processingFormat)
audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler:nil)
audioEngine.startAndReturnError(nil)
audioPlayerNode.play()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1403 次 |
| 最近记录: |