SDL_mixer is a library we use to make audio playing easier (because it can get
complicated). We have to set it up just like we
set up SDL_image. Like before, it's just a matter of having the headers files,
library files, and binary files in the right place with your compiler configured to use them.

To initialize SDL_mixer we need to call Mix_OpenAudio. The first argument sets the
sound frequency, and 44100 is a standard frequency that works on most systems. The second argument determines the sample format, which again here we're using the default. The
third argument is the number of hardware channels, and here we're using 2 channels for stereo. The last argument is the sample size, which determines the size of the chunks we use
when playing sound. 2048 bytes (AKA 2 kilobyes) worked fine for me, but you may have to experiment with this value to minimize lag when playing sounds.

If there's any errors with SDL_mixer, they're reported with Mix_GetError.

In the event loop, we play a sound effect when the 1, 2, 3, or 4 keys are pressed. The way to play a Mix_Chunk is by calling
Mix_PlayChannel. The first argument is the channel you want to use to play it. Since
we don't care which channel it comes out of, we set the channel to negative 1 which will use the nearest available channel. The second argument is the sound effect and last argument
is the number of times to repeat the effect. We only want it to play once per button press, so we have it repeat 0 times.

A channel in this case is not the same as a hardware channel that can represent the left and right channel of a stereo system. Every sound effect that's played has a channel
associated with it. When you want to pause or stop an effect that is play, you can halt its channel.

case SDLK_9:
//If there is no music playing
if( Mix_PlayingMusic() == 0 )
{
//Play the music
Mix_PlayMusic( gMusic, -1 );
}
//If music is being played
else
{
//If the music is paused
if( Mix_PausedMusic() == 1 )
{
//Resume the music
Mix_ResumeMusic();
}
//If the music is playing
else
{
//Pause the music
Mix_PauseMusic();
}
}
break;
case SDLK_0:
//Stop the music
Mix_HaltMusic();
break;
}
}

For this demo, we want to play/pause the music on a 9 keypress and stop the music on a 0 keypress.

When the 9 key pressed we first check if the music is not playing with
Mix_PlayingMusic. If it isn't, we start the music with
Mix_PlayMusic. The first argument is the music we want to play and the last argument is
the number of times to repeat it. Negative 1 is a special value saying we want to loop it until it is stopped.