SDL Sound Crackling
June 21, 2007 5:41 PM   Subscribe

Why is there a sound crackle with SDL in some (mainly open-source) games? Full details inside.

I am a developer of an open-source game called Neverball and we have a sound problem (crackling in the music, .ogg's). We think this problem stems from SDL, but have no idea what causes it or how to fix it. The SDL version we are using has changed since the last stable release of the game, but no one has seen anything that would cause issues.
Increasing the sound buffer like 500% fixes it, but this isn't practical (previous stable version was fine with current buffer). Another thing that fixes it is setting the volume in-game to 100%, but that is odd as well.
We know that some other games that use SDL have this issue as well (can't think of any ATM).
Please help!
posted by jammnrose to Computers & Internet (6 answers total)
 
That looks like a badass game, btw. Have you thought about hooking it up to a laptop accelerometer, and using the laptop tilt to control the ball? There was a tech demo (java, I think?) of it a while ago, & there's C code for at least freebsd (so probably every other OS in existence too).

In terms of SDL, what audio driver are you using? SDL is a great library, and can make life much easier, but sometimes it likes to redirect stuff so much that the direct path you thought you were getting turns out to go through 6 different steps before it actually goes to the hardware. Switching drivers can help with this immensely.
posted by devilsbrigade at 8:04 PM on June 21, 2007


I hope this doesn't come off as "was it plugged in", but have you tried it on another box? As in, are you sure it's SDL and not hardware/drivers/stuff in between?
posted by aeighty at 8:08 PM on June 21, 2007


The crackle is the the audio buffer underflowing. As you say, a bigger buffer helps but will kill your latency.

Reason that 100% volume fixes it is probably because it bypasses the SDL_mixer module entirely.
posted by polyglot at 8:14 PM on June 21, 2007


Response by poster: Answer to #1:
The last stable version, 1.4, didn't have this problem. I assume it's somehow related to the new SDL version and something we did, but I don't think SDL would've released something buggy... Maybe they changed the way SDL works in some way none of us can see.

Answer to #2:
Confirmed in Win and OSX (Linux too I think) as well as 5 or more people who are active on the dev team.
posted by jammnrose at 8:20 PM on June 21, 2007


SDL has a great -dev mailing list. You should subscribe yourself and go ask there and/or search the recent archives. If it's a problem with the new release, it will have been done to death, otherwise you'll likely get someone highly knowledgeable in your area of interest to answer.

Can you ditch SDL_mixer and play the OGGs manually? My guess is that SDL_mixer is the problem, bypassing it and manually adding the music waveform to your game sounds may solve it.
posted by polyglot at 8:54 PM on June 21, 2007


I'm actually the original developer of Neverball, so I guess I've got an interest in the answer to this question.

I have to admit that after years of usage over 3 OSs and many different hardware platforms that I have never observed this bug occurring. It seems limited to specific hardware. I'd love to fix it, I just can't reproduce it.
posted by rlk at 7:31 AM on June 22, 2007


« Older Donating/Keeping a human skull?   |   Bell's Thugs Newer »
This thread is closed to new comments.