Sound System Progress

I have been working on the sound system lately, which has been pretty enjoyable. I based the design on the old sound system. I’m not sure if many people saw that, because I implemented it (along with resource management) between the release of Alpha 1.4 and our decision to rework the code from the ground up. It was pretty slick from the end user’s perspective. The user could create a new SoundEffect object and that would acquire a pointer to the shared AL buffer automatically. That buffer was shared, so there was never more than 1 copy of “cannon.ogg” or whatever in memory at one time. It would also automatically unload the buffer when the last SoundEffect using it was deleted. The sound system also managed your OpenAL sources so that only a given number of sources would be created. If you tried to play more sounds than that, it would revoke the source from the oldest sound to play the most recent. That was pretty nice, but it was a little ugly behind the scenes because when I originally wrote it I was not yet aware of boost’s smart pointers. I had a feature where you could “lock” a source so it would not be revoked, but I never used that because I never updated the code to stream ogg files from the disk to use the sound system. As a result, the source management was much more complicated than it needed to be and it was still possible to run out OpenAL sources if you played too many sounds at one time.

I have gotten a good chunk of the way through moving the sound system into our new codebase. I think in general the sound system is much better now. It is a little ugly because it is running on its own thread, but I think that will be worth it. I have renamed the SoundEffect class to SoundBuffer (since it is a sound that is played from a single buffer in memory as opposed to one that is streamed from disk, which is done with the SoundStream class). It has basically the same interface as it used to, but now all the SoundBuffer does is fire off events to the SoundSubSystem (as you can see in the SoundBuffer implementation). Sources are still revoked just like they were, but now I am positioned to combine the source allocation for the SoundStream class too. I wrote a really simple class for reading ogg/vorbis files in a more C++ friendly manner. It allows us to use RAII and hide some of the oddities of the vorbis lib. I reworked our LoadOgg function that loads the entire contents of an ogg/vorbis file into a single OpenAL buffer so that it used the new OggFile wrapper, and it resulted in this diff. That is way more readable, so I’m pretty pleased with that. Now, I’m working on using that ogg/vorbis wrapper to implement streaming music off the disk. It’s nice to have all of my ogg/vorbis code in a single place instead of duplicating it like we used to. Maybe I should do something similar for WAV files. I also probably should rename all of our *Ogg* classes, functions and methods to *Vorbis*…

Anyway, it has been fun to rework the sound stuff using our improved resource management code and just the general better code base we have now.

One Response to “Sound System Progress”

  1. [...] Crown and Cutlass Crown and Cutlass Developer Blog « Sound System Progress [...]

Leave a Reply