Sound effects – clicking noises!

Today I spent a couple hours struggling with an annoying “clicking” noise that was showing up in my Asteroids Runner game when an asteroid got destroyed. It was somewhat sporadic and difficult to debug; early on in a game the noise was very common, and then it got less common as the session went on. How could this be?

The first thing I tried was implementing proper pre-loading of sound files, figuring that maybe there was a loading issue happening the first few times the sound played. ImpactJS handles this pretty well, letting you either load sounds at runtime (probably a bad idea), or using a sound manager to preload them:

ig.soundManager.load('media/explosion.mp3', true);
ig.soundManager.load('media/laser.mp3', true);
var deathSound = ig.soundManager.get('media/explosion.mp3');;

This seemed to smooth out the first few sound effects which was a nice gain, but it didn’t actually solve the clicking problem at all!

Next I ventured into Audacity to try to learn more about what might be causing the noise. A little experimentation with various sound effects made it clear that abruptly stopping a sound (any sudden change in volume) can lead to that clicking effect, so I went off in search of any code path that could cause sounds to get stopped early.

I made the Sound objects multi-channel so that the browser is able to play them on top of each other, theoretically preventing a case where a sound is stopped early because a new one needs to start. This seemed to improve the overall sound quality but the click was still there. I was able to tell this working by logging which channel was being used in the Javascript console:

console.log("Returned channel #" + i);

So after circling the long way around the problem trying to find the bug in my code that was causing this, I dug back into Audacity and after playing various chunks of my explosion sound over and over, I came to an embarrassing realization: the clicking sound was actually in the sound file itself. It was an artifact of the original freeware sound I had downloaded. My code, instead of causing the bug, was actually just covering up the issue in many cases!

Example of a sharp volume change that could lead to a clicking noise when played at full speed

So after another web search for publicly usable sound effects and some rewiring and damping of the new explosion sound, Asteroids Runner is click free. It now has better initial performance and smoother overall sounds to boot!


Leave a Reply