From ArchWiki
Jump to navigation Jump to search

FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications. It is optionally used by gst-plugins-bad.


The first step is to install the fluidsynth package.

You should also install a SoundFont to be able to produce sound. Here is a list of SoundFonts:


There are two ways to use FluidSynth. Either as MIDI player or as daemon adding MIDI support to ALSA.

Standalone mode

You can simply use fluidsynth to play MIDI files:

$ fluidsynth -a alsa -m alsa_seq -l -i /usr/share/soundfonts/FluidR3_GM.sf2 example.midi

assuming than you installed soundfont-fluid.

There are many other options to fluidsynth; see manpage or use -h to get help.

One may wish to use pulseaudio instead of alsa as the argument to the -a option.

Tip: The soundfont does not needed to be specified every time if a symbolic link created for the default soundfont, e.g.
ln -s FluidR3_GM.sf2 /usr/share/soundfonts/default.sf2

ALSA daemon mode

If you want fluidsynth to run as ALSA daemon, edit /etc/conf.d/fluidsynth and add your soundfont along with any other changes you would like to make. For e.g., fluidr3:

OTHER_OPTS='-a alsa -m alsa_seq -r 48000'

After that, you can start/enable the fluidsynth service.

Note that you cannot use root to start the fluidsynth service, if you are using the pulseaudio driver. Pulseaudio will not allow root to connect, since the pulseaudio server is usually started by the user (and not root). Hence the service is provided as a systemd/User service which allows to start the service as any user via:

 systemctl --user start fluidsynth

The following will give you an output software MIDI port (in addition of hardware MIDI ports on your system, if any):

$ aconnect -o
client 128: 'FLUID Synth (5117)' [type=user]
   0 'Synth input port (5117:0)'

An example of usage for this is aplaymidi:

$ aplaymidi -p128:0 example.midi


To use fluidsynth with programs that use SDL_Mixer, you need to specify the soundfont as:

 $ SDL_SOUNDFONTS=/usr/share/soundfonts/FluidR3_GM.sf2 ./program

How to convert MIDI to MP3/OGG

Requires soundfont-fluid or any other soundfont of your choice.

/usr/share/soundfonts is the default location of FluidR3_GM

Simple command lines to convert midi to mp3:

$ fluidsynth -l -T raw -F - /usr/share/soundfonts/FluidR3_GM.sf2 example.mid | twolame -b 256 -r - example.mp3 

Requires twolame.

Simple command lines to convert midi to ogg:

$ fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -T oga -F example.ogg /usr/share/soundfonts/FluidR3_GM.sf2 example.MID

Here is a little script to convert multiple midi files to ogg in parallel:

maxjobs=$(grep processor /proc/cpuinfo | wc -l)
midi2ogg() {
	name=$(echo $@ | sed -r s/[.][mM][iI][dD][iI]?$//g | sed s/^[.][/]//g)
	for arg; do 
	fluidsynth -nli -r 48000 -o synth.cpu-cores=$maxjobs -F "/dev/shm/$name.raw" /usr/share/soundfonts/FluidR3_GM.sf2 "$@"
	oggenc -r -B 16 -C 2 -R 48000 "/dev/shm/$name.raw" -o "$name.ogg"
	rm "/dev/shm/$name.raw"
	## Uncomment for replaygain tagging
	#vorbisgain -f "$name.ogg" 
export -f midi2ogg
find . -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P $maxjobs bash -c 'midi2ogg "$@"' --


Conflicting with PulseAudio

If your fluidsynth application is set to use alsa as driver, the sound card will be accessed directly and pulseaudio and applications using pulseaudio will not be able to work properly. You can modify the configuration file /etc/conf.d/fluidsynth and change the driver to PulseAudio, then restart fluidsynth and PulseAudio:

OTHER_OPTS='-a pulseaudio -m alsa_seq -r 48000'