使用 audiokit 运行 断开耳机会导致 AKOperationEffect 出现 malloc 错误
Disconnecting headphones with audiokit running gives malloc error with AKOperationEffect specifically
// 我的代码如下
do{
file = try AKAudioFile(readFileName: "Sound1.mp3", baseDir: .resources)
// file = try AKAudioFile(forReading: SingletonClass.sharedInstance.recordedURLs[SingletonClass.sharedInstance.recordedURL]!)
// AKSettings.defaultToSpeaker = true
}
catch {
}
do {
player = try AKAudioPlayer(file : file)
}
catch {
}
let lfoAmplitude = 1_000
let lfoRate = 1.0 / 3.428
_ = 0.9
//filter section effect below
filterSectionEffect = AKOperationEffect(tracker) { input, _ in
let lfo = AKOperation.sineWave(frequency: lfoRate, amplitude: lfoAmplitude)
return input.moogLadderFilter(cutoffFrequency: lfo + cutoffFrequency,
resonance: resonance)
}
Audiokit.output = filterSectionEffect
Audiokit.start()
每当我使用带有代码 player.play 的按钮播放音频时,音频都能正常播放。如果我连接耳机,它也可以正常播放,但是一旦我断开耳机,我就会看到错误:
对于有线耳机和蓝牙耳机,情况都是一样的。
我的应用程序因为这个问题而卡住了,这也只发生在 AKOperationEffect
上。任何帮助,将不胜感激。
Kunal Verma 的评论是正确的,但为了完整起见,这里是修复它的提交。
https://github.com/AudioKit/AudioKit/commit/ffac4acbe93553764f6095011e9bf5d71fdc88c2
// 我的代码如下
do{
file = try AKAudioFile(readFileName: "Sound1.mp3", baseDir: .resources)
// file = try AKAudioFile(forReading: SingletonClass.sharedInstance.recordedURLs[SingletonClass.sharedInstance.recordedURL]!)
// AKSettings.defaultToSpeaker = true
}
catch {
}
do {
player = try AKAudioPlayer(file : file)
}
catch {
}
let lfoAmplitude = 1_000
let lfoRate = 1.0 / 3.428
_ = 0.9
//filter section effect below
filterSectionEffect = AKOperationEffect(tracker) { input, _ in
let lfo = AKOperation.sineWave(frequency: lfoRate, amplitude: lfoAmplitude)
return input.moogLadderFilter(cutoffFrequency: lfo + cutoffFrequency,
resonance: resonance)
}
Audiokit.output = filterSectionEffect
Audiokit.start()
每当我使用带有代码 player.play 的按钮播放音频时,音频都能正常播放。如果我连接耳机,它也可以正常播放,但是一旦我断开耳机,我就会看到错误:
对于有线耳机和蓝牙耳机,情况都是一样的。
我的应用程序因为这个问题而卡住了,这也只发生在 AKOperationEffect
上。任何帮助,将不胜感激。
Kunal Verma 的评论是正确的,但为了完整起见,这里是修复它的提交。
https://github.com/AudioKit/AudioKit/commit/ffac4acbe93553764f6095011e9bf5d71fdc88c2