23

背景 - 我在 Apple 最近的 WWDC 上发布的以下视频列表中看到了一个名为“实践中的 AVAudioEngine”的视频,用于将音效应用于音频。 https://developer.apple.com/videos/wwdc/2014/

之后,我成功地使用以下代码更改了音频的音高:

 //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 连接起来,然后我将其连接到输出。

我现在对在音频中添加多种音效感到好奇。例如,音高变化和混响。我将如何为音频添加多种音效?

另外,在 viewDidLoad 中附加和连接节点是否有意义,而不是我在 IBAction 中如何完成?

4

2 回答 2

13

只需将它们连接起来。

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)
于 2014-09-09T11:39:04.973 回答
6

背景 - 我从 Udacity 发布的以下视频列表中看到了一个名为“将所有内容放在一起 - 使用 Swift 进行 iOS 应用程序开发简介”的视频,以将音效应用于音频。

https://youtu.be/XiQfjaYJjuQ

之后,我成功地使用以下代码更改了音频的音高:

func playAudioWithVariablePith(pitch: Float){
        audioPlayer.stop()
        audioEngine.stop()
        audioEngine.reset()

        let audioPlayerNode = AVAudioPlayerNode()
        audioEngine.attachNode(audioPlayerNode)

        let changePitchEffect = AVAudioUnitTimePitch()
        changePitchEffect.pitch = pitch

        audioEngine.attachNode(changePitchEffect)

        audioEngine.connect(audioPlayerNode, to: changePitchEffect, format: nil)

        audioEngine.connect(changePitchEffect, to: audioEngine.outputNode, format: nil)

        audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)

        try! audioEngine.start()

        audioPlayerNode.play()

    }
于 2015-12-01T08:21:25.280 回答