Sign in to follow this  

SDL_Mixer 'pop' noise

Recommended Posts

Kris_A    182
Hi, I'm trying to use SDL_Mixer to make some audio clips from scratch. I've been trying to make a silent clip. When I play the clip, I get a slight 'pop' at the beginning and end. What could be causing this? Here's my code (with unimportant bits taken out):
Mix_Chunk * sample;
const int RATE = 44100;

// Init audio
Mix_OpenAudio(RATE, AUDIO_S8, 1, 4096);

// Create a sample 1 second long
sample = new Mix_Chunk;
sample->alen = RATE; 
sample->abuf = (Uint8*)malloc(sample->alen); 
sample->volume = 128;

// This is called when the mouse is clicked, inside a main loop.
// This only happens once upon clicking and does not repeat every loop. I had this problem originally but I fixed it

// Close audio

Thanks a lot, Kris. PS: This doesn't happen if I load a sample from a .wav file, silent or otherwise [Edited by - Kris_A on August 2, 2005 5:22:25 PM]

Share this post

Link to post
Share on other sites
benryves    1999
I could be speaking out of my arse here (not knowing how SDL_Mixer works), but I'll try and offer my solution [smile].
Currently, it doesn't look like you're setting the sample level to anything in particular, right? A silent clip would be one that would be full of the centre-point of the sound - so for an 8-bit sound (which is what you seem to be using) you would set the levels to 127. 0 is the lowest trough and 255 is the highest peak, so if you set the levels to 0 the sound will dip down (and pop) from the centre-point when it starts and finishes.
I've only done this sort of thing loading the wave sounds out of a DOOM WAD file and playing them directly through SDL (no SDL Mixer) and to elminiate the pops I treated my "silence" level as 127 (when writing to the buffer) and it all seemed to work fine.

When you load a WAV file they will be balanced out so that they start and end at 127, hence no popping.

Share this post

Link to post
Share on other sites
Kris_A    182
ahh, of course, I just looked at the output in CoolEdit, and the 'base level' seems to be 127/128. Works perfectly now, thanks!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this