The definitive MIDI controller | This is not rocket science

What is RPC?

The Raspberry Pi Controller is intended to be a stand-alone MIDI sequencer workstation, made with open-source software and DIY electronic components. It is built around a Raspberry Pi board delivering a solid user interface. The I/O connections are served by an Arduino feeding directly to four MIDI inputs and outputs, guaranteeing accurate timing.

The name pays homage to the venerable Akai MPC series, but this is going to be a whole new kind of beast.

If this project is of interest to you, or if you would be interested in having your own little RPC (DIY, kit or pre-built, doesn’t matter) please drop me an email, tell me what you want to see me accomplish, and I will add you to the news email list. You’ll be the first to hear of updates, and I will be aware if someone actually wants one! No spam.

The protosynth

The DSP synthesizer project has taken most of my attention lately, with the RPC making steady progress on the background. The unique synthesis algorithms of the synth will make it a beast of a companion for the RPC.

Recent posts

It’s alive!

The box for the protosynth is finally complete. See the previous posts for details. The paint is still not entirely finished and could use some final touch-up, but it’s good enough for now. First pics!

Sumutor-1 ready to rok

Sumutor-1 ready to rok

All the hardware is in there and, most importantly, it all seems to work. All knobs and buttons register, leds light, and although there is no real gui, you can tap on the mock buttons and they register. Headphone output works, but I’m not sure yet if the voltage levels are right or if it’s clipping. All the parts of the synth work just as before.

The picture is taken at such an angle that the display looks empty. No, it works just fine. The led segment displays will get covered later, I still have to find some nice red film to put on top of them.

Sumutor-1 with its fleshy belly open

Sumutor-1 with its fleshy belly open

All the internals are in place. In the cover: thumbstick, big buttons and the headphone amplifier on the left, with the main UI panel and the touch TFT screen with its SD card slot taking the rest of the space. On the bottom: the synth on the left has grown itself an opamp attachment and a couple of admittedly ugly connectors, the USB+MIDI interface in the middle, and power supply board and the power connector and switch on the right. Oops, I forgot to remove the jtag cables for the photo shoot.

I’ll take some fancier shots and soundclips later (see the previous posts though!). There’s still much to do on the software side.

Eurorack DSP development platform

We wanted to start making DSP-based modules for the Eurorack modular synthesizer format. The problem was just that there is no easy way to get started; there are no evaluation boards on the market made for this purpose, so you always need something custom for every project. So I decided to make one.

Eurorack is a relatively simple platform: it provides you with dual power supplies (+/-12V), a standard signal level of about 10V p-p, and control voltages roughly in range 0-5V. Pitch control is in 1V/octave; one volt increase in a pitch control voltage should double the pitch of a controlled oscillator.

You want to write DSP code, so you need a DSP processor. Everything is ARM these days, and with the good experiences with the KL26, we decided to try the Kinetis MK22F series. This one has hardware floating point support (single precision) and set of integer DSP instructions: it can do integer MACs in 1 clock, with a 64-bit accumulator! At 120 MHz!

The board would also need some way to get audio in and out of the processor, and the standard way to do that is to use an audio codec connected over an I2S bus. After some searching I found the AK4558 stereo codec, which has some very intriguing capabilities. It allows you to select between different antialiasing filters, some with very short group delay! The codec can also run at 192 kHz sample rates, which, combined with low-latency filters, means that the total latency for passing audio through the CPU is very low. It’s not zero, so if you mix the processed output with the input, it will still result in phase interference, but it looked very promising for short delaylines.

What else do we need? Not much, really. I wanted to have a module that could be used for development, or plugged in to an Eurorack module frontpanel for placing it in a rack.

The finished development board looks like this. On the bottom there’s a standard Eurorack power connector, and on the top two rows of pins for connecting to a front panel (or plugging in other things.)

Voltage conversions have to be provided off the board: gate signals have to be adapted to (and from) 3.3V range, and adding more CV output signals needs an external DAC. But those can be added on the front panel boards.

You can think of it as an “Arduino for Eurorack DSP code”. Development takes place in the Kinetis Design Studio, which also provides full debugging capabilities. All code is written in C++ (unless you insist on Assembly…)

And here’s how it looks like when plugged in to a frontpanel!

USBmidi2 4×4 teaser

Here’s a snap of the USBmidi2 4×4 fit on a lasercut half-rack proto panel (can you find it?):

USBmidi2 4x4 halfrack

USBmidi2 4×4 halfrack

The rack PC mount was another small side project. I have had that Nord Modular for some 13 years. Now finally I got its editor running in the place where it belongs, right next to the synth! The PC and screen are from ebay, with the PC hiding behind the display. The mount for buttons and the PC was manufactured Protocase. Some wires are still sticking out, the buttons are not hooked up yet.

USBmidi2 4×4 coming soon!

Mellotron on the Raspberry Pi

Mellotron is one of those curious instruments that are impossibly difficult and expensive to own, but so deceptively simple and expressive that when you get to play one, you can’t let go of it. So of course I want one.

Note: you will need an audio interface that works with Jack. This will define how playable your new instrument will be! You will also need a MIDI interface, such as the USBmidi2, but any Linux-compatible audio interface will do.


Step 0: Acquire the necessary parts

The purpose of this post is to demo the USBmidi2. So I have one of those for connecting a MIDI keyboard. It will let you plug in a laptop also.

For the audio I used an old Terratec audio interface that I was familiar with. You can use any audio interface that you can get Jack to work with. The Raspberry Pi’s internal headphone jack will also “work”, kind of, but it requires so long buffer sizes that it’s unusable.

The Mellotron sample bank is available on the LinuxSampler instrument page.

Step 1: Configure Jack

