[sdlsound] need help putting it all together (sdl_sound,sdl_m ixer,physfs)

Eric Wing ewing2121 at yahoo.com
Tue Dec 3 17:07:17 EST 2002

--- torbjorn.e.andersson at tietoenator.com wrote:
> I've been hoping for someone else to answer, but...

Thank you for the response. I've made a little more
progress but I'm still stuck on some things.

> Yes, it will decode the entire MP3 into a memory
> buffer. You should probably
> just decode a little bit at a time, like "playsound"
> does.
I totally missed the callback function for sounds in
the SDL_mixer. I saw the music callback but didn't see
the sound callback and I assumed it was like the
missing RWops support. So I was totally clueless on
how to know when to continue decoding without it. So I
got that working (kind of) now. Thanks. 

> It sounds as if SDL_sound is decoding the audio to a
> different format than
> SDL_Mixer expects it to. At least that would explain
> the wrong speed. I
> don't know what'd cause the second bug though. If it
> was a problem with
> byte order and/or signedness of the output, that
> should have been noticeable
> with the other ones as well.

Okay, I think you nailed both problems. My open call
to SDL_mixer is something like:
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
My sound files are unfortunately recorded at all
different types of frequencies, mono and stereo, bit
precisions, and are in different formats. So I presume
SDL_Sound is decoding them for their "actual" stats.
However, I am not sure how to get the two to work
together correctly. In the case where I have an MP3
file encoded at 44100 and SDL_Mixer is set to the
same, I have no problems. But when my audio values
don't match, I get into a ton of problems.

I've found the "desired" field in Sound_NewSample.
I've create a Sound_AudioInfo desired; where,
desired.format = MIX_DEFAULT_FORMAT; // This fixed the
garbled problem
desired.channels = 0; // Assuming 0 takes the actual
desired.rate = (Whatever SDL_mixer is set to);

I call Sound_NewSample(rwops, fileext, &desired,

So here are some of the weird cases:
With SDL_mixer set to 22050 (and thus desired), my MP3
file plays very stranglely. For each decoded chunk,
roughly the first half plays normally, and then the
second half plays at a slower speed (1/2 or 1/4). Then
when the next chunk is decoded and played, it repeats
the same problem (first half okay, second half slow).
Also I noticed that my playback seems click more
between chunk, and I have to increase the buffer size
to decode. However, if I do a DecodeAll instead of
streaming, the file plays fine.

With SDL_mixer set to 44100, and playing a 11025hz
WAV, it runs really fast, something like 8x. If I
select my desired rate to be 88200, then it plays
normally. If I take the same WAV file and make it an
OGG, I get no output. However, if I do DecodeAll
instead, I hear the output like the WAV.

Can somebody please explain this to me? And is there a
better way of getting the samples to play at the
correct speed? It seems that converting to extremely
high numbers like 88200 is not a good thing. I can
already see performance hits. SDL_mixer also seems to
vary in performance from system to system and it seems
that I would like to keep the SDL_mixer frequency user
> Mind you, I've never actually used SDL_sound (which
> is embarrassing since I
> helped writing parts of it :-). Ryan has been
> threatening to rewrite
> SDL_Mixer to use SDL_sound as a backend. This should
> make most of these
> problems go away, but I understand he's been busy
> elsewhere lately.
That would be the greatest solution, but yeah, he
seems to be really busy.


Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.

More information about the sdlsound mailing list