Audio Quick Start for newbie? loopwave.c questions

Hi,

I’m new to SDL and interested in using it’s audio features. I’ve looked
at the loopwave.c example and have some questions.

When i call SDL_PauseAudio(0) what exactly happens? A callback function
i register is called? What is the best way to load several frequently
used sounds into memory and have them played at will?

-brett

Brett Wiesner wrote:

Hi,

I’m new to SDL and interested in using it’s audio features. I’ve looked
at the loopwave.c example and have some questions.

When i call SDL_PauseAudio(0) what exactly happens? A callback function
i register is called? What is the best way to load several frequently
used sounds into memory and have them played at will?

All SDL sound samples go through an audio buffer. Your callback function
is responsible for filling the buffer with a sound sound data. The data
gets played and then your callback is called again to provide more data.
If you want to play multiple sounds at once, your callback function has
to keep track of all the currently-playing sounds and mix them into one
sound in the audio buffer (SDL has a function to help you 'merge’
sounds).

You might want to look at the SDL_Mixer lib - it’s a layer on top of the
raw SDL audio system and provides you with multiple ‘channels’ to play
sounds on (i.e. it does mixing for you). The SDL_Mixer documentation is
in the SDL_Mixer.h header file.

Alternatively, try out OpenAL - it looks pretty nice.

Ben.–
Ben Campbell
Programmer, Creature Labs
ben.campbell at creaturelabs.com
http://www.creaturelabs.com