Question about SDL_sound

I have a question about SDL_sound. Is it appropriate to ask about
SDL_sound in this mailing list? If not, where should I ask?

I am wondering about loading and playing sounds. I want to load a
sound (like an interface sound) once, and then play it as many times
as I want without it loading more than that initial load. I have
looked all over the web for an example of this, and I cannot find one.

The examples on the web I have found involve reloading a sound every
time it is played. What some examples do is set up a callback that
reads a certain amount from the sound file, plays that amount, and
then reads in more of the file and plays it, and so on until the
whole sound file has been played. I am wondering if this type of
thing is done out of necessity because of the potentially large
amounts of memory that cannot be stored for the duration of a program.

Here is one example I found:
Sound_MixInit(NULL); // start the mixer; don’t care what format.
Sound_Sample *hello = Sound_NewSampleFromFile(“hello.wav”, NULL, 10240);
Sound_Sample *music = Sound_NewSampleFromFile(“icculus.ogg”, NULL,
10240);
Sound_SetAttribute(hello, SOUND_ATTR_FIREANDFORGET, 1);
Sound_SetAttribute(music, SOUND_ATTR_FIREANDFORGET, 1);
Sound_MixPlay(music);

Does anyone know of a bit of sample code that loads a sound file once
and allows for playing it again and again without reloading it?

I think that not having to reload a file would be a lot faster than
reloading it.
Can someone please direct me to a good site explaining this or at
least tell me if what I want to do is not possible?

Thanks in advance.
-Trevor
http://www.lackeyccg.com

I have a question about SDL_sound. Is it appropriate to ask about
SDL_sound in this mailing list? If not, where should I ask?

There’s an SDL_sound mailing list (blank email to
sdlsound-subscribe at icculus.org to get on the list), but this list is
probably fine for the occasional direct question.

I am wondering about loading and playing sounds. I want to load a sound
(like an interface sound) once, and then play it as many times as I want
without it loading more than that initial load. I have looked all over
the web for an example of this, and I cannot find one.

The examples on the web I have found involve reloading a sound every
time it is played. What some examples do is set up a callback that
reads a certain amount from the sound file, plays that amount, and then
reads in more of the file and plays it, and so on until the whole sound
file has been played. I am wondering if this type of thing is done out
of necessity because of the potentially large amounts of memory that
cannot be stored for the duration of a program.

The callback itself can’t be avoided: that’s how SDL plays audio. The
loading part can be avoided (see below), but you’re right: the usual
way involves decoding as you need it because an uncompressed audio file
can use a LOT of memory to store and a lot of CPU time to decompress all
at once. If you have a small sound file (say, a “click” sound when you
press a button in a GUI), there’s no reason you couldn’t just decompress
the whole thing up front, though.

Here is one example I found:
Sound_MixInit(NULL); // start the mixer; don’t care what format.
Sound_Sample *hello = Sound_NewSampleFromFile(“hello.wav”, NULL, 10240);
Sound_Sample *music = Sound_NewSampleFromFile(“icculus.ogg”, NULL, 10240);
Sound_SetAttribute(hello, SOUND_ATTR_FIREANDFORGET, 1);
Sound_SetAttribute(music, SOUND_ATTR_FIREANDFORGET, 1);
Sound_MixPlay(music);

That’s for the proposed SDL_sound 2.0 API…those functions don’t exist
(yet!).

Does anyone know of a bit of sample code that loads a sound file once
and allows for playing it again and again without reloading it?

Load it and call Sound_DecodeAll(mysample) … then mysample->buffer
will have mysample->buffer_size bytes that represent the entire
uncompressed audio data. Be careful, because it will try to do this even
if the uncompressed data turns out to be hundreds of megabytes.

Also, if you just want to play some audio and not screw around with
callbacks, use SDL_mixer instead (or wait for SDL_sound 2.0, but that’s
a long ways off yet). Or maybe decode with SDL_sound and feed the data
to OpenAL. There’re several options.

–ryan.