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:

 
Mix_PlayChannel(-1,bat_sound,0);


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?

Thanks,

Mike
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.
http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC26
Hi Peter,

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

Mike
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.

Mike
Make sure that your shooting sound is loaded correctly.
1
2
3
4
5
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.