Using sound effects with AudioEngine

后端 未结 2 451
情深已故
情深已故 2020-12-12 19:29

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

相关标签:
2条回答
  • 2020-12-12 20:07

    Background - I saw a video titled "Putting it all together - Intro to iOS App Development with Swift" from the following list of videos published at Udacity to apply sound effects to an audio.

    https://youtu.be/XiQfjaYJjuQ

    After that, I was successfully able to change the pitch of an audio with the following code:

    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()
    
        }
    
    0 讨论(0)
  • 2020-12-12 20:08

    Just connect them.

    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)
    
    0 讨论(0)
提交回复
热议问题