Play Soundfonts with Timidity in Ubuntu

Kiran Karkera
2 min readMay 7, 2022

--

How to get Timidity to play midi files using custom Soundfonts.

Prerequisites:

  • Make a backup of the file /etc/timidity/timidity.cfg . This is where Timidity loads its Soundfonts by default.
  • Download Polyphone in order to peek into your Soundfont file definitions.
  • Download a Soundfont file (here’s an example: PapelMedia flute soundfont)

Finding bank and preset

Open the Papelmedia_Flute.sf2 in Polyphone. Note the bank, preset and instrument number.

Bank, preset and instrument number in Polyphone

dir /home/usr/Downloads/soundfonts

bank 0

0 %font Papelmedia_Flute.sf2 0 0

Copy the above section into /etc/timidity/timidity.cfg

  • The first line tells Timidity where to look for Soundfonts.
  • The second line tells Timidity to use bank 0
  • The third line has the format

<instrument number in midi file> <%font> <soundfont file> <bank in your soundfont file> <instrument number in your soundfont file>

Hat tip to this page for the format

Finally, run `timidity music.midi`

and you should hear the installed Soundfont playing

Attentive readers will point out that the instrument number in Polyphone == 1 but has a value 0 in the timidity.cfg. This (I guess) is because the definition needs to be decreased by 1.

Tips for debugging:

  • Turn on --verbose in order to see why loading the Soundfont fails

Init soundfonts `Papelmedia_Flute1.sf2'
Papelmedia_Flute1.sf2: No such file or directory
Can’t open soundfont file Papelmedia_Flute1.sf2
Couldn’t load instrument Papelmedia_Flute1.sf2 (tone bank 0, program 0)
Init soundfonts `Papelmedia_Flute1.sf2'
Papelmedia_Flute1.sf2: No such file or directory

If the Timidity can’t load the Soundfont file, you’ll see a similar error

Init soundfonts `Papelmedia_Flute.sf2'
Couldn’t load instrument Papelmedia_Flute.sf2 (tone bank 0, program 0)

If Timidity loads the Soundfonts, but cannot find the instrument at bank 0 and program 0, you’ll see such an error.

--

--