SDL_Mixer 'pop' noise

Started by
1 comment, last by Kris_A 18 years, 8 months ago
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); 
memset(sample->abuf,0,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
Mix_PlayChannel(-1,sample,0);	

// Close audio
Mix_CloseAudio();




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]
Advertisement
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.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

ahh, of course, I just looked at the output in CoolEdit, and the 'base level' seems to be 127/128. Works perfectly now, thanks!

This topic is closed to new replies.

Advertisement