FluidSynth
FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications. It is optionally used by gst-plugins-bad.
Installation
Install the fluidsynth package.
A SoundFont is also needed. See MIDI#List of SoundFonts for a list of SoundFonts. You may wish to #Set the default SoundFont.
Configuration
FluidSynth is configured system-wide in /etc/fluidsynth.conf or on a per-user basis in ~/.fluidsynth. These files should contain lines of FluidSettings in the command format given in fluidsynth(1).
For example, the following shows a system-wide configuration to increase gain:
/etc/fluidsynth.conf
set synth.gain 0.4
The system-wide file is always loaded first if it is available, followed by user-specific configuration, then configuration files passed via the -f flag. Settings from later configuration files override those from earlier ones.
Set the default SoundFont
The file /usr/share/soundfonts/default.sf2 can be symbolically linked to the desired SoundFont:
# ln -s FluidR3_GM.sf2 /usr/share/soundfonts/default.sf2
Alternatively, the synth.default-soundfont setting may be used:
/etc/fluidsynth.conf
set synth.default-soundfont /usr/share/soundfonts/FluidR3_GM.sf2
Usage
FluidSynth may be used as a standalone synthesizer, or as a daemon which accepts MIDI input and provides synthesized output.
Standalone synthesizer
Use the fluidsynth command to directly play MIDI files:
$ fluidsynth -i /usr/share/soundfonts/FluidR3_GM.sf2 example.mid
You may wish to specify a different audio driver using the -a option, e.g. -a pipewire or -a pulseaudio, instead of using the default ALSA driver. A list of valid drivers can be found using:
$ fluidsynth -a help
FluidSynth has many other options; see the FluidSynth Wiki, fluidsynth(1), and fluidsynth -h for more detail.
Daemon
Choose the desired MIDI and audio drivers, and configure them per #Configuration. Then, start/enable the fluidsynth.service user unit to run the daemon as a user service.
For example, to configure the daemon to handle events via the ALSA Sequencer and synthesize to PipeWire at 48 000 Hz:
/etc/fluidsynth.conf
set audio.driver pipewire set midi.driver alsa_seq set synth.sample-rate 48000
You may want to experiment with settings for the sample rate, buffer size (audio.period_size) and count (audio.periods) if the output quality or latency is not satisfactory. See the FluidSynth wiki for recommendations on values to achieve low latency. Additional information can be found at Professional audio#JACK parameters.
Verification
aconnect from alsa-utils may be used to list all available ALSA sequencer MIDI ports:
$ aconnect -o
client 128: 'FLUID Synth (5117)' [type=user] 0 'Synth input port (5117:0)'
type=kernel ports compared to the FluidSynth daemon's type=user.The port can then be tested with aplaymidi:
$ aplaymidi -p128:0 example.mid
Tips and tricks
Convert MIDI to MP2/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 mp2:
$ fluidsynth -l -T raw -F - /usr/share/soundfonts/FluidR3_GM.sf2 example.mid | twolame -b 256 -r - example.mp2
Requires twolame.
Simple command lines to convert midi to mp3:
$ fluidsynth -l -T raw -F - /usr/share/soundfonts/FluidR3_GM.sf2 example.mid | lame -b 256 -r - example.mp3
Requires lame.
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:
#!/bin/bash
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"
done
}
export -f midi2ogg
find . -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P $maxjobs bash -c 'midi2ogg "$@"' --
Troubleshooting
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/fluidsynth.conf and change the driver to pulseaudio, then restart fluidsynth and PulseAudio:
/etc/fluidsynth.conf
set audio.driver pulseaudio set midi.driver alsa_seq set synth.rate 48000
No MIDI sound / Not the lowest or first MIDI device
$ aconnect -o
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 128: 'FLUID Synth (5117)' [type=user]
0 'Synth input port (5117:0)'
Wine, Proton and many other programs will grab the first MIDI device as their default output. Many have methods to configure a non-default or specific MIDI device but disabling the snd_seq_dummy module is simpler, even if it can be useful for professionals who need to duplex MIDI output to multiple devices.
Remove the module right now.
# rmmod snd_seq_dummy
Then blacklist it from being even loaded in the first place.
Stuck 'key' (constant sound)
Stop the fluidsynth.service user unit, kill all remaining fluidsynth processes, then start the fluidsynth.service user unit.
If using ALSA or OSS, and running as a root service: follow the same instruction for fluidsynth.service.
Broken Pipe and all sound stops with Pipewire
If even simple playback tests sometimes make pipewire get stuck and the pipewire log shows messages like snd_pcm_avail after recover: Broken pipe, the audio buffer size might need to be increased:
fluidsynth -ni --audio-bufsize=128 test.mid # Fixes "Broken pipe".
Audio distortions using PipeWire
After starting FluidSynth if you start hearing audio distortions or crackles during any playback, try setting audio.period_size to 512 or 8192, i.e -z512 in the configuration, if the recommended value of 128 didn't help.[1]