Mauricio Ritter’s Invasion game for Windows was originally written in DirectX 6 and published on CodeProject in 2002. Since then it’s been ported Managed DirectX (aka MDX) by Steve Maier and to XNA 4 for Windows Phone 7 by me. As Microsoft is abandoning XNA, I’ve been porting it yet again – this time to MonoGame for Windows Phone 8.
While MonoGame is extremely similar to XNA, some of its functionality isn’t fully implemented yet, and it’s ability to play sound-effects is a good example of where MonoGame still needs a little work. While MonoGame was able to play three of Invasion’s legacy sound-effects, the other six wouldn’t play at all and instead threw runtime exceptions when SoundEffect.Play was called. Here’s a table showing the nine sound-effects, their properties, and whether MonoGame was able to play them.
The first thing I noticed with these sound-effects is that they have fairly odd bit-rates – 88 kbps, 176 kbps, and 705 kbps. For comparison, modern sound effects have bit-rates of 64, 80, 96, 128, 160, 192, 256, and 320 kbps. But this didn’t fully explain the problem, because skid.wav has a 176 kbps bit-rate and can be played by MonoGame, whereas four other sound-effects also had a 176 kbps bit-rate and couldn’t. Likewise, blub.wav has a frequency of 22,050 Hz and could be played by MonoGame, but none of the other 22,050 Hz sound-effects could. Combining these two properties clearly showed a pattern indicating which sound-effects MonoGame could play and which ones it couldn’t.
Within the debugger I noticed that all of the sound-effects indicated they were 16-bit PCM files, which XNA can play and I thought MonoGame should be able to play too. Using Audacity, I opened each of the files that couldn’t play and exported it to the “Signed 16-bit PCM WAV” format, and noticed that the resulting .wav file had double the original bit-rate (e.g. 88 kbps files were now 176 kbps and 176 kbps files became 384 kbps) and accordingly had doubled in size. Perhaps those wav files had actually been 8-bit PCM, or possibly the reported channels were incorrect? I’m just guessing there, but whatever the reason, the good news was that MonoGame was now able to play these newly formatted wav files! All except one, getextra.wav. Audacity seemed to have a problem converting it at first, but after stripping it of all meta-data (which consisted of its name and the fact that it had been created using SoundForge 2.0 many years ago), it finally worked too.
So the sound files in the MonoGame version of Invasion will be 55 KB larger than in previous versions, but at least MonoGame can play them now without throwing exceptions. So if you are having trouble getting MonoGame to play old sound-effects, download and fire up Audacity and convert them to “Signed 16-bit PCM WAV”, even if you think they already are in that format. It just might save you a lot of time that’s better spent working on your game!