Music playback

I just finished writing some of the worst code for getting music streaming working. I need to go back and fix it here-and-there during the next few weeks but I can’t afford the time to not have it hard-coded and incredibly flaky.

If the audio I was using fell exactly on 2048-byte boundaries, there’d be no issue. However, as this is the real world where timing can be off, I’m very glad what I sampled was as imperfect as possible.

This came down to the wire. If I couldn’t get it working today, I was going to leave it as unable to be looped. The funny thing is that it doesn’t need to be looped at all and can just play once. Another thing I haven’t yet done in all this is test out stereo. I’ve been using one mono track. Getting stereo actually working will be a challenge due to the need to interleave the file so that for each new buffer’s worth of samples, there isn’t a jump back to the track earliest on the disc. Leading to wear-and-tear, an awful sound from the console, and just general uncleanliness.

Like everything else, I’m most certain that I overcomplicated the streaming playback. One incredibly useful debugging tool for all of this was Audacity. Being able to use the original track, copy-and-paste it, then compare with what I was getting from the Dreamcast helped a great deal. Very glad it existed when it did, otherwise I’m not sure what other tool I’d use which isn’t a propietary solution.

The main challenge I faced was a good week’s worth of trying to get the track to loop seamlessly more than twice. The buffer would be exhausted by the time I needed another buffere’s worth, so being able to get it read in just-in-time was a huge challenge juggling everything around with the correct order, printing debug information, comparing the audio output with my Audacity test file. Nothing else is quite as satisfying as tackling a problem that you’re unfamiliar with.

Anyway, this upcoming week is going to be spent converting the level data (just geometry right now) to a binary format. I’ve estimated about six or eight days for this due to the requirement of making it easily expandable in the future with cameras, lights, and other environmental details.

Something else I’d like to try and get in before I realease the teaser is exception handling. If something goes horribly wrong, it’d be nice if the data could be collected and sent back for analysis.