Porting the sound system to SDL_mixer
#1
Hi everybody,

I got into this forum with a personal request... getting the good old Descent Music to work properly. Now after a bit of researching and exchanging ideas with Zico, I've taken upon myself to improve music playback in DXX-R.

I'll be starting with D1X.
SDL_mixer is a higher level library built upon classic SDL audio. It completely abstracts features such as playback and fading of music, so it looks like a very appealing replacement for the old, direct-access MIDI routines.

I already have proof-of-concept code that uses music files in the game directory. Those files can theoretically be of any type supported by SDL_mixer (MP3, OGG, MIDI...).

The existing SDL audio code for sound effects does not need to be ported to SDL_mixer immediately; it is essentially a sound mixer implemented in a big callback function, that can be registered as a PostMix processor in SDL_mixer, without modification.

This still needs work, though, as this limits music playback to the same sampling used for sound effects (11 KHz). I'm currently trying to bypass this limitation, but the sound effects code might eventually need a port to SDL_mixer as well. We'll see...

You can find my (ridiculously small) pieces of code here:
http://descent.tacticalgames.org/
It's not going into SVN yet, as I want to clean things up first.

See, Zico, we're making fast progress there Big Grin
Matt

Material Defender 2211

\"I only hope this is just a reconnaissance mission and nothing more...\"
Reply
#2
Welcome to the "Developers corner". I bet you will finish yours earlier then me mines. Big Grin
Much fun and fast progress. Smile
Reply
#3
Many thanks, MD 2211.

I've tried your code with D2X and it's working fine. Just delete the line

memset(stream, 0x80, len); // fix "static" sound bug on Mac OS X

from the audio_mixcallback.

I spent all night trying to get the music working until I noticed the fucking memset :x
Reply
#4
Hi everyone!

I'm back! I didn't have much time to allocate to DXX-Rebirth during the so-called "summer holidays", but things are settling down now. Please excuse my long silence, I tend to work on a zillion things at once and it's not easy to keep up with everything.

But my heart forever belongs to Descent  Smile

And to make this comeback even better, I've got some progress! Recently, I took some time to explore the pieces of code I'm working on, and generate some bits of documentation. The whole picture got a lot easier to understand, and today I am almost ashamed that the new code I have written is amazingly short and simple. The catch is, you've got to figure out what to write, where; and that's not easy unless you understand the logic (and even harder if you spent your last 2 years coding in Java).

Enough babbling, here's the good news:
  • I'm now successfully converting and playing D1X sound effects via SDL_mixer
  • while music plays (also via SDL_mixer) at a whooping 44 KHz
  • and with as many mixing channels as you want (no more missing sounds when you're going really wild on PORGYS  :-D)
  • Thanks for the report, A600, but I don't have a callback anymore - it got much simpler![/list:u]

    I still have bugs:
    • Music volume not correctly restored at startup (easy one)
    • Looped sound effects not working properly
    • A few things I'd like to clean up about music management[/list:u]

      I'm working on these issues. Then expect a patch for use against the current SVN very soon...
Matt

Material Defender 2211

\"I only hope this is just a reconnaissance mission and nothing more...\"
Reply
#5
It´s very good to have you back. Smile
And it looks like you have a nice pice of code with you.

And you are calming me down in another way... now I know that I´m not the one who is short in time all the day. :-D

Welcome back MD 2211 Cool
Reply
#6
I'm very glad to be back and meet all of you again, too  Cool

I haven't come empty-handed... the SDL_mixer sound system port is now functional! (I didn't say finished however Wink)
The patches can be downloaded from http://descent.tacticalgames.org/
This is D1X/Linux-only for now, but it should be easy to bring this code to win32 and D2X.

With it you can enjoy 44KHz 16-bit stereo music, read from external files placed in the game directory.
Sound effects are currently mixed into 64 (hardcoded) channels. But that should be enough for most human ears...

Be aware that these modifications have not been extensively tested. I'm interested in getting feedback about the sound effects, which had all the volume/panning logic re-implemented using SDL_mixer. It will be interesting to see how it performs in unusual game situations, like boss encounters. My only reference for looping sound effects was the fan in Level 1 :-D

Enjoy!
Matt

Material Defender 2211

\"I only hope this is just a reconnaissance mission and nothing more...\"
Reply
#7
Someone needs to port it to win32 to get some feedback from my side.
I´m still only on Windows (shame on me :-D).
Reply
#8
I think we've hit a milestone on this development tonight!
SVN revision 230 has a functional (and optional, disabled by default) SDL_mixer sound system for D1X Linux.
That means that D1X-Rebirth Linux can play external MP3/OGG soundtracks, and the original internal MIDI music using Timidity, which is much more reliable than the vanilla low-level, direct-access MIDI backend.

Lots of thanks to Hans de Goede (D1X maintainer) for his HMP2MID conversion code, that was put to good use.

The next steps are:
  • Port those changes to D2X-Rebirth Linux (trivial; the sound system is the same)
  • Port those changes to DXX-Rebirth Windows. It should be easy enough, as SDL code is completely portable. However, it is possible that the current Windows MIDI backend will be preferred over SDL_mixer/timidity, as it is reliable enough and requires no configuration (as opposed to Timidity which requires sound patches and a config file)
  • Needless to say, the MP3/OGG playing ability will be ported to Windows, whatever happens to the MIDI backend[/list:u]

    Expect new updates in a not-too-distant future...
Matt

Material Defender 2211

\"I only hope this is just a reconnaissance mission and nothing more...\"
Reply
#9
Smile
Reply
#10
Question: To use this on Linux, I still need either Timidity(or similar) or to have a sound card with midi built onto it, yes?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)