Running FluidSynth on a Raspberry Pi 4

March 19, 2021

Follow this if you want to use components like these:

View this post on Instagram

A post shared by David Piggott (@dhpiggott)

So that input from a USB MIDI keyboard is output to the headphone jack:

View this post on Instagram

A post shared by David Piggott (@dhpiggott)


Installation guide

  1. Follow https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi up to step 4.

  2. Once you’ve SSHed to the Pi change the hostname from the default:

    sudo hostnamectl set-hostname fluidsynth.dhpiggott.net
    

    Log out and in again for the change to take effect.

  3. Optionally enable Byobu on login and customise the notifications:

    byobu-enable
    byobu-notifications
    

    Log out and in again for the change to take effect.

  4. Install FluidSynth:

    sudo apt install fluidsynth
    
  5. Write this to /etc/security/limits.d/audio.conf:

    @audio   -  rtprio      90
    

    If you skip this step, FluidSynth will run but it will issue this warning:

    warning: Failed to set thread to high priority
    

    Log out and in again for the change to take effect.

  6. Write this to ~/.config/systemd/user/fluidsynth.service:

    [Unit]
    Description=FluidSynth Daemon
       
    [Service]
    ExecStart=/usr/bin/fluidsynth --server --no-shell -o midi.autoconnect=1 -o midi.realtime-prio=90 --audio-driver=alsa --sample-rate=96000 --audio-bufcount=2 --audio-bufsize=960 -o audio.alsa.device=hw:0 -o audio.realtime-prio=90 -o synth.cpu-cores=4 --gain=1 /usr/share/sounds/sf2/FluidR3_GM.sf2
       
    [Install]
    WantedBy=default.target
    
  7. Enable the service:

    systemctl --user enable fluidsynth
    
  8. Tell systemd to start user services before users login and to keep them running after they logout:

    loginctl enable-linger ubuntu
    
  9. Check the service status using systemctl --user status fluidsynth.service:

    ubuntu@fluidsynth:~$ systemctl --user status fluidsynth.service
    ● fluidsynth.service - FluidSynth Daemon
         Loaded: loaded (/home/ubuntu/.config/systemd/user/fluidsynth.service; enabled; vendor preset: enabled)
         Active: active (running) since Fri 2021-03-19 18:21:33 UTC; 3min 29s ago
       Main PID: 21473 (fluidsynth)
         CGroup: /user.slice/user-1000.slice/user@1000.service/fluidsynth.service
                 └─21473 /usr/bin/fluidsynth --server --no-shell -o midi.autoconnect 1 -o midi.realtime-prio 90 --audio-driver=alsa --sample-rate=96000 --audio-bufcount=2 --audio-bufsize=960 -o audio.alsa.device hw>
       
    Mar 19 18:21:33 fluidsynth.dhpiggott.net systemd[1733]: Started FluidSynth Daemon.
    Mar 19 18:21:34 fluidsynth.dhpiggott.net fluidsynth[21473]: fluidsynth: Connection of Midi Through Port-0 succeeded
    Mar 19 18:21:34 fluidsynth.dhpiggott.net fluidsynth[21473]: fluidsynth: Connection of Oxygen 61 MIDI 1 succeeded
    

    Invoke systemctl --user start fluidsynth.service if it’s not already running.