When we think of video games, we often think of the music and sounds that accompany them. Providing those special effects used to be very difficult. Keep reading to learn how SDL makes this important task very easy.
A game without audio is like a buffet without spice. Without sound bytes games can be played, but they would fail to providing an immersive environment. Before the coming of SDL, sound effects were either very complex to implement or very limited in output.
Then came SDL with its core and extended libraries. The core library provides the ability to work with wav files. Using the extended libraries, sound formats such as mid, mpeg-1 and others can be integrated into the gaming environment. In the first three sections I will discuss the core audio library. The final section will use the APIs introduced in the first section to create an application that is extensible for future projects.
Playing the Sound with SDL
Sound is one of the sub-systems of SDL. But unlike other sub-systems, sound not only needs to be initialized, but also opened in a way that is akin to setting up the video mode. Even then sound can be used only by using playing routines. In essence there are three steps to using sound within an application. They are:
Opening the audio
Playing the sound
It is in the second step that the format, track rate and more comes into the picture. The following are the details of each step.
The first step in using audio in an application is initializing the audio subsystem. This is done by passing the parameter referring the audio subsystem i.e. SDL_AUDIO. To put it in code:
This is no different than initialization of any other sub-system.