As described in documentation, Mix_PlayChannel function have a 3 parameters:
- channel: Channel to play on, or -1 for the first free unreserved channel.
- chunk: Sample to play.
- loops: Number of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop).
I don't understand the meaning of the channel parameter. What channel is referred to in the documentation?
They are addressing mixed audio channels.
Since SDL_mixer is a multi-channel Audio Mixer Library, you can access multiple mixed audio channels at once and thus play multiple sounds independently at the same time. That's why it requires you to specify which channel to play it on. With the argument
-1
it would just take the first free channel.This is important to know when you try to stop only one of your playing sounds:
This is how you can mix/allocate a certain amount of channels to work with:
There is also a single music channel which can be addressed without specifying a channel which will also play independently: