New Sound Engine

From Armagetron
Revision as of 06:01, 17 December 2005 by Lucifer (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I just committed a new sound engine to cvs head. It only supports music right now, and I hope I didn't break anybody's builds. Should only affect Linux, and that should work fine, although there may be some unintended side effects.

Sound effects aren't implemented yet! I had intended to do that before I committed, but decided I better throw it up before my computer melts or something.

Here's how it works (or doesn't, as the case may be):

There needs to be a music directory inside the data directory (/usr/share/games/armagetronad?), and in this directory, you need at least 4 files. Here's what they are:

title.ogg (um, I think. I may have changed that, heh) guitrack.ogg default.m3u any file, so long as it's referenced in default.m3u. It *must* have "music/" in front of it. Here's an example playlist file:

music/Flotsam And Jetsam & Suicidal Tendencies - Battery (Metallica Cover).mp3
music/Suicidal Tendencies - Get Wacked.mp3
music/Suicidal Tendencies - Lights Camera Revolution - 02 - Lost Again.mp3
music/Suicidal Tendencies - Lights Camera Revolution - 03 - Alone.mp3
music/Suicidal Tendencies - Lights Camera Revolution - 08 - Emotion No 13.mp3

There are new config items to go along with it, but they're probably just temporary. I made them so I wouldn't be hardcoding song file names, but I'm waving my hand and saying "those will be replaced by actual Resource descriptors".

Here they are:

  • MUSIC_VOLUME - A number from 1-128. It's SDL_Mixer's music volume, *not* your soundcard's volume!
  • MUSIC_ACTIVE - 0 to disable music, anything else to enable it.
  • TITLE_TRACK/GUI_TRACK/MUSIC_PLAYLIST - These three all refer to a file in $share/music.

I did not commit music to go with this stuff because I'm just testing with random oggs and mp3s on my hard drive! So you'll need to put actual files in there, and you need to use a format supported by your build of SDL_Mixer. My build supports ogg, mod, and mp3, but *not* midi. For some reason. (It would support midi if I had timidity installed, I think)

Sound Effects

Like I indicated, sound effects aren't implemented yet. If you want to implement them, here's what's in place for it right now.

In eSoundMixer, there's a method PushButton, takes an int. You need to have a mapping of ints (enums, #defines, whatever) to sound effects. Ideally this mapping will be generic enough that we can dynamically add new mappings and the engine will work with it. Whatever. For now, you need a mapping of the existing sound effects. So you'd call from, say, gExplosion, something like:

eSoundMixer* mixer = eSoundMixer::GetMixer();
mixer->PushButton(CYCLE_EXPLOSION);

Then the PushButton method needs to find an available channel and tell SDL_Mixer to play the explosion there. There's a lot more to it than that, we need to get cycle position, camera position, bearing for both of them (probably), and compute a distance and angle to give SDL_mixer so we can have a 3d effect for the sound.

Cycle motor will not be handled this way! A different setup for sound effects that start at a specific time and end at a specific time, loop in the meantime, with some processing, is needed. I have some ideas, but I'll leave them out for now. :)