0

I am trying to create footstep sounds in sdl2. It plays fine but it ignores the sound that is already playing in the channel.

So when I move the player the footstep sound plays like a machine gun(it overplays itself).

//Declaration
Mix_chunk* footstep = Mix_LoadWAV("Path/to/sound.wav");
//Current usage
while (gameLoop)
{
    if (Player.hasMoved==true)
    {
        Mix_PlayChannel(-1,footstep,0);//the sound keeps playing even if the channel is still busy
    }
}

In pygame I could easily use get_busy() method. It should be easy to use in SDL2 too since pygame is using it.

//IDEAL usage
while (gameLoop)
{
    if (Player.hasMoved==true)
    {
        if (ChannelFinishedPlaying(-1)==true)
        {
            Mix_PlayChannel(-1,footstep,0);
        }    
    }
}
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
yolowex
  • 31
  • 5

1 Answers1

0

Try the Mix_Playing function, but you need to know which channel the sound is played on.

You can also use Mix_ChannelFinished function. Register your callback and you will be notified each time the channel is finished. The handling is slightly different than the pygame example given, so you'll need to organize your code a bit differently.