In Like Flynn
And just like that, sound is now back in the game. I’m pretty pleased with the results. Even though I was wrong about the SDL_mixer library not having a pan/stereo feature (it did, thanks for pointing that out NotPyry), I went ahead and created my own audio mixer. Come to find out, they’re really not that hard to put together and I get the ability to customize it to the game a little bit (volume controls, mixing settings, etc.).
The system now can play 32 simultaneous sounds at 16-bit 44 kHz. Measuring performance shows that on a simple test scene where we get 880 fps, the sound system drops it down to about 800 fps when all 32 sounds are playing (or something close to that — I was just spamming spells as fast as I could). Most levels will have no more than 8 sounds at once standing still and about 12 when the combat is going.
On top of it, stereo/panning is working and I was able to play the game in all its glory. I had no problems with sound distortion or even the “crunchy” sound I’ve had in the past (which surprised me). Maybe that’s because I do the clipping check at the very end of the mathematics and use the full spectrum of the audio system (16-bit 44 kHz instead of just 8-bit 22 kHz).
Overall, I’m very pleased. I even got frequency bending working (this allows a 11 kHz “Ugh!” sound to be changed to a higher or lower frequency version of “Ugh!” at no extra cost).
But I’m not done. I don’t have the background music back in there and need to clean up the code a bit so the DOS and Windows version aren’t intermixed. I don’t expect there to be big changes in the future, but it would be nice to be able to read the code better in the future. For the Windows version I’m going to drop the MIDI and just stick to digital looped music. I’ve got the files and downloads are no longer 19200 baud modems. Background music will only cost 1 more constantly on sound effect in the system.
Bad Spells are Cursed
As I’ve worked on the code I get an occasional heap corruption in the debug version that crashes the game. I was so excited to have sound that I started playing Quest 7 Map 1, and since I forgot how to get the exit to work, I spent a considerable amount of time trying to figure out the puzzle (yeah, I should remember this, but I don’t). Just as I was about to get the last step figured out, crash! Sigh.
But here is the good news, I’m seeing a pattern. There seems to be a link between casting an invalid spell (I didn’t have my list of spells handy) and this heap corruption bug. It’s not a 100% thing, but the more invalid spells you cast, the greater the chance of a heap corruption. There may be more bugs in the system, but this seems to be the first well hidden bug that has a pattern to it.