我使用 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
}
最佳答案
您似乎忽略了 AVAudioUnitTimePitch
可以同时进行音高和时间。
https://developer.apple.com/documentation/avfaudio/avaudiounittimepitch
https://stackoverflow.com/questions/57172346/
相关文章:
angular - ionic 4 : Ion-checkbox checked not updat
firebase - 我应该使用 Firebase 动态链接而不是通用链接和应用链接吗?
php - 在电子邮件中添加 PhpSpreadsheet 附件
npm - 在私有(private)网络上托管 github 发布
c# - Process.Start 无法正确运行批处理文件
node.js - TransferHttpCacheModule 不会阻止 Angular 8 中
amazon-web-services - 使用 aws sts assume-role 配置 AW