SDL_Sound and SDL_Mixer

Hello all,

I have just started playing around with SDL_Sound these times so that a
can play sounds in mp3 format and stored in memory buffers. I want to
keep using SDL_Mixer to do the classical stuff of mixing.
Is there anyone who could post some example code on how to do this,
especially loading the buffers, decoding, and setting the parameters ?–
Mathieu

I have just started playing around with SDL_Sound these times so that a
can play sounds in mp3 format and stored in memory buffers. I want to
keep using SDL_Mixer to do the classical stuff of mixing.
Is there anyone who could post some example code on how to do this,
especially loading the buffers, decoding, and setting the parameters ?

Corona688 sent me a patch to hook SDL_sound up to SDL_mixer, but I have to
dig it up and apply it. I’m alarmed by the number of patches I seem
to…simply lose over time. :frowning:

–ryan.

Ryan C. Gordon wrote:

I have just started playing around with SDL_Sound these times so that a
can play sounds in mp3 format and stored in memory buffers. I want to
keep using SDL_Mixer to do the classical stuff of mixing.
Is there anyone who could post some example code on how to do this,
especially loading the buffers, decoding, and setting the parameters ?

Corona688 sent me a patch to hook SDL_sound up to SDL_mixer, but I have to
dig it up and apply it. I’m alarmed by the number of patches I seem
to…simply lose over time. :frowning:

Thanks for your reply.

I have tried to do it alone, but it didn’t work.

So here’s what i have done (this could be of interest for people having
the same problem) I tried to build a simple example of SDL_sound and SDL
(without SDL_mixer) , opening a WAV from a buffer and playing it, and it
worked ! SDL_mixer is (to my point of view) just a thin layer upon SDL,
so it’s easy to create one’s own code doing the same job.
I then tried to mix MP3, but after a few hours wandering why it hanged
up when using “decode”, i realized i had to recompile SDL_sound with the
library libsmpeg installed. I hadn’t done it before, but “MP3” was told
to be supported by SDL_sound using an internal decoder, but in fact, it
didn’t work. I think this is a bug in SDL_sound.
After recompiling with libsmpeg installed, it worked fine.
If there is anybody interested in it, i can post my example code here
(after a few cleanups ;)) )–
Mathieu

just to complete this:

its possible to combine SDL_Sound and SDL_Mixer to play
ogg files for examples (I used oggs due to license restrictions of mp3).

Just use a combination of

Sound_NewSampleFromFile()
Sound_DecodeAll();
Mix_QuickLoad_RAW()
Mix_PlayChannel()

with these functions its possible to play simultaneously multiple *.oggs and *.wavs
and even possible to load the sound data in a separate thread in the background
while the main program is still running.

I tried to use this to decrease the memory consumption of our game (due to the
many uncompressed wavs needed), but finally gave up and didnt use it in the
release version. The problem for me was that the decompression of oggs in memory
took too long, afaik this has been corrected now ( = some bug corrected).

Drop me a note if you need some more code/hints. Or you may also look at the
example source files of the SDL_Sound and SDL_mixer source packages.
Or search in the docs/archives for the functions above.

greetings,
Thomas> ----- Original Message -----

From: mavila@irisa.fr (Mathieu Avila)
To:
Sent: Wednesday, September 03, 2003 11:15 AM
Subject: Re: [SDL] SDL_Sound and SDL_Mixer

Ryan C. Gordon wrote:

I have just started playing around with SDL_Sound these times so that a
can play sounds in mp3 format and stored in memory buffers. I want to
keep using SDL_Mixer to do the classical stuff of mixing.
Is there anyone who could post some example code on how to do this,
especially loading the buffers, decoding, and setting the parameters ?

Corona688 sent me a patch to hook SDL_sound up to SDL_mixer, but I have to
dig it up and apply it. I’m alarmed by the number of patches I seem
to…simply lose over time. :frowning:

Thanks for your reply.

I have tried to do it alone, but it didn’t work.

So here’s what i have done (this could be of interest for people having
the same problem) I tried to build a simple example of SDL_sound and SDL
(without SDL_mixer) , opening a WAV from a buffer and playing it, and it
worked ! SDL_mixer is (to my point of view) just a thin layer upon SDL,
so it’s easy to create one’s own code doing the same job.
I then tried to mix MP3, but after a few hours wandering why it hanged
up when using “decode”, i realized i had to recompile SDL_sound with the
library libsmpeg installed. I hadn’t done it before, but “MP3” was told
to be supported by SDL_sound using an internal decoder, but in fact, it
didn’t work. I think this is a bug in SDL_sound.
After recompiling with libsmpeg installed, it worked fine.
If there is anybody interested in it, i can post my example code here
(after a few cleanups ;)) )


Mathieu


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ryan C. Gordon wrote:

I have just started playing around with SDL_Sound these times so that a
can play sounds in mp3 format and stored in memory buffers. I want to
keep using SDL_Mixer to do the classical stuff of mixing.
Is there anyone who could post some example code on how to do this,
especially loading the buffers, decoding, and setting the parameters ?

Corona688 sent me a patch to hook SDL_sound up to SDL_mixer, but I have to
dig it up and apply it. I’m alarmed by the number of patches I seem
to…simply lose over time. :frowning:

I have a question about SDL_mixer as i easily succeeded to get rid of it.
I manage to mix my sounds myself, using SDL_MixAudio, but the doc page
doesn’t recommend to mix more than two samples together because it could
lead to distorsions and bad effects.
I looked at the source code of SDL_Mixer to see how it is performed, but
it seems to be done the same way. (There is also much code to add
effetcs). But what else ? Is there something i shuld know about mixing
more than 2 sounds ? For many games, I think mixing more than 5 sounds
together is quite reasonable, so what are the tricks about mixing, which
would need to use SDL_Mixer ?–
Mathieu

I have a question about SDL_mixer as i easily succeeded to get rid of it.
I manage to mix my sounds myself, using SDL_MixAudio, but the doc page
doesn’t recommend to mix more than two samples together because it could
lead to distorsions and bad effects.
I looked at the source code of SDL_Mixer to see how it is performed, but
it seems to be done the same way. (There is also much code to add
effetcs). But what else ? Is there something i shuld know about mixing
more than 2 sounds ? For many games, I think mixing more than 5 sounds
together is quite reasonable, so what are the tricks about mixing, which
would need to use SDL_Mixer ?

Typically what is done is a higher resolution data type like int or float
is used for mixing all the channels, and then it is converted back down to
the output format.

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

I looked at the source code of SDL_Mixer to see how it is performed, but
it seems to be done the same way. (There is also much code to add
effetcs). But what else ? Is there something i shuld know about mixing
more than 2 sounds ? For many games, I think mixing more than 5 sounds
together is quite reasonable, so what are the tricks about mixing, which
would need to use SDL_Mixer ?

The samples get clamped at mix time, so you have a potential problem when
mixing again against something you’ve already clamped. Ideally you want to
mix everything at once using a 32-bit data type and then clamp the final
result. SDL_mixer really needs to be fixed (or the SDL API needs to be
extended to allow multiple streams to be mixed at once), but this problem
doesn’t get triggered often in Real Life to this point, so it hasn’t been
dealt with.

–ryan.