Skip to content

Instantly share code, notes, and snippets.

@sustmi
Last active November 28, 2024 12:10
Show Gist options
  • Save sustmi/cb6fc88843266874574ac6623c59db1e to your computer and use it in GitHub Desktop.
Save sustmi/cb6fc88843266874574ac6623c59db1e to your computer and use it in GitHub Desktop.
Raspberry Pi MIDI keyboard setup

Install

See: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md

SSH access

touch /boot/ssh

See: https://www.raspberrypi.org/documentation/remote-access/ssh/

Default password: https://www.raspberrypi.org/documentation/linux/usage/users.md

USB Wi-Fi driver, timezone and expand SD card filesystem

Switch to rtl8192cu driver

Edit /etc/modprobe.d/blacklist-rtl8192cu.conf and make it

# CUSTOM: rtl8192cu actually seems to work better than the default `8192cu`
#blacklist rtl8192cu
blacklist 8192cu

Configure Wi-Fi network, select timezone and expand SD card filesystem

sudo raspi-config

See: https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

Update packages

sudo apt-get update
sudo apt-get upgrade

[Optional] Enable PageUp and PageDown to search Bash history

Edit /etc/inputrc and uncomments the following settings:

# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward

Install FluidSynth

sudo apt-get install fluidsynth

Download a decent sound font that does not take too much RAM

Or choose some other: https://www.youtube.com/watch?v=se0Ei4uhnl0

You can use Polyphone to convert or merge soundfont files.

Run FluidSynth

fluidsynth --audio-bufcount=8 --audio-driver=alsa --chorus=0 --reverb=0 -o synth.polyphony=32 -o midi.autoconnect=1 -o synth.midi-bank-select=mma --gain=1 --no-shell --server /usr/share/sounds/sf2/pianissimum.sf2

Explanation of options:

  • --audio-bufcount=8 - lowers the latency
  • --audio-driver=alsa - explicitly select Alsa in order to prevent from using any extra interlinks (like Jack) that would eat more CPU
  • --chorus=0 --reverb=0 -o synth.polyphony=32 - makes it less CPU heavy so that the sound does not get distorted even on my Rasperry Pi 1B (single core 700 MHz ARMv6 CPU)
  • -o midi.autoconnect=1 - autoconnect MIDI device (instead of running aconnect manually)
  • -o synth.midi-bank-select=mma - use bank selection mode that Studiologic SL990 Pro keyboard uses
  • --gain=1 - increases the volume
  • --no-shell --server - something like a daemon mode

Running FluidSynth as a service + remap modulation wheel to volume

Create /home/pi/fluidsynth.config with the following contents:

# Remove current rules (to remove cc sustain events):
router_clear

# Map modulation wheel to volume
router_begin cc
router_par1 1 1 0 7
router_end

# Enable back sustain pedal
router_begin cc
router_par1 64 64 0 64
router_end

# Enable back bank select (MSB)
router_begin cc
router_par1 0 0 0 0
router_end

# Enable back bank select (LSB)
router_begin cc
router_par1 32 32 0 32
router_end

# Set the rules to pass through other messages types (note, prog, pbend, cpress, kpress)
router_begin note
router_end

router_begin prog
router_end

router_begin pbend
router_end

router_begin cpress
router_end

router_begin kpress
router_end

Create /etc/systemd/system/fluidsynth.service with the following contents:

[Unit]
Description=Runs FluidSynth server

[Service]
ExecStart=/usr/bin/fluidsynth --audio-bufcount=8 --audio-driver=alsa --chorus=0 --reverb=0 -o synth.polyphony=32 -o midi.autoconnect=1 -o synth.midi-bank-select=mma --gain=1 --no-shell --server --load-config fluidsynth.config /usr/share/sounds/sf2/pianissimum.sf2
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Enable the services:

sudo systemctl enable fluidsynth.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment