I have made some progression since the last time I wrote an article about my new game Slengo.
I created a Vorbis player UserControl, optimized for sounds effects in games. When initialized, the MediaElement inside will be streaming silence. When the function Play is called with a stream, the silence will be replaced by this stream, until the end of the sound, where the stream will go back into silence mode.
This scheme solves the short-sound problem, ie MediaElement is incapable of handling sounds shorter than 1 second. The silence-stream actually makes the sound effect longer than a second. Secondly, this scheme solves a major part of the sound-latency or audio-gap. With a buffer of 45ms, this latency is drastically lower than what you get out of the box. I develop in a Virtual Machine and I’ve been really pushing to get this latency as low as possible. Then I tested on iron, which demonstrated a great latency improvement.
The only drawback of this scheme is that you cannot make major sound changes while continues playing a stream. It is not possible to alter the audio buffer length, it is not possible to switch from mono sounds to stereo sounds. Those are acceptable limits.
Past week I have added another NPC to the game. And ofcourse tested her (yes it’s a she). That currently makes a total of four NPC’s (enemies).
This weekend I took my Vorbis player to the next step: seamless audio. So you buy a couple of loop-sets, encode them to Ogg Vorbis and just mix the tracks. A MediaEnd event is triggered when a sound has finished playing, and a tracker function just injects the next track. As there is no audio-gap, the tracks play seamlessly after eachother. And at the end of the playlist, you just repeat the whole thing.
The next step was to add the tracker to the game, so that you hear the music and the sound effects at the same time.
A weird thing happened. While in my test-tracker, the background music played without a glitch, in the game the sound began to stutter and distort. I thought that the decoding routines were slow, so I thought I decode all sounds effects at the start of the game and keep the result in a cache. Only the music would then be decoded at playing time. Well, this caching scheme did not work, the music still sounded distorted. The solution was to use less VorbisPlayers for the sound effects. Apparently, there were too many MediaElements active at the same time. That’s one of those cases where it is a good thing getting to know your tools.
I’ve also worked on a title screen for the game. I’m keeping it simple this time. I also want to introduce a level picker, where a level is unlocked when you reach a certain level. That sounds easy. The hard part will be next, creating challenging levels, which keep game-players attracted.