使用AudioEngine的声音效果 [英] Using sound effects with AudioEngine
问题描述
背景 - 我在Apple最近的WWDC上发布的以下视频列表中看到了一个名为AVAudioEngine in Practice的视频,用于将声音效果应用于音频。
https://developer.apple.com/videos/wwdc/2014/
Background - I saw a video titled "AVAudioEngine in Practice" from the following list of videos published at Apple's recent WWDC to apply sound effects to an audio. https://developer.apple.com/videos/wwdc/2014/
之后,我成功地使用以下代码更改了音频的音高:
After that, I was successfully able to change the pitch of an audio with the following code:
//Audio Engine is initialized in viewDidLoad()
audioEngine = AVAudioEngine()
//The following Action is called on clicking a button
@IBAction func chipmunkPlayback(sender: UIButton) {
var pitchPlayer = AVAudioPlayerNode()
var timePitch = AVAudioUnitTimePitch()
timePitch.pitch = 1000
audioEngine.attachNode(pitchPlayer)
audioEngine.attachNode(timePitch)
audioEngine.connect(pitchPlayer, to: timePitch, format: myAudioFile.processingFormat)
audioEngine.connect(timePitch, to: audioEngine.outputNode, format: myAudioFile.processingFormat)
pitchPlayer.scheduleFile(myAudioFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(&er)
pitchPlayer.play()
}
根据我的理解,我使用AudioEngine将AudioPlayerNode与AudioEffect连接,而AudioEffect又连接到输出。
From what I understand, I used the AudioEngine to attach the AudioPlayerNode with the AudioEffect, which I in turn attached to the Output.
我现在很想知道为音频添加多种音效。例如,音高变化和混响。我如何为音频添加多个声音效果?
I am now curious about adding multiple sound effects to the audio. For instance, pitch change AND reverb. How would I go about adding multiple sound effects to the audio?
此外,在viewDidLoad中连接和连接节点是否有意义,而不是我在这里完成的方式在IBAction中?
Also, would it make sense to attach and connect the nodes in viewDidLoad rather than how I have done it here in an IBAction ?
推荐答案
只需连接它们。
engine.connect(playerNode, to: reverbNode, format: format)
engine.connect(reverbNode, to: distortionNode, format: format)
engine.connect(distortionNode, to: delayNode, format: format)
engine.connect(delayNode, to: mixer, format: format)
这篇关于使用AudioEngine的声音效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!