A while ago I wrote about the plans of using the Raspberry Pi as a synthesizer for the Midi keyboard. You can read about the steps to get this working on Windows over here. But this post is about getting it to work with the Raspberry Pi step-by-step.
First connect your keyboard (with USB) to the RPi (Raspberry Pi).
$ sudo apt-get update $ sudo apt-get install fluidsynth
And run Fluidsynth with ALSA as audio driver
$ fluidsynth --audio-driver=alsa --gain=5 /usr/share/sounds/sf2/FluidR3_GM.sf2
Now load the sf2 sound font file in the Fluidsynth shell (>) and set the gain at maximum (needed with my headphones).
> load /usr/share/sounds/sf2/FluidR3_GM.sf2 > gain 5
Also make sure the system volume is not to low with the following command (use screen or another console to keep Fluidsynth running)
With the following command you can check if it is recognized as an Midi Keyboard and at which channel Fluidsynth is listening
$ aconnect -o
This should give an output like this:
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 20: 'USB Keystation 61es' [type=kernel] 0 'USB Keystation 61es MIDI 1' client 128: 'FLUID Synth (2975)' [type=user] 0 'Synth input port (2975:0)'
In order to test if the key strokes are received from the keyboard use this command.
$ aseqdump -p xx
Where xx is the client number of the keyboard from the previous command which is 20 for me.
To connect the keyboard to Fluidsynth use
$ aconnect xx:0 yy:0
Where xx is again the Midi client id of the keyboard and yy is the client id of Fluidsynth.
Now enjoy your beautiful piano tunes without the need of a full blown computer!
Thanks Floris, very interesting. It works, but a little bit too much latency for my taste. I will try this with Csound and the fluidsynth opcodes.
Very informative and clear article to get started with midi and fluidsynth. Many thanks.
This might interest people trying to make a synthesize / sampler work on RaspberryPi: http://www.samplerbox.org/. Here is the sourcecode: https://github.com/josephernest/SamplerBox
It's possible to have a 500MB grand piano or Rhodes sample set with a decent polyphony.
Thanks for the amazing article. Helped me a lot to set up my Korg.
Thanks for the info, very helpful. My M-Audio Axiom 49 keyboard and Raspberry Pi running Fluidsynth are now connected- working well and sounding good.
I tried this with a Raspberry Pi 2B running Raspbian and there's too much latency sadly. Sometimes it delays before playing a note or switching between notes. Bummer. Maybe with a Pi 3 it would work better??
A bit far removed from your last comment; I'm new to Pi/Linux, any idea how to set this up so it's automatically loaded every time you switch the Pi on?
The latency is a consequence of the PWM-audio of the plain vanilla Rasbperry. Although it is possible to reduce it by fiddeling with the audio parameters, it never vanishes completely.
Your best bet is to buy a simple USB audio sound card. Those are inexpensive in our days and once installed (which is simple, if Rasbian knows the chipset), the latency is immediately gone.
As for autostarting fluidsynth: Once you figured the the entire startup sequence for fluidsynth (in server mode) and how to connect it the keyboard, you include those commands in /etc/rc.local
After trying a lot of different ways on how to configure fluidsynth without the help of the fluidsynth command line, I figured out that it is possible to specify a command file to fluidsynth (-f option). Just include your commands in a file and specify it to fluidsynth. This was necessary as I wanted to load multiple soundfonts and needed to modify the bank numbers during the load to differentiate them.
Took me a while to understand what was going on, so this post helped me a lot! I decided to combine everything into a small startup script written in Python on github: https://github.com/bneijt/pipiano
Thank you for writing this blog post!