Sorry, this part I will not explain here in detail. I used jackd2 and qjackctl. I was able get a latency of 2.9 ms at 44.1khz (according to qjackctl)!

You have to make sure that your Pi is configured to output audio at the minimum possible latency with minimum glitches, before you continue.

For testing Jack, I simply played some mp3s with mplayer -ao jack [song.mp3]

Step 2: Acquire LinuxSampler sources

LinuxSampler is available in the official SVN repository. See the LinuxSampler download page for details.

I had to install a few dependencies first (I already had a g++ installed):

sudo apt-get install subversion bison flex libtool automake autoconf intltool libsqlite3-dev patch

Then download the sources:

mkdir linuxsampler-src
cd linuxsampler-src
svn co libsf2
svn co libgig
svn co liblscp
svn co linuxsampler

Step 3: Build the support libraries

Build libsf2, libgig, and liblscp in that order.

To build each, run these commands:

automake --add-missing
./configure --prefix=/usr
make -j4
sudo make install

Some of them may require some variation or some commands were unnecessary; I will make better notes if I have to do this from scratch. Make sure the make and make install steps finish completely before continuing to the next.

Step 4: Patch LinuxSampler sources for the Raspberry Pi

LinuxSampler does not support the ARM CPU of the Raspberry Pi out of the box. Luckily someone has already fixed this, and the necessary patches are available here. You need both the RTMath.cpp patch, and also the attached atomic.h.diff patch. Or you can just grab them from my site.

Apply the patches:

cd src/common/
patch < ~/RTMath.cpp.diff patch -p2 < ~/atomic.h.diff cd ../..

Step 5: Build LinuxSampler

There are a few programs in linuxsampler/scripts/ that you have to run first, before LinuxSampler is ready to compile. I ran them all on order:

cd scripts

Those perl scripts required XML::Parser to run, but I think that installing ‘intltool’ adds the necessary dependencies. If not, make sure to see “Installing packages system-wide” before going on installing all the Perl libraries with cpan.

Step 6: Build LinuxSampler

This will take some time if you do it on the Pi, and it will require several hundred megabytes of disk space.

The same commands work as before, but configure required some help:

automake --add-missing

CFLAGS="-I/usr/include/sf2 -I/usr/include/libgig" CPPFLAGS="-I/usr/include/sf2 -I/usr/include/libgig" ./configure --prefix=/usr

make -j4
sudo make install

You should now be able to run ‘linuxsampler’ in a shell on the Pi.

Step 7, optional: Install qsampler on a PC

LinuxSampler allows the GUI to run remotely. You can build qsampler to run on a more powerful computer, and connect to the Pi with it. The sources are in the same subversion repository.

Step 8: Install the sample bank and configure LinuxSampler

Extract the TaijiguyGigaTron.tar.bz2 from the LinuxSampler instrument page on the Pi. If you use qsampler remotely, the .gig file must be at the exact same path on both the Pi and your remote controller host.

I ran out of disk space at this point. Running “make clean” in the linuxsampler source tree will make you some room. I was able to fit everything on a 4 GB disk by removing a bunch of unnecessary locales from /usr/share/locale. My Raspbian also came with a rather large General Midi sound bank in /usr/share/, see if you can find it! (OK, I’m assuming it was General Midi, I deleted it before listening to it.)

Now you have to create a LSCP (LinuxSampler Control Protocol) script that initializes your hardware and loads the Mellotron sample bank. I did it like this:

  • Start linuxsampler on Pi
  • Start qsampler on PC
  • In qsampler:
    • Disable local server
    • Connect to “raspberrypi”
    • Add ports for your audio and MIDI hardware
    • Add a channel with TaijiguyGigaTron_switched.gig
    • Make sure the green “led” in qsampler blinks when you play notes – if not, check your MIDI connections!
    • Make sure sound comes out when the green “led” blinks – if not, check your audio connectiosn!
    • Save settings to LSCP file, I called mine “TaijiguyGigaTron.lscp”

Then copy the LSCP file to your Pi. My example LSCP file is available for download here, but I’m sure that you will have to modify it to work with your choice of hardware.

Step 9: Set up LinuxSampler to start without remote control

There’s a nice trick to load the LSCP file from the previous step on the Pi.

First run LinuxSampler in one shell on the Pi:


When it says “initialization completed”, send the LSCP file to it in a second shell:

cat TaijiguyGigaTron.lscp | netcat localhost 8888

If you didn’t change anything else since Step 7, you should now be able to play notes with the Mellotron patch.

Step 10: Wrapping it up in a script

To prepare for starting everything in one go, I wrote a simple script that kicks off Jack and LinuxSampler. OK, it’s dirty with those sleeps and all, but works pretty well for a quick hack.

I have this in /home/pi/, you have to replace the jackd command line with whatever your hardware needs:

daemon -e "DISPLAY=:0.0" -- /usr/bin/jackd -P10 -dalsa -dhw:USB2448 -r44100 -p64 -n2 -Xseq -P
sleep 1
daemon -- linuxsampler
sleep 1
cat /home/pi/TaijiguyGigaTron.lscp | netcat localhost 8888

Debugging it is easy; you can add the -f parameter to daemon to run the programs in a terminal. That allows you to directly see the jack error messages. And when you get each step to run properly, just update the parameters in the script and continue with the next.

Step 11: Running Jack and LinuxSampler on startup

I found it easiest to add my script to the LXDE autostart scripts. I had two directories in /etc/xdg/lxsession/, and I’m not sure why, so I added it in both:

sudo nano /etc/xdg/lxsession/LXDE/autostart
# add on new line at end of file: /home/pi/

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
# add on new line at end of file: /home/pi/

Save everything, test it a few times, reboot, and you’re ready to rok!