Playing SDL_mixer games with soundfonts
Here’s a post for people who use Linux and still like to play games.
As almost everyone above a certain age is aware, DOS was a popular gaming platform. Because most DOS games were made before the advent of CD-ROMs, they stored their music in MIDI format, which is extremely space-efficient. A MIDI file is the equivalent of sheet music; how good a DOS game sounded depended on how well your sound card could play it.
Today, software designed for playing DOS games implement their MIDI output in one of two ways. DOSBox and ScummVM expect TiMidity++ to be set up as an ALSA server. They connect to the ALSA server and issue it commands. On the other hand, Exult (for playing Ultima 7) and every DOOM source port I can name defers to SDL_mixer’s MIDI functionality.
The second way is a problem because no released version of SDL_mixer supports soundfonts. Every version up to and including 1.2.11 (the current one now) works by embedding a very old version of TiMidity++ that doesn’t have soundfont support. This limits you to using instrument patches in the format designed for Gravis UltraSound. In decreasing order of preference, you choices would be limited to an actual set of patches from the Gravis UltraSound’s official software, EAWPATS, or FreePats.
Well, as it turns out, a patch to add soundfont support to SDL_mixer has been contributed. While it is not yet in any released version of SDL_Mixer, it’s in the version control repository. So if you want to use it, all you need to do is the following. First, install Fluidsynth: the dependency that SDL_mixer will use to play midi. Then check out the repository, build it, and replace your system’s SDL_mixer libraries with the results. You then set the SDL_SOUNDFONTS environment variable to the path to the soundfont you want to use.
One of the celebrated sounfonts in the DOSBox and ScummVM communities is Shan’s Soundfont (search Youtube for captures of game music that use it). The download link on its official homepage is dead. However, I did find a mirror. The actual soundfont file is in the sfArk format, which is designed specifically for compressing soundfonts. It needs to be uncompressed. As every download link I could find for the Linux-based compressor sfarkxtc was broken, I installed the Windows version under Wine and used it to do the extracting.
Some setup-work was required, but I can now play DOOM with a source port and have the MIDI played with Shan’s Soundfont:
SDL_SOUNDFONTS=SGM-V2.01.sf2 prboom -iwad DOOM1.WAD
(And yes, I know that prboom might not be the best example because you can replace it with prboom-plus, which has has a Fluidsynth backend and supports widescreen aspect ratios. That’s not the point).