Using Apple's new AudioEngine to change Pitch of AudioPlayer sound

前端 未结 1 588
生来不讨喜
生来不讨喜 2021-02-01 09:50

I am currently trying to get Apple\'s new audio engine working with my current audio setup. Specifically, I am trying to change the pitch with Audio Engine, which apparently is

1条回答
  •  无人及你
    2021-02-01 09:57

    You use an AVAudioPlayerNode, not an AVAudioPlayer.

    engine = AVAudioEngine()
    playerNode = AVAudioPlayerNode()
    engine.attachNode(playerNode)
    

    Then you can attach an AVAudioUnitTimePitch.

    var mixer = engine.mainMixerNode;
    auTimePitch = AVAudioUnitTimePitch()
    auTimePitch.pitch = 1200 // In cents. The default value is 1.0. The range of values is -2400 to 2400
    auTimePitch.rate = 2 //The default value is 1.0. The range of supported values is 1/32 to 32.0.
    engine.attachNode(auTimePitch)
    engine.connect(playerNode, to: auTimePitch, format: mixer.outputFormatForBus(0))
    engine.connect(auTimePitch, to: mixer, format: mixer.outputFormatForBus(0))
    

    0 讨论(0)
提交回复
热议问题