converting MIDI to WAV (or MP3), the easy way

This is a question that comes up all the time: what’s the easiest way to convert a MIDI file in to an audio file, like an MP3, under Linux? The old answer was TiMidity++ (usually just called “timidity”), a software MIDI synth that’s nearly as old as Linux itself, but it’s awkward to use and isn’t actively maintained. Today, though, I discovered that FluidSynth can do the job, and very easily at that.

FluidSynth is a synth that plays SoundFonts; in the studio it’s usually used through the Qsynth GUI, or as a DSSI plugin in a sequencer like Qtractor, but you can also use it stand-alone, through the “fluidsynth” command-line tool. To use it, you’ll need at least one SoundFont, and there’s a good General MIDI SoundFont called “Fluid” (which, despite the similar name, is unrelated to FluidSynth) that’s packaged in most distros.

This will install both the “fluidsynth” tool and the Fluid SoundFont on an Ubuntu or Debian system:

sudo apt-get install fluidsynth fluid-soundfont-gm

Then, just run the “fluidsynth” tool, specifying the SoundFont file to use and the MIDI file to play, and adding the “-F” option to dump the output to a file:

fluidsynth -F out.wav /usr/share/sounds/sf2/FluidR3_GM.sf2 myfile.mid

If you want the result in MP3, you can transcode it using LAME:

lame --preset standard out.wav out.mp3

or in to Ogg Vorbis using oggenc:

oggenc -q 5 out.wav

The great thing about using FluidSynth, apart from its simplicity, is that you can easily substitute whatever SoundFont you want. For instance, if you find Fluid too big to work with, you can user a smaller alternative, like the GeneralUser GS SoundFont, or if the piece is a solo work, you could use a higher-quality solo instrument SoundFont, like jRhodes3, which is a great Rhodes sound.