[sdlsound] alt audio converter

Andersson Torbjorn E torbjorn.e.andersson at tietoenator.com
Sat Jun 22 10:27:53 EDT 2002

I finally sat down to have a closer look at my problems with the new audio
converter. What I found was that most of it was because of bad interaction
with SDL_sound, not because of bugs in the converter itself. Specifically,
it doesn't set all the required fields of the Sound_AudioCVT struct:

* The "needed" flag was never set, so Sound_ConvertAudio() was never called.

* The "len_cvt" field was never set, and SDL_sound completely ignores the
  returned value from Sound_ConvertAudio().

The attached patch should also fix a compile error, and an error with
changing signedness of 16-bit data. The changeSigned16BitWrong filter was
never used. Instead changeSigned16BitSys was used in two cases.

This doesn't fix every problem. There seems to be some subtle problem with
the stereo to mono conversions, causing playsound to crash at the end of the
sound, and the mono to stereo conversions don't work at all though the
result certainly sounds... interesting.

Please note that I didn't make an exhaustive test of every possible code
path. What we really need here is a complete set of test cases, and a script
to automate them. But that's for another day.

Speaking of the mono/stereo conversions, is it really necessary to have both
signed and unsigned versions of the stereo to mono conversions? Wouldn't the
unsigned version work for both cases, just like with mono to stereo?

Also, I can't help but getting nervous about things like

   buffer[i] = ((int) *(src++) + *(src++) ) >> 1;

I've always been a bit uncertain around these parts of the C language, but
isn't this the sort of code that produces undefined behaviour? This is used
by the stereo to mono conversions. The mono to stereo conversions use

   *(--dst) = *(--dst) = buffer[i];

and I don't think that's kosher either. Ryan, I assume you have more
experience with this sort of things that I have?

Despite these complaints, let me emphasise that I am pleased and excited
about the prospect of new and improved conversion filters. They just need a
few more bugfixes, that's all. :-)


TietoEnator Resource Management AB
Torbjörn Andersson

-------------- next part --------------
A non-text attachment was scrubbed...
Name: alt_audio_convert.diff.gz
Type: application/octet-stream
Size: 662 bytes
Desc: not available
URL: <http://icculus.org/pipermail/sdlsound/attachments/20020622/b46948ef/attachment.obj>

More information about the sdlsound mailing list