【发布时间】: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