FluidSynth and PipeWire

I was trying to play a MIDI file on my laptop, with Ubuntu MATE 24.04, using fluidsynth, but nothing was playing.

I could see the following error via journalctl -r -b 0 | grep fluid:

Jan 01 12:34:56 host fluidsynth[1234]: fluidsynth: error: Failed to open the "default" audio device

Turns out, all we need is to use the pipewire audio driver setting, but this requires either; a) a user configuration for fluidsynth, or; b) for fluidsynth.service to pass the correct value to the --audio-driver argument.

User configuration

The documentation for user configuration is found here: FluidSynth configuration files · FluidSynth/fluidsynth Wiki · GitHub

All we'll need in our ~/.fluidsynth file is the following contents:

set audio.driver pipewire

And we restart the service:

user@host:~$ systemctl restart --user fluidsynth.service

And presto :musical_notes: A fluidsynth process was running with port 128:0 for MIDI playback.

Configure arguments for service

With a little bit of digging in /etc/systemd/user/default.target.wants/fluidsynth.service; I noticed that:

  1. An environment variable called OTHER_OPTS is appended to the command when launching the fluidsynth process, and;
  2. The environment (variables) for the service can be set on a per-user basis via the ~/.config/fluidsynth file.

So with this in mind, I created the ~/.config/fluidsynth file with the simple contents (e.g. in Pluma or any text editor):

OTHER_OPTS=--audio-driver pipewire

And we restart the service:

user@host:~$ systemctl restart --user fluidsynth.service

Same result as above :musical_notes: !

Discussion

These solutions have minor differences. The first option will apply those settings whenever the user invokes the fluidsynth CLI (including by systemd). The second option will only apply those settings when the systemd service invokes the fluidsynth CLI.

5 Likes

As an aside: it would be nice if FluidSynth would go to sleep when it hasn't received events for a while - unfortunately as it stands both it and PipeWire continuously use CPU to output silent audio.

See: PipeWire sleep while not producing · Issue #1630 · FluidSynth/fluidsynth · GitHub

Really not great if you're on a laptop and care about battery usage!

With luck: the suggestion for a user-specified timeout (and sleep) is implemented.

4 Likes