If you've been around a while, you may remember me thinking about how the sound in SLUDGE should be improved
before. That thread is two years old, and I did nothing about it after posting. (I've read it a couple of times again now, though, while thinking about this new sound system.) But this time around, something has to happen. My new game that I'm currently getting started on requires a significant upgrade to the sound capabilities in SLUDGE, or I'll have to leave SLUDGE and make it in another engine. So I'm pretty much as motivated as I'm going to get about making this change happen.
This is how far I've come when thinking about it:
* The sound list functionality in its current form has been
removed. That system isn't flexible enough to be expanded on, and I'm the only one that have ever used it
, so there's no need for keeping it. Better to clean up the sound system and start fresh. (But as you'll see later in this post, I'm still keeping the basic ideas behind the system.)
* The original Sound and Music functions will of course remain (almost) as they are. That backwards compatibility can't be removed without forking SLUDGE and making a new engine. In which case there are a lot of things I'd change, but I'm not up for that kind of work. (I'd rather learn Unity or AGS or something if it turns out I won't be able to fix sound in SLUDGE to my satisfaction.)
* To replace the sound lists, I'm instead adding a whole bunch of new functions to go alongside the existing Sound and Music functions, creating a third sound category rather than trying to mess with the old system. I call this new system SoundQ, short for sound queues.
* Like the current music functions, the SoundQ functions will work on channels. (The music system has three channels - maybe that's a good number for these too?)
Here's a list of functions:addSoundQ (filehandle, channel)
Adds one sound to a sound queue.If something is already playing in the channel, the new sound is simply added to the end of the queue. If nothing is playing, the new sound is started immediately.replaceSoundQ (filehandle, channel)
Replace any queued sounds with the new sound. This function will not stop or replace the currently playing sound. Call this function with NULL instead of a file handle to clear the queue without stopping the currently playing sound.stopSoundQ (channel)
Stops any sound that may be playing on the channel, and clears the queue.pauseSoundQ (channel)
Pause the channel. This does not change the queue.resumeSoundQ (channel)
Resume a paused channel. Does nothing if the channel wasn't paused.setSoundQLoop (loopHow, channel)
Sets if (and how) the channel should loop:
loopHow = 0: Don't loop. Sounds will be deleted from the queue as they finish. (This is the default.)
loopHow = 1: Loop the whole queue from the beginning.
loopHow = 2: Loop only the last sound in the queue. Previous sounds will be deleted from the queue as they finish.setSoundQVolume (volume, channel)
Sets the volume for a channel. Note that unlike the other volume functions, this one set the volume of a channel regardless of if anything is playing on it or not. I first considered setting it up like the music functions, but this makes more sense to me.r = getSoundQInfo (channel)
Returns a stack, where r is the file handle of the currently playing sound (or NULL), and r is the time left until this sound ends. (I notice how Deirdra adds a short "um" when a character has to wait for a loop in order to hit their cue. I think that's a nice touch, that this function would allow me to replicate.)r = skipSoundQ (channel)
Jumps to the next sound in the queue. If it reaches the end of the queue, it stops the sound and returns 0. Otherwise it returns the file handle of the new sound playing.
That's how far I've come thinking about the interface for an updated sound system, that should have enough functionality to be usable for my game, without being too complex for me to handle. (I'd love to have functionality like FMod, but that's way past my skills/time available.) Thoughts are welcome. Update:
I've now done most of the work implementing it.
The sound cache functions - cacheSound
- are removed. All sounds are now streamed instead of loaded, so no caching is needed. (Any old calls to freeSound() are redirected to stopSound under the hood.) getSoundCache
is renamed to getActiveSounds
is removed. It hasn't been working since Tim switched from FMOD to BASS many years ago anyway (SLUDGE 1.5), and AFAIK nobody has missed it.