Cara Esten Hurtle
Cara Esten Hurtle

Reputation: 257

AudioUnit: How to get rid of popping/clicking at the start and end of tones?

Working on a game where I'm using AudioUnits to generate sound effects. I've based my sound generation code off of the sample here: http://cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html

I've gotten almost everything working, except I get a really annoying popping noise as each tone is starting and ending. Is there any way to filter this out? I've been working for hours to try and fix it and I could really use some pointers. What could cause this popping noise?

Upvotes: 7

Views: 2475

Answers (3)

bunkerdive
bunkerdive

Reputation: 2101

Yes, it is true that sudden jumps within the signal will cause pops/clicks. However, it's important to comment that if the tones are played continuously, then there should be continuity between them as well (e.g. last sample==first sample), and that the frequency content is "smooth".

I have found it most useful to generate mirrored audio tones. For example, if you need an n-sample audio tone, you can generate an n/2-sample sinusoid, and then append the flipped/reversed (n/2-sample) signal to itself so that you know (last sample==first sample), and that the frequency domain properties are continuous as well.

If octave/matlab are available, sig = [halfSig fliplr(halfSig)]; will do it. Observe with figure;plot(abs(fft(sig)));

Multiply by a linear ramping envelope, and voila.

Upvotes: 1

jscs
jscs

Reputation: 64002

The popping noise is caused by the constant amplitude of your generated sound. The diaphragm of the speaker has to move instantly from rest position (0 amplitude) to the correct displacement for the amplitude of your first sample. The "jump" that it makes causes a popping sound.

You need to ramp up the amplitude over the first few tens of samples, and likewise ramp down when the sound ends.

Upvotes: 11

Jem
Jem

Reputation: 2275

It's likely to be caused by the sudden change from silence to maximum volume, causing a strong discontinuity in the signal. If so, you should have an attack phase and a release phase: going progressively from volume 0 to volume max, and vice-versa. Those phases do not have to be long, a few milliseconds only. they won't be noticeable to human hears.

Upvotes: 4

Related Questions