I think I’ve mentioned this before, but as I’ve been writing this game, I only add features to the engine as I need them. In addition to that I generally write the simplest system to get the job done. This is good for development speed, but bad when the game out grows the simple systems.
When I wrote the audio code it was pretty simple. It played some uncompressed wave data at some volume, at some frequency. Then I needed some 3D audio, so I added some simple listener code to determine what sounds to play and attenuate the ambient environment sounds and the noises the people and animals make. This works great. But…
The amount of audio started growing as I continued development. Uncompressed audio is really big. Stereo audio runs about 10 megabytes per minute. The ambient sound data takes up a lot of space in memory, and I was loading entire music tracks into memory to play them.
So over the last two days I’ve fixed this. The audio is now preprocessed and shrunk to a format with around a 30:1 compression ratio. The data is then decompressed as it plays. I also added some streaming code to load the music on the fly. This nicely decreases both the disk and memory footprint of the game.
I also enhanced the music system to be more dynamic. Instead of playing random tracks, it now picks music based on the season of the game as well as the health and happiness of the citizens. I hope this system will give nice audio hints about the state of the town as the game is played.