How to make a comfortable synthesizer with your own hands

As a child I had a piano, this is a real, Soviet, 300 kilo kilogram. I liked to strum on it, and even after graduating from music school, even play something. The piano is cool, authentic, but not at all practical. And in order to be completely straightforward for the soul, we also need a drum set, five lotions for an electric guitar, a clarinet, a sitar and sample loops ...







Of course, now you don’t need to make a garage studio with a stash of six wages from an apartment; you just need to install a free music editor on your PC. But, this is inconvenient.



The keyboard of a PC is not at all like a keyboard instrument, everything is different here. Moreover, it is not suitable for teaching a child. It seems there is no choice but to acquire a synthesizer. But still tearing at me doubts.



What is a synthesizer? A large device, with a music keyboard, which somewhere should take a decent place. In which the acoustics are built in, and in fact I already have a receiver with speakers. In which the bad PC is built, but I have a good PC.



It turns out that for 40 thousand I buy what I already have in the best quality, except for just the keyboard. It's just some kind of irrational spending.



Looking for a separate keyboard, I came across a class of devices like the USB MIDI Keyboard.

It always seemed to me that MIDI is from a professional music field.

But now all music is made on a PC, in any convenient place, which means that musicians need mobile music keyboards that fit easily into a backpack.



Here it is!







A plan immediately formed in my head. We connect the MIDI-keyboard to the home media center based on the Raspberry Pi 3, where the software synthesizer is spinning, allowing anyone who wants to play their next masterpiece at any time. On such MIDI-keyboards as a rule there is a set of knobs and additional buttons that are programmed for various effects or additional musical instruments. It looks and sounds very cool!



There are bigger and smaller devices, there is more expensive and slightly cheaper. I chose the option for about 5 sput. He has two octaves, the normal size of the key, the buttons for the percussion, the tuning knob, that is, everything that the novice electronic musician can dream of.



I am not an expert in creating music on a PC, so it was difficult to find ways to implement my ideas. Information had to be collected bit by bit. The puzzle gradually began to take shape and it turned out to collect a working solution, which I share with you. Oddly enough, but the standard distribution of Raspbian / Debian found everything you need, did not even have to connect external repositories.



Fluidsynth is used as a sequencer (an application that plays MIDI files).

A MIDI keyboard is immediately detected via ALSA and is available to connect to the sequencer.

To play the sounds of various instruments using an open base of samples in the format SoundFont2. First, install it all.



sudo -s apt-get update apt-get -y install alsa-utils fluid-soundfont-gm fluidsynth
      
      





Connect the MIDI keyboard to the Raspberry and launch the sequencer in server mode:



 fluidsynth -i -s -a alsa -g 3 /usr/share/sounds/sf2/FluidR3_GM.sf2
      
      





Execute the command:



 aconnect -o
      
      





As a result, we will see a list of available MIDI clients:



 client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 20: 'VMini' [type=kernel] 0 'VMini MIDI 1 ' 1 'VMini MIDI 2 ' client 128: 'FLUID Synth (1628)' [type=user] 0 'Synth input port (1628:0)'
      
      





Here it is important for us to remember the numbers of the keyboard and sequencer clients, then to connect them with the command:



 aconnect 20:0 128:0
      
      





Now we are ready to play the Yamaha Piano (this is the default instrument). Read the fluidsynth manual, there are many interesting commands there, for example, to change the instrument to percussion or wind instruments, set the amount of reverberation or chorus.



Let's make our software synthesizer convenient. In order not to manually connect the keyboard with the sequencer each time, we will write a simple demon that will do this when it starts automatically.



 cat > /etc/init.d/fluidsynth << EOF #!/bin/bash ### BEGIN INIT INFO # Provides: fluidsynth # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Fluidsynth deamon to play via MIDI-keyboard ### END INIT INFO startDaemon() { sleep 30s && fluidsynth -i -s -a alsa -g 3 --load-config=/home/osmc/midi-router >/var/log/fluidsynth & sleep 60s && aconnect 20:0 128:0 & } stopDaemon() { pkill -9 fluidsynth &> /dev/null } restartDaemon() { stopDaemon startDaemon } case "$1" in start) startDaemon ;; stop) stopDaemon ;; restart) restartDaemon ;; status) ;; *) startDaemon esac exit 0 EOF
      
      





Register the daemon for autorun:



 chmod 755 /etc/init.d/fluidsynth update-rc.d fluidsynth defaults
      
      





Note that now when starting the sequencer, the configuration file (/ home / osmc / midi-router) is sent, containing commands that turn our keyboard into a real synthesizer.



This is what it is. Each key and twist on the keyboard sends certain events with its own number. I understand there are no special standards, so each manufacturer creates what he wants. For example, I want the square keys to sound drums, the other keys sound the piano, the knobs control the volume, reverb and chorus.



So, I need to register event codes from the keyboard for different instruments, and codes from the knobs for codes that the sequencer understands. In fluidsynth, this is done using a router. These commands are contained in the configuration file.



Here is an example of my configuration file, with comments on what it does.



 cat > /home/osmc/midi-router << EOF #     ,  -    load /usr/share/sounds/sf2/FluidR3_GM.sf2 load /home/osmc/241-Drums.SF2 #       select 1 2 128 0 select 2 1 0 0 #       0 #          router_begin note router_chan 0 0 0 1 router_par1 36 48 1 0 router_end #          router_begin note router_chan 0 0 0 2 router_par1 0 35 1 0 router_end router_begin note router_chan 0 0 0 2 router_par1 49 255 1 0 router_end #      ,   , #         fluidsynth router_begin cc router_chan 0 0 0 2 router_par1 14 14 0 98 router_end router_begin cc router_chan 0 0 0 2 router_par1 15 15 0 11 router_end router_begin cc router_chan 0 0 0 2 router_par1 16 16 0 91 router_end router_begin cc router_chan 0 0 0 2 router_par1 17 17 0 93 router_end #     0, #      #      cc 0 7 0 EOF
      
      





To find out which codes your device generates, you need to use this utility:



 aseqdump -p 20:0
      
      





She listens and displays events from the MIDI keyboard to the console. Click the button or twist the knob and you will see the type, channel and event code. You can program your keyboard the way you want, not the way the engineers who designed the specific synthesizer came up with. For that many thanks to the developers of fluidsynth, alsa, SoundFont2, Raspberry and V-Mini.



By the way, this topic with DIY synthesizers is reflected in several inventions, I recommend to study: one and two .



All Articles