SDL Sound Help Please

Hi guys,

I am working on a 2D side scroller game and came upon a sound issue. I would like to be able to play multiple sounds simultaneously but am unable to do so. Currently, I am using:


to call sound effects. I have seen some talk about "threads," but I don't know anything about them at this point.

Is there some simple, elegant way to do it?


You should be able to play multiple sounds at the same time by calling Mix_PlayChannel multiple times. That should work for up to 8 sounds at the same time. If you need to be able to play more sounds at the same time you can use Mix_AllocateChannels to increase the number.
Hi Peter,

I have tried called Mix_PlayChannel multiple times, but it only appears to play the latest instance.

Did you pass 0 as the third argument each time?
Yes I did, and just tried it again. For example, my character shoots lances which makes a sound, and then I have enemies running around with sound being looped in the move function. After a compile and run, only the enemies sound is playing, while my shooting is not doing anything. It's a bit strange.

Make sure that your shooting sound is loaded correctly.
Mix_Chunk* shooting_sound = Mix_LoadWAV("shot.wav");
if (shooting_sound == NULL)
	std::cout << Mix_GetError() << std::endl;

Last edited on
Topic archived. No new replies allowed.