【问题标题】:How to change pitch and rate at same exact time with AVAudioEngine如何使用 AVAudioEngine 在同一时间更改音高和速率
【发布时间】:2019-12-01 23:36:12
【问题描述】:

我使用 AVAudioEngine 来改变 Swift 中音频的音高和速率。

我想出了如何更改速度/速率并保持音高不变,但是当我这样做时,会出现一种音频故障,当您切换速率时,您可以听到音频音高快速调整(我猜因为代码首先改变了速率,然后改变了音高,听起来像原来的)

我想摆脱这种影响,同时改变音高和速率。这甚至可能吗?

W

    var engine : AVAudioEngine = AVAudioEngine()
    var speedControl : AVAudioUnitVarispeed = AVAudioUnitVarispeed()
    var pitchControl : AVAudioUnitTimePitch = AVAudioUnitTimePitch()

    // ...

    func changeTempo(to tempo: Float) {
        speedControl.rate = tempo

        // to keep the same pitch:
        let pitchChange = log2(speedControl.rate) * 1200.0
        pitchControl.pitch = pitchChange * -1
    }

【问题讨论】:

    标签: swift xcode multithreading avaudioengine


    【解决方案1】:

    你似乎忽略了AVAudioUnitTimePitch 可以同时做音高和时间。

    https://developer.apple.com/documentation/avfaudio/avaudiounittimepitch

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多