The Zynthian project

Recently I found out that I was not the only one trying to build a synth module out of a Raspberry Pi with ZynAddSubFX. The Zynthian project is trying to achieve the exact same goal and so far it looks very promising. I contacted the project owner to ask if he would be interested in collaborating. I got a reply promptly and we both agreed it would be a good idea to join forces. The Zynthian project has all the things that I still had to set up already in place but I think I can still help out. The Zynthian set-up might benefit from some optimizations like a real-time kernel and things like boot time can be improved. Also I could help out testing, maybe do some packaging. And if there’s a need for things like a repository, web server or other hosting related stuff I could provide those.

Protoype of the Zynthian project
Zynthian prototype

I’m very happy with these developments of our projects converging. Check out the Zynthian blog for more information on the current state of the project.

The Zynthian project

The hardest part

At least, for me. Now I have to code something that enables me to select banks and instruments on my synth module. I’ve settled for pyliblo to talk to ZynAddSubFX but I’m just no coder. My elbow now rests on “Learning Python” from O’Reilly, I started reading it like a year ago but never got past chapter 3 or something. Time to persist, I’ve been wanting to be able to code a little bit for years now.

As a note to self, and maybe it’s helpful for others too, what follows are some of the relevant OSC messages to change banks and instruments in ZynAddSubFX.

Changing banks can be done with /loadbank. pyliblo comes with an example script and loading a bank with works as follows: 7777 /loadbank ,i 3

7777 is the port ZynAddSubFX runs on. The /loadbank message wants an integer (,i) and ,i 3 loads the fourth bank (Choir and Voice) as ZynAddSubFX starts counting from 0. Bear in mind that this will only load the bank, it won’t change the instrument that is loaded. To load an instrument from a loaded bank the following incantation does the trick: 7777 /setprogram ,c $'\x03'

So /setprogram loads an instrument from an active bank. It takes a character (,c) as an argument because the program numbers are in hex. But hex are multiple characters so you have to add some escape sequences to make it work (and I lost it there so I could be completely wrong). The above command should load the fourth instrument from the Choir and Voice bank (Voice OOH) as that bank should have been loaded by the previous /loadbank message.

It is also possible to load instrument (.xiz) files. This can be done with the /load_xiz message: 7777 /load_xiz 0 "/usr/share/zynaddsubfx/banks/Bass/0001-Bass 1.xiz"

This will load the Bass 1 instrument fom the Bass bank into part 1 (remember that ZynAddSubFX starts counting from 0). So to load the Bass 2 instrument into part 2 you’d do the following: 7777 /load_xiz 1 "/usr/share/zynaddsubfx/banks/Bass/0002-Bass 2.xiz"

So now I have to incorporate this stuff into Python code that gets called when I press buttons on my LCD display. These are the mappings I’d like to accomplish:

  • Up: toggle next bank and display first instrument from that bank
  • Down: toggle previous bank and display first instrument from that bank
  • Left: toggle previous instrument and display instrument
  • Right: toggle next instrument and display instrument
  • Select: select displayed instrument

That shouldn’t be too hard right? Well, first hurdle, pyliblo can only send or dump OSC messages, it doesn’t seem to be able to handle return messages from the OSC server (ZynAddSubFX in this case). To be continued…

Edit: of course sending just messages with pyliblo won’t handle any return messages, you will need a receiving part. But maybe I should take a look at using MIDI with mididings for instance. Thanks Georg Mill for the tip!

The hardest part

Two steps further

For my little synth module project I created the following systemd unit file /etc/systemd/system/zynaddsubfx.service that starts up a ZynAddSubFX proces at boot time:


ExecStop=/usr/bin/killall zynaddsubfx


/usr/local/bin/zynaddsubfx-mpk is a simple script that starts ZynAddSubFX and connects my Akai MPK:


zynaddsubfx -r 48000 -b 64 -I alsa -O alsa -P 7777 -L /usr/share/zynaddsubfx/banks/SynthPiano/0040-BinaryPiano2.xiz &

while ! aconnect 'MPK mini' 'ZynAddSubFX'
  sleep 0.1


/usr/local/bin/ in its turn is a small Python script that shows a message and a red LED on a 16×2 LCD display so that I know the synth module is ready to use:

# Example using a character LCD plate.
import math
import time

import Adafruit_CharLCD as LCD

# Initialize the LCD using the pins
lcd = LCD.Adafruit_CharLCDPlate()

# Show some basic colors.
lcd.set_color(1.0, 0.0, 0.0)
lcd.message('Raspberry Pi 2\nZynAddSubFX')

The LCD is not an Adafruit one though but a cheaper version I found on Dealextreme. It works fine though with the Adafruit LCD Python library. Next step is to figure out if I can use the buttons on the LCD board to change banks and presets.

Raspberry Pi synth module with 16×2 LCD display
The synth module test environment
Two steps further

Working on a stable setup

Next step for the synth module project was to get the Raspberry Pi 2 to run in a stable manner. It seems like I’m getting close or that I’m already there. First I built a new RT kernel based on the 4.1.7 release of the RPi kernel. Therefore I had to checkout an older git commit because the RPi kernel is already at 4.1.8. The 4.1.7-rt8 patchset applied cleanly and the kernel booted right away:

pi@rpi-jessie:~$ uname -a
 Linux rpi-jessie 4.1.7-rt8-v7 #1 SMP PREEMPT RT Sun Sep 27 19:41:20 CEST 2015 armv7l GNU/Linux

After cleaning up my cmdline.txt it seems to run fine without any hiccups so far. My cmdline.txt now looks like this:

dwc_otg.lpm_enable=0 dwc_otg.speed=1 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=data=writeback elevator=deadline rootwait

Setting USB speed to Full Speed (so USB1.1) by using dwc_otg.speed=1 is necessary otherwise the audio coming out of my USB DAC sounds distorted.

I’m starting ZynAddSubFX as follows:

zynaddsubfx -r 48000 -b 64 -I alsa -O alsa -P 7777 -L /usr/share/zynaddsubfx/banks/SynthPiano/0040-BinaryPiano2.xiz

With a buffer of 64 frames latency is very low and so far I haven’t run into instruments that cause a lot of xruns with this buffer size. Not even the multi-layered ones from Will Godfrey.

So I guess it’s time for the next step, creating a systemd startup unit so that ZynAddSubFX starts at boot. And it would be nice if USB MIDI devices would get connected automatically. And if you could see somehow which instrument is loaded, an LCD display would be great for this. Also I’d like to have the state of the synth saved, maybe by saving an .xmz file whenever there’s a state change or on regular intervals. And the synth module will need a housing or casing. Well, let’s get the software stuff down first.

Working on a stable setup

Building a synth module using a Raspberry Pi

Ever since I did an acid set with my brother in law at the now closed bar De Vinger I’ve been playing with the idea of creating some kind of synth module out of a Raspberry Pi. The Raspberry Pi 2 should be powerful enough to run a complex synth like ZynAddSubFX. When version  2.5.1 of that synth got released the idea resurfaced again since that version allows to remote control a running headless instance of ZynAddSubFX via OSC that is running on for instance a Raspberry Pi. I looked at this functionality before a few months ago but the developer was just starting to implement this feature so it wasn’t very usable yet.

zynaddsubfx-ext-guiBut with the release of ZynAddSubFX 2.5.1 the stabilitity of the zynaddsubfx-ext-gui utility has improved to such an extent that it’s a very usable tool. In the above screenshot you can see zynaddsubfx-ext-gui running on my notebook with Ubuntu 14.04 controlling a remote instance of ZynAddSubFX running on a Raspberry Pi.

So basically all the necessary building blocks for a synth module are there. Coupled with my battered Akai MPK Mini and a cheap PCM2704 USB DAC I started setting up a test setup.

For the OS on the Raspberry Pi 2 I chose Debian Jessie as I feel Raspbian isn’t getting you the most out of your Pi. It’s running a 4.1.6 kernel with the 4.1.5-rt5 RT patch set, which applied cleanly and seems to run so far:

pi@rpi-jessie:~$ uname -a
Linux rpi-jessie 4.1.6-rt0-v7 #1 SMP PREEMPT RT Sun Sep 13 21:01:19 CEST 2015 armv7l GNU/Linux

This isn’t a very clean solution of course so let’s hope a real 4.1.6 RT patch set will happen or maybe I could give the 4.1.6 PREEMPT kernel that rpi-update installed a try. I packaged a headless ZynAddSubFX for the RPi on my notebook using pbuilder with a Jessie armhf root and installed the package for Ubuntu 14.04 from the KXStudio repos. I slightly overclocked the RPi to 1000MHz and set the CPU scaling governor to performance. The filesystem is Ext4, mounted with noatime,nobarrier,data=writeback.

To get the USB audio interface and the USB MIDI keyboard into line I had to add the following line to my /etc/modprobe.d/alsa.conf file:

options snd-usb-audio index=0,1 vid=0x08bb,0x09e8 pid=0x2704,0x007c

This makes sure the DAC gets loaded as the first audio interface, so with index 0. Before adding this line the Akai would claim index 0 and since I’m using ZynAddSubFX with ALSA it couldn’t find an audio interface. But all is fine now:

pi@rpi-jessie:~$ cat /proc/asound/cards
 0 [DAC            ]: USB-Audio - USB Audio DAC
                      Burr-Brown from TI USB Audio DAC at usb-bcm2708_usb-1.3, full speed
 1 [mini           ]: USB-Audio - MPK mini
                      AKAI PROFESSIONAL,LP MPK mini at usb-bcm2708_usb-1.5, full speed

So no JACK as the audio back-end, the output is going directly to ALSA. I’ve decided to do it this way because I will only be running one single application that uses the audio interface so basically I don’t need JACK. And JACK tends to add a bit of overhead, you barely notice this on a PC system but on small systems like the Raspberry Pi JACK can consume a noticeable amount of resources. To make ZynAddSubFX use ALSA as the back-end I’m starting it with the -O alsa option:

zynaddsubfx -r 48000 -b 256 -I alsa -O alsa -P 7777

The -r option sets the sample rate, the -b option sets the buffer size, -I is for the MIDI input and the -P option sets the UDP port on which ZynAddSubFX starts listening for OSC messages. And now that’s the cool part. If you then start zynaddsubfx-ext-gui on another machine on the network and tell it to connect to this port it starts only the GUI and sends all changes to the GUI as OSC messages to the headless instance it is connected to:

zynaddsubfx-ext-gui osc.udp://

Next up is stabilizing this setup and testing with other kernels or kernel configs as the kernel I’ve cooked up now isn’t a viable long-term solution. And I’d like to add a physical MIDI in and maybe a display like described on the Samplerbox site. And the project needs a casing of course.

Building a synth module using a Raspberry Pi

Raspberry Pi Revisited

When the Raspberry Pi 2 was released I certainly got curious. Would it be really better than it’s little brother? As soon as it got available in The Netherlands I bought it and sure this thing flies compared to the Raspberry Pi 1. The four cores and 1GB of memory are certainly an improvement. The biggest improvement though is the shift from ARMv6 to ARMv7. Now you can really run basically anything on it and thus I soon parted from Raspbian and I’m now running plain Debian Jessie armhf on the RPi.

So is everything fine and dandy with the RPi2? Well, no. It still uses the poor USB implementation and audio output. And it was quite a challenge to prepare it for its intended use: a musical instrument. To my great surprise a new version of the Wolfson Audio Card was available too for the new Raspberry Pi board layout so as soon as people reported they got it to work with the RPi2 I ordered one too.

Cirrus Logic Audio Card for Raspberry Pi

One of the first steps to make the device suitable for use as a musical device was to build a real-time kernel for it. Building the kernel itself was quite easy as the RT patchset of the kernel being used at the moment by the Raspberry Foundation (3.18) applied cleanly and it also booted without issues. But after a few minutes the RPi2 would lock up without logging anything. Fortunately there were people on the same boat as me and with the help of the info and patches provided by the Emlid community I managed to get my RPi2 stable with a RT kernel.

Next step was to get the right software running so I dusted off my RPi repositories and added a Jessie armhf repo. With the help of fundamental the latest version of ZynAddSubFX now runs like charm with very acceptable latencies, when using not all too elaborate instrument patches Zyn is happy with an internal latency of 64/48000=1.3ms. I haven’t measured the total round-trip latency but it probably stays well below 10ms. LinuxSampler with the Salamander Grand Piano sample pack also performs a lot better than on the RPi1 and when using ALSA directly I barely get any underruns with a slightly higher buffer setting.

I’d love to get Guitarix running on the RPi2 with the Cirrus Logic Audio Card so that will be the next challenge.

Raspberry Pi Revisited

The Infinite Repeat – Cala Del Aceite

Finally got around finishing a new track. And it’s just 65BPM so no four to the floor this time. I posted the demo a while ago, this is more or less a definitive version (definitive is a fluid term in my dictionary). … aceite.ogg

This song is about one of the most beautiful places I know on this
planet, Cala Del Aceite in the most southern part of Spain: … eConil.htm

Tools used:

  • Qtractor for recording and mixing
  • seq24 for sequencing
  • The necessary plugins:
    • drumkv1 to hold the drum samples (drum samples are all from
    • a lot of plugins that are part of Distrho or Carla: Noize Maker, Tal
    • Reverb III, ZynAddSubFX-LV2, Nekobi
    • MDA subsynth
    • FluidSynth DSSI for the Rhodes
    • linuxDSP plugins (EQ500, DYN500, MBC2B on the master bus)
    • Calf Vintage Delay
    • LADSPA comb filter, Fast Lookahead Limiter
    • GxZitaReverb

The background vocals for the choruses are sung by my wife. The ocean
sample is from Freesound:

Cádiz is pretty close to Conil, hence the choice.

Thanks to everyone for making this possible. Especially falkTX and rncbc, couldn’t have done this without your valuable work.

Making promises that I can’t keep
It’s pushing me, pushing me into a deep
State of sadness, state of doubt
A state of awareness I can’t live without

Making mistakes, so hard to bear
It’s driving me, driving me to a point where
I can’t escape, I can’t shy away
From the daemons I refuse to obey

All is forgiven, all is well…

Awaiting the day that I’ll be relieved
From this burden, this burden that has grieved
So many loved ones, so many friends
All the people on which I depend

Stand up, act now, it’s time for a change
Lingering won’t help, help to rearrange
The current imbalance, the current state
Of things so rush now don’t hesitate

All is forgiven, all is well…

Creative Commons License
Cala Del Aceite by The Infinite Repeat is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

The Infinite Repeat – Cala Del Aceite

The wait is almost over

For years users have been asking for a ZynAddSubFX or Yoshimi plug-in with a GUI for Linux. It seems the wait is almost over thanks to the great work of Filipe Coelho aka falkTX.

ZynAddSubFX-LV2 Test #1 (Qtractor)

According to falkTX work on the plug-in is almost 90% done. Parameters can be restored too as the following video shows.

ZynAddSubFX-LV2 Test #2 (Ardour)

Apparently the developer of ZynAddSubFX is working on exposing all parameters so in the future it should also be possible to automate Zyn’s most relevant parameters. Needless to say this stuff is still highly experimental so use at your own risk. I’ve done quite some tests and the plug-in keeps up well, also if you use many of them within a project (I’ve tested with a project with about 15 ZynAddSubFX-LV2 instances). But this doesn’t mean the plug-in doesn’t have any flaws, closing its GUI could crash your DAW for instance. Further tests should reveal all the obvious bugs so everyone, get that code and test it! Build instructions can be found in the aforementioned forum thread.

Many, many thanks to falkTX for making this possible!

The wait is almost over

Carla on the Raspberry Pi

Last week I managed to get Carla running on my RPi. Carla is a really nice plugin host that supports the most important plugin frameworks available for Linux (LV2, DSSI, LADSPA and VST) with some awesome extra features like a built-in ZynAddSubFX synth and support for SF2, SFZ and GIG files. The latter didn’t work until yesterday but I managed to compile LinuxSampler (which is needed by Carla in order to be able to load SFZ and GIG files) for the RPi with the help of Paul Brossier aka piem from the Aubio project.

I just wrote him a mail:

Hello Paul,

I’m trying to package LinuxSampler for Raspberry Pi but I’m running into an issue when compiling which fails with a message related to RTMath.h. After some googling I ended up here:
So I started scouring the interwebs and found this:
Where there is a reference to a possible fix. But the diff.gz that contains the patch is untraceable. I know this announcement is almost 8 years old but do you think you still have the diff or maybe an idea what changes you made to the code?

Thanks in advance and keep up the good work with Aubio!

Best regards,

Jeremy Jongepier

And guess what, he replied almost instantly! He gave me some pointers where to add some extra code and even though I’m not a coder I started trying things out. But then I stumbled upon actual patches to resolve this issue. I needed both the ARM and atomic patch and after applying those LinuxSampler compiled flawlessly in my Raspbian ARM chroot. The few lines of code I cooked up myself were almost identical so I got quite far actually. I should really pick up learning how to code, I think I’d learn fast.

So after compiling LinuxSampler I could rebuild Carla against the freshly created LinuxSampler libs. Installed the deb on my RPi and loaded some SFZ’s. It all worked like a charm. Carla is like a Swiss Army Knife, I’m really starting to appreciate this piece of software. Kudos to falkTX! And thanks to Paul Brossier for responding so quickly and helping me to get on the right track.

text-align: center;

Carla running on the Raspberry Pi

Carla on the Raspberry Pi

Yoshimi 1.0.0

Op 2 juli is Yoshimi 1.0.0 uitgekomen ter nagedachtenis van Alan “Cal” Calvert die op die dag precies een jaar geleden overleden is. Naast wat kleine aanpassingen en patches is het vooral een eerbetoon aan Alan Calvert. En Yoshimi is stabiel genoeg voor een 1.0.0 release. De planning is nu dat ik ga werken aan het aanpassen van de sources om Yoshimi 1.x.x weer dichter bij ZynAddSubFX te brengen zodat op de lange duur de projecten samen zouden kunnen smelten. De ontwikkelbranch (nu 0.062.x) zal wel blijven bestaan.

Yoshimi 1.0.0