Pops in sdl mixer?

I’m using SDL_mixer in my game, which is maybe overkill because right now
all I’m using it for is to play wavs every now and then.

Up until now, the sound samples have been 11025Hz (mono, 8bit). This is
proving inadequate (can’t do high sounds nicely enough) so I’m converting to
22050 Hz (still mono 8 bit). Got everything nicely converted in theory, but
now, a second or so after each sound is played, there’s a faint pop (at
least on Win32 – haven’t had a chance to test on Linux yet, as my wife is
hogging that computer to play Frozen Bubble). These pops are not part of
the wav files.

Audio is opened with

Mix_OpenAudio(22050, AUDIO_U8, 2, 256));

sounds are loaded with Mix_LoadWAV (only once, of course) and then played
back with

Mix_PlayChannel(-1, mysound, 0);

This worked fine with Mix_OpenAudio(11025, AUDIO_U8, 2, 256)), and in fact
works fine like that even with my new 22050Hz samples.

What’s my problem here?–
Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/

Additional information: SDL_mixer 1.2.4. Sound Blaster Live card. And
unfortunately for debugging, the pop doesn’t actually happen every time, but
rather about 1/3 of the time.On Mon, May 27, 2002 at 07:09:30PM -0400, Matthew Miller wrote:

22050 Hz (still mono 8 bit). Got everything nicely converted in theory, but
now, a second or so after each sound is played, there’s a faint pop (at


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/

Mix_OpenAudio(22050, AUDIO_U8, 2, 256));

Make the 256 something bigger, like 1024, and see if the pops go away.

–ryan.

Mix_OpenAudio(22050, AUDIO_U8, 2, 256));

Make the 256 something bigger, like 1024, and see if the pops go away.

We should just define 1024 as the default next time. :slight_smile:

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Cool; that does indeed fix the problem. Thank you very much. Is there any
benefit (or detriment) to using an even bigger value?On Mon, May 27, 2002 at 06:56:57PM -0700, Sam Lantinga wrote:

Make the 256 something bigger, like 1024, and see if the pops go away.
We should just define 1024 as the default next time. :slight_smile:


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/

Cool; that does indeed fix the problem. Thank you very much. Is there any
benefit (or detriment) to using an even bigger value?

Latency.

The bigger the value, the longer it will take to play your sound (since
there’s more buffered to the audio device).

512 to 1024 is good for most apps, and you have to scale it depending on
what sample rate you use (since you might need to feed more data at a
time)…and you already saw what happens when you don’t give it a large
enough buffer to accomodate your sample rate. It’s a tightrope. Trial and
error is best.

–ryan.

Okay. I’m a little concerned about trial and error for this, since I had
someone who was reporting a weird “echoing a second later” problem even with
the old settings (lower sample rate and lower chunksize) on their system. I
couldn’t reproduce it, so I was a bit stuck. I bet this was the issue,
though. So I suppose have a user-setable value is the best way, but that
kinda sucks.On Mon, May 27, 2002 at 11:42:15PM -0400, Ryan C. Gordon wrote:

512 to 1024 is good for most apps, and you have to scale it depending on
what sample rate you use (since you might need to feed more data at a
time)…and you already saw what happens when you don’t give it a large
enough buffer to accomodate your sample rate. It’s a tightrope. Trial and
error is best.


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/

I bet this was the issue, though. So I suppose have a user-setable
value is the best way, but that kinda sucks.

This is what I’m using for Serious Sam:
SDL_AudioSpec desired;

if (desired.freq <= 11025)
desired.samples = 512;
else if (desired.freq <= 22050)
desired.samples = 1024;
else if (desired.freq <= 44100)
desired.samples = 2048;
else
desired.samples = 4096; // (shrug)

…and it seems to work well, but putting some other way for users to
specify their own (cvar, environment car, config file, command line…) is
always a good idea anyhow.

–ryan.

sigh. Well, for now, they’ve got the source code. :)On Tue, May 28, 2002 at 12:03:10AM -0400, Ryan C. Gordon wrote:

…and it seems to work well, but putting some other way for users to
specify their own (cvar, environment car, config file, command line…) is
always a good idea anyhow.


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/