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.

7 thoughts on “converting MIDI to WAV (or MP3), the easy way

  1. Hi!

    FluidSynth uses libsndfile for creating audio files, so if sndfile(>=1.0.18) has built-in OGG support, you can create OGA files directly, like many other file types.


    $ fluidsynth -T help
    FluidSynth version 1.1.3
    Copyright (C) 2000-2010 Peter Hanappe and others.
    Distributed under the LGPL license.
    SoundFont(R) is a registered trademark of E-mu Systems, Inc.

    -T options (audio file type):
    'aiff','au','auto','avr','caf','flac','htk','iff','mat','mpc','oga','paf','pvf','raw','rf64','sd2','sds','sf','voc','w64','wav','wve','xi'

    auto: Determine type from file name extension, defaults to "wav"

  2. The list of the file extensions disappeared off the page. Here is a folded list.
    I don’t see .mp3 in it. Is this just an oversight?

    -T options (audio file type):
    ‘aiff’,’au’,’auto’,’avr’,’caf’,’flac’,’htk’,’iff’,’mat’,’mpc’,’oga’,’paf’,
    ‘pvf’,’raw’,’rf64′,’sd2′,’sds’,’sf’,’voc’,’w64′,’wav’,’wve’,’xi’

  3. Glad I found your notes. I used this approach to create a web application that translates a company’s stock price history into a 45-second piece of music, Quote2Note [http://quote2note.larrylang.net]. Custom ruby code to map the data into midi, then fluidsynth into wav, then lame into mp3. (I can’t think of anything useful about this application, but it was a fun project. :-)

    Thanks for the helpful advice!

  4. Pingback: fluidsynth -F file.wav font.sf2 | daw.raks

  5. GeneralUser GS is the best. Wish it would be included in package managers or even with Fluidsynth.

    Anyway, thanks a ton for this article; this’ll help me batch convert these 100-odd songs I have!

Leave a Reply

Your email address will not be published. Required fields are marked *