简体   繁体   English

AVFoundation / AudioKit 播放低频声音会产生咔嗒声/爆音

[英]AVFoundation / AudioKit Playing a low frequency sound produces click/pop

I'm creating a sort of drum pad app, and it seems like AKPlayer is the best of many classes available in AudioKit for playing my samples.我正在创建一种鼓垫应用程序,似乎 AKPlayer 是 AudioKit 中用于播放我的样本的许多类中最好的。

Trouble is, when I start playing a low-frequency (bass note) sample, there's always a clicking sound (or "pop") when playing the sample!问题是,当我开始播放低频(低音)样本时,播放样本时总是会发出咔哒声(或“爆音”)!

This can be easily heard by running an unmodified "Mixing Nodes" demo from the AudioKit Playgrounds.这可以通过从 AudioKit Playgrounds 运行未经修改的“混合节点”演示轻松听到。 Turn down the volume on everything but the Bass, and you'll notice the clicking every time the Bass sample loops.调低除贝司以外的所有设备的音量,您会注意到每次贝司样本循环时都会发出咔哒声。

I also tested the issue with AVFoundation and it is the case too.我还用AVFoundation测试了这个问题,情况也是如此。 This only happens with low frequency sounds like bass.这只发生在低频声音(如低音)中。 Lead and other sounds dont produce this.铅和其他声音不会产生这种情况。 I also tested with my own bass sample and same issue was here.我还用我自己的贝司样本进行了测试,同样的问题也在这里。

Here is the code for both:这是两者的代码:

import AudioKitPlaygrounds
import AudioKit

import AVFoundation


//: This section prepares the players
let drumFile = try AKAudioFile(readFileName: "drum.wav")
let bassFile = try AKAudioFile(readFileName: "bass.wav")
let guitarFile = try AKAudioFile(readFileName: "guitar.wav")
let leadFile = try AKAudioFile(readFileName: "lead.wav")

var drums = AKPlayer(audioFile: drumFile)
var bass = AKPlayer(audioFile: bassFile)
var guitar = AKPlayer(audioFile: guitarFile)
var lead = AKPlayer(audioFile: leadFile)

bass.play() // will produce click/pop
guitar.play() // will not produce click/pop, only low frequency samples produce click


let path = Bundle.main.path(forResource: "3", ofType:"aac")!
let url = URL(fileURLWithPath: "path")

var bombSoundEffect = try AVAudioPlayer(contentsOf: bassFile.url)
bombSoundEffect.prepareToPlay()

// uncomment below for AVFoundation
// bombSoundEffect.numberOfLoops = -1
// bombSoundEffect.play()

How may I get rid of this click/pop?我怎样才能摆脱这种点击/弹出?

Rework your bass sample so that it starts and ends with some silence.重新处理您的贝司样本,使其以静音开始和结束。

To avoid clicks and pops when looping, the values at the seam must be continuous, that is they must not differ too much.为了避免循环时的咔嗒声和爆裂声,接缝处的值必须是连续的,即它们不能相差太大。 Their velocities need to match too, not sure about acceleration.它们的速度也需要匹配,不确定加速度。 You could achieve this easily by loading the sample into memory and multiplying it by a curve that has the above properties.您可以通过将样本加载到 memory 并将其乘以具有上述属性的曲线来轻松实现此目的。 Something that eases in from 0 to 1 at the beginning then back out at the end.开始时从 0 到 1 缓和然后在结束时退出的东西。

Also load up your sample in sound editor and inspect the beginning and end.还要在声音编辑器中加载您的样本并检查开头和结尾。 Maybe the end has been cut off too sharply.也许结尾被剪得太尖锐了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM