Transplanting SDL_audiocvt.c to SDL_sound

Torbjörn Andersson torbjorn.e.andersson at
Sun Oct 14 09:40:42 EDT 2001

This is a first attempt at transplanting the audio converter from SDL
to SDL_sound. I've reformatted the code and made some slight
restructuring, but the only important change is that I've enabled the
slow rate conversion filter.

I didn't even dare to touch the file header.

I thought I would have to change SDL_sound to handle arbitrary buffer
lengths, but it looks like playsound already does. Neat.

One known issue is that the MP3 decoder gets very unhappy if I force a
conversion between signed and unsigned data. I have no idea why. I
can't reproduce the problem with any of the other converters I tried.

The choppy sound when converting from 16- to 8-bit sound that I
mentioned the other day turned out to be an error in SDL_sound.c. When
a conversion was needed, Sound_Decode() would do

     retval *= internal->sdlcvt.len_mult;

which didn't work if the converted audio buffer was shorter than the
original. I've changed this to

     retval = internal->sdlcvt.len_cvt;

which I hope is the Right Thing to do.

I'm a bit nervous about the len_mult and rate_incr parts of
Sound_AudioCVT, but perhaps they're ok. Anyway I don't understand
SDL_sound.c well enough to get rid of them.


* We really should make sure the filters[] array doesn't overflow.
   I've increased it's size from 10 to 20, but it still makes me

* As Ryan said, even the slow frequency converter leaves a lot to be
   desired. Perhaps we could borrow some from SoX?

* One thing which might be useful would be a way to tell
   Sound_BuildAudioCVT() if the conversion should be optimized for
   sound quality or computation speed.

The patch also includes the fix mentioned earlier to make the
experimental MIDI decoder pick a sensible default format when there's
no desired one. No sense in having an experimental decoder if people
can't experiment with it. :-)

Torbjörn Andersson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: audiocvt.diff.gz
Type: application/x-gzip
Size: 5253 bytes
Desc: not available
URL: <>

More information about the sdlsound mailing list