RPi as guitar effects processor : Installing and configuring Pd

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 !

Setting up your Raspberry Pi                 Raspi_logo

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 !

Installing Pure Data                   PureData_icone

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 :

startx

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.

Configuring Pd

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 :

nano .pdsettings

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.

This entry was posted in Software, Uncategorized and tagged , , , , . Bookmark the permalink.

12 Responses to RPi as guitar effects processor : Installing and configuring Pd

  1. Flomoto says:

    Thats sounds quite easy. The problem for me would rather be to find the same usb audio card, this one doesn’t seem to be still manufactured… Maybe one can find a second-hand one.

  2. Pingback: Real-time guitar effects with Raspberry Pi, Pd and Arduino | Guitar Extended

  3. MarcB says:

    First of all, congrats on the great work!
    However, to get the latency down a bit more you could try running pd with Jack instead of ALSA. Have you already tried that?

    I’m really interested in seeing this further developed, although at this very instant I have my hands full so I cannot commit to any devel work. I was thinking of running a headless RPI on a stripped Raspbian with PD and Jack running with critical priorities (by means of internal switches and nice’d to the max).
    Control and patch selection would be done via a minimal web interface running on nginx. Just click on a patch, hit the ‘Load’ button and Bob’s your uncle. Or you could create a patch in pd-extended on your laptop then upload it to the RPi via HTTP and rock away.

    I would really like to commit to this project in a month or so, so get back to me if you want to set up a repo on github :D.

    P.S. Also, check out Justin Sandercoe if you’re really into guitar, I learned heaps from this guy, including how to play. He’s really amazing.

    • Hi, I haven’t tried with JACK yet, but running Pd in rt with maximum priorities doesn’t really improve latency as far as I know (i have made a few tests). I believe the linux kernel has incorportated enough of the previous rt kernels to make JACK less important for latency, but I might be wrong.
      I already use the Pi headless all the time, I use ssh or ftp to modify or upload the patches.
      I don’t know Justin Sandercoe, but thanks for the suggesting, i’ll see what he’s done.
      I have no plan to set up a repo in the very near future, but your ideas or suggestions are most welcome.

  4. xxx says:

    hi,
    did you by any chance try to get the soundhack externals running? most externals work fine on my rpi, but those i can’t seem to get working.

    thanks!

  5. toby says:

    Hi,

    How did you manage to get pduino working on raspberry pi? When I try the arduino object shows up red. Iv also installed the comport, cyclone, mapping and zexy but this is still happening. Any ideas?

    Kind Regards,
    Toby

    • Hi,
      You need to put the pduino folder in a place where Pd can find it. You should add this folder to the “Start” paths in Pd. This should solve the red-dotted-object problem. Once the object is created, you should also check that the libraries you mentioned are effectively loaded (missing libraries will show up in red in Pd’s main window).

  6. Colin says:

    Hello,

    This project is fantastic! I’m trying to do something similar to do some audio pre-processing for a device I want to build. I’m trying to set up PureData to work with the USB audio device I have. I have everything set up and working, but the audio coming in when I hit “Monitor Inputs” in PD is absolutely distorted. I don’t think the usb device is the issue, as when I use the alsamixergui and listen to the input it sounds fine. Any suggestions on how to improve the audio quality?

    Thanks,
    Colin

    • Hi, it hard to say as “distorted” can mean many things. Make sure the gain isn’t too hi on your soundcard first. Or maybe it’s a latency issue (the computer doesn’t have time to process all the audio and you hear “dropouts”), which can be fixed by increasing the size of the buffer in PD’s audio settings, on in JACK if you’re using it. It could also perhaps be a sample rate problem (PD runs at 44100 HZ by default), so check that your card is set on the correct rate.

  7. Pingback: Raspberry pi e L2Ork | sound objects

Leave a comment