This chapter gives an overview of the principal tools used for playing MIDI files. It does not include MIDI editors, MIDI producers, etc
The tools described in this chapter each include a software synthesizer. This produces audio as PCM data from the MID data fed to it. The MIDI data contains information about the instrument playing each note, and of course, every instrument sounds different. So the synthesizer must make use of mapping information from MIDI notes + instrument into PCM data.
The mapping is usually done using soundfont files. There are various formats for this, of which the primary one is the .sf2 format. Some synthesizers (such as Timidity) can also use Gravis UltraSound patches, which are recorded real instruments.
Many soundfont files have been created. See for example Links to SoundFonts and other similar files (although many of the links are broken).
/usr/share/sounds/sf2/FluidR3_GM.sf2. This file is nearly 150Mbytes - soundfonts are not small!
soundbank-emg.sf2. This is considerably smaller at 1.9Mb!
Possibly surprisingly, using different soundfonts doesn't seem to make much difference to CPU usage - for FluidSynth they all use about 60-70% CPU on one song. They do, of course, sound different.
Timidity is a "Software sound renderer (MIDI sequencer, MOD player)"
Its home page is Maemo.org
Timidity can be used to play MIDI files by giving them on the command line
The default soundfonts used by Timidity are Gravis UltraSound patches,
These soundfonts are missing many instruments, so should be
replaced by another such as the FluidSynth fonts.
The settings are made in the configurations file
It can also be run as an ALSA server listening on a port (Using MIDI with UNIX):
timidity -iAD -B2,8 -Os1l -s 44100
The "-iAD" option runs it as a Daemon process in the background as an
ALSA sequencer client. The "-B2,8" option selects the number of buffer
fragments. The "-Os1l" option selects ALSA output as PCM. The "-s"
option is the sample size.
(For the Raspberry Pi, I found that
worked better than
In this mode, ALSA can send messages to it. The command
will show output such as
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' laptop:/home/httpd/html/LinuxSound/MIDI/Python/pyPortMidi-0.0.3$aconnect -o client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 128: 'TiMidity' [type=user] 0 'TiMidity port 0 ' 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 '
The "Midi Through" port is not useful but the Timidity ports are. MIDI files can then be played by an ALSA sequencer such as
aplaymidi -p128:0 rehab.mid
The default output for TiMidity can be changed using the
-O option. TiMidity help (
shows, for example,
Available output modes (-O, --output-mode option): -Os ALSA pcm device -Ow RIFF WAVE file -Or Raw waveform data -Ou Sun audio file -Oa AIFF file -Ol List MIDI event -Om Write MIDI file -OM MOD -> MIDI file conversion
For some of these modes the device name can also be set, using
-o option. For example, to play a file using
hw:2 ALSA device, use
timidity -Os -o hw:2 ...
TiMidity can be run with Jack output using the
option. In a user-based environment such as Ubuntu you may need
to stop or pause PulseAudio, start the Jack server and then run TiMidity.
PulseAudion may be paused by e.g.
in one terminal. In another, start the Jack daemon using ALSA input and output
In a third terminal, run TiMidity
timidity -Oj 54154.mid
The links may be shown graphically by also running
"Rosegarden is a well-rounded audio and MIDI sequencer, score editor, and general-purpose music composition and editing environment"
Its home page is RoseGarden
It is not a standalone synthsesizer: it uses FluidSynth, for example.
GStreamer allows you to build "pipelines" that can be played using
It can play MIDI files by e.g.
gst-launch filesrc location="rehab.mid" ! decodebin ! alsasink
fluidsynth is a command line MIDI player.
It runs under ALSA with a command line
fluidsynth -a alsa -l <soundfont> <files...>
The soundfont is set explicitly on the command line, so can be set to another soundfont.
qsynth is a GUI interface to
You can use FluidSynth to convert MIDI files to WAV files by
fluidsynth -F out.wav /usr/share/sounds/sf2/FluidR3_GM.sf2 myfile.mid
Fluidsynth can be run as a server in the same way as TiMidity. Use
fluidsynth --server --audio-driver=alsa /usr/share/sounds/sf2/FluidR3_GM.sf2
a connect -o will show the ports and it can
be played to by e.g.
amidi -p 128:0 <midi-file>
The aim of this sequencer/synthesizer is to be small. It succeeds at this!.
On playing the same song with the different systems, I observed the following CPU patterns:
VLC is a general purpose media player.
There is a
VLC module to handle MIDI files using
To get this working on a Debian system you first need to
Then in Advanced Options of VLC, choose Codecs-Audio Codecs-FluidSynth.
You will need to set the soundfont, eg. to
This chapter has looked at a variety of user level tools for manipulating MIDI. It has primarily includde players, but there are also a large number of MIDI editors, producers, etc.
Copyright © Jan Newmarch, firstname.lastname@example.org
"Programming and Using Linux Sound - in depth" by Jan Newmarch is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License .
Based on a work at https://jan.newmarch.name/LinuxSound/ .
If you like this book, please contribute using PayPal
Or Flattr me: