This post aims at explaining how to install and configure Pure Data on the Raspberry Pi in order to turn your RPi in a real-time multi-effects. I have tried to make it understandable to people who aren’t use to Linux and the command line. The fact that Pd can run with such a low latency (it can go below 10 ms) with an external soundcard is very new, and is the results of recent improvements in the Raspbian distribution. A lot of people have been trying to achieve this in the Pd community over the past few months, and this recent success was great news for at least a few of us !
The first thing you need to do is prepare a SD card with the latest Raspbian distro. You can download the image here, and follow the instructions on how to write it to a SD card here. You’ll need a 4GB SD (or bigger, though it is not necessary for this application), and it has to be Class 6 at least.
Once your SD is ready, you can start your RPi with hdmi screen, usb keyboard and mouse plugged in. You’ll see a configuration screen after a few seconds. There you can configure your keyboard layout, and also expand Raspbian so that it fills the entire SD card (this can be useful if you want to store big audio samples for instance). You can then reboot the RPi (just unplug and replug the power cord).
From now on you’ll need a ethernet cable connected to your Raspberry Pi so that you can download Pd. When your RPi starts you’ll see many lines printed on the screen while it’s loading. When it’s done you’ll see
Raspberrypi login: _
with a blinking underscore. This means that you need to login as a user to send commands to the RPi. Your login is “pi”, and the password “raspberry”. Hit enter after you typed the login, and enter again after you typed the password. You should now see
pi@raspberrypi ~ $
. This is the command prompt. Now we can start working !
To install Pd, type :
sudo apt-get install puredata
, and press enter. You’ll see a few lines on the screen, and you’ll asked if you want to proceed. Type “y” and press enter. Wait until you see “pi@raspberrypi ~ $” again.
To check that Pd was installed correctly and is working fine you can start the “desktop” (X Window System) by entering the following command :
You can then find Pd by clicking on the LXDE icon in the bottom left corner, and going into the “Sound & Video”. Now we assume that it’s installed and that you are back in the command prompt.
The previous command installed Pd-vanilla, that is, the plain, standard version developped by Miller Puckette (as opposed to the richer pd-extended). In order to use pduino to read data from the arduino-based pedal, you’ll need to download a few other packages (comport, cyclone, mapping, zexy). You can install them by entering the following :
sudo apt-get install pd-comport pd-cyclone pd-mapping pd-zexy
Now that we have installed Pd and a few externals, we need to configure it.
Before you go ahead with fine tuning the configuration of Pd, you should test your external soundcard with the Raspberry Pi and Pd (with the graphical interface -GUI- for easy changes in the settings). Mine works just fine (E-MU USB 0404), but other Pd users have had mixed results with other soundcards – I hope to be able to write more about this later. You can test your soundcard by making a very simple patch ([adc~] connected to [dac~]), selecting your soundcard as input and output interface in the audio settings, and turning on audio computation. If it works (which I hope!), you can go back to the audio settings and try to reduce the audio buffer from 100 ms to 50, then to 20, etc. I can go to 10 ms of latency with my card, even with the GUI, with very little audio dropouts (glitches). without GUI I get no dropouts at all with a simple patch.
Assuming your soundcard works fine, you’ll need to make the settings permanent. The easiest way to do it is to edit the “.pdsettings” file. To do this, assuming your in the command prompt (open the terminal if your are in the “desktop”), and assuming you are in “/home/pi” (it should be the case if your can see this line “pi@raspberrypi ~ $”), type :
This opens a text editor (don’t try to use your mouse, it only works with the keyboard!). You should see something like this :
audioapi: 1 noaudioin: False audioindev1: 2 2 noaudioout: False audiooutdev1: 2 2 audiobuf: 16 rate: 44100 callback: 0 blocksize: 64 nomidiin: True nomidiout: True path1: /usr/lib/puredata/extra path2: /usr/lib/puredata/doc path3: /usr/lib/puredata/doc/3.audio.examples path4: /home/pi/pd-extra/Pduino-0.5 npath: 4 standardpath: 1 verbose: 0 loadlib1: zexy nloadlib: 1 defeatrt: 0 flags: -rt
The most important lines are “audioindev1: 2 2″, “audiooutdev1: 2 2″ (this tells Pd to use your external soundcard by default), “audiobuf: 16″ (tells Pd to use a buffer -latency- of 16 ms, this could be lower if your patch is simple), and “rate: 44100″ (this is the sample rate. I haven’t tried anything higher, but this is already pretty good, and any higher value will further increase the latency). Once you have edited the file, do Ctrl+X, hit “y”, and press enter to save the changes.
I’ll write more posts later about fine tuning Pd’s settings, and also about how to launch it at startup automatically so you don’t need any keyboard or screen. In the meantime, feel free to read previous post about guitar effects in Pd, or send me your comments or questions.