Home arrow Multimedia arrow Learning Sound for Game Programming using SDL

Learning Sound for Game Programming using SDL

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.

  1. Learning Sound for Game Programming using SDL
  2. Opening the audio
  3. Playing the Audio
  4. Playing the sound in the real world
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 6
March 27, 2007

print this article



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:

  1. Initializing audio
  2. Opening the audio
  3. 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.

Initializing audio

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.

>>> More Multimedia Articles          >>> More By A.P.Rajshekhar

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Basic Lighting in OpenGL and SDL Game Progra...
- Working with Colors in OpenGL for Game Progr...
- Animation in OpenGL for Game Programming usi...
- Game Programming with SDL: Getting Started w...
- Using OpenGL with SDL for Game Programming
- Learning Sound for Game Programming using SDL
- Game Programming using SDL: Raw Graphics and...
- Game Programming using SDL: Getting Started
- Network Radio With Icecast
- Learning To SMILe

Developer Shed Affiliates


Dev Shed Tutorial Topics: