Sega Genesis Programming Part 4: Echo Sound Engine

The Echo Sound Engine

This is going to be a rather short one because there's very little coding involved, very little coding for me at least.

In the last part I speculated that I'd next "either add some scenery and collision detection, or take a stab at music". Once I started looking into the latter I found it was simpler than expected. Well, the playing music part is simpler but the creating music part is still a bit tricky.

There is an open source project called Echo that provides a sound engine and samples that took about 5 minutes to add. I started by pulling the 68k source and making a few small changes to address warnings from vasm. The author noted using asm68k and in my (brief) experience I've found it and vasm disagree on when a label is being reassigned.

In my init method, I pulled the routines to initiate the Z80 & PSG and replaced them with:


 bsr.w Echo_Init

The code additions were really light too:


 lea BGM_Test,a0

 bsr Echo_PlayBGM



 incbin 'bgm_jtxmas.esf'

After these additions my previous demo was exactly the same only now there's xmas-like music playing in the background. The original setting of a mall in 1989 is now a more specific "mall during the 1989 holiday season" until I change my mind.

Getting that .esf file created was by far more work...

Converting .xm to .esf

Echo uses a proprietary format for its audio files. That's not a problem because it's possible to convert .xm (FastTracker) files to it. There are only two issues with that:

1) All the tools run on Windows, minor issue because I have a few virtual machines on standby at all times.

2) To make everything sound good you need to know a little about how trackers work, bigger issue for me at the moment because it's something I need to learn.

There's also a general issue of me not knowing jack about composing music.

The first order of business is pulling down a copy of xm2esf including the VB6 GUI to create the .xm -> .esf conversion settings. It makes me happy to see an active project using VB6.

Then you need to grab some .xm files, there are a ton that are free to use over at The Mod Archive.

The next part is a little tricky, you need to run the xm2esf GUI, open the .xm file you want to convert, and create the channel & instrument mappings.


I found this somewhat non-intuitive because I'm not familiar with tracker files. There's a tutorial I found helpful which recommended analyzing the .xm file in OpenMPT. That was useful because it showed how many instruments there were and which channels are playing what. The .esf file I created didn't sound identical to the source but it was easy to tell they were the same song. As I experiment with this more the results will get better and for the moment I'm happy just to get to this point.

Download the latest source code on GitHub