In Part 1 of our New Meris Maker Series, we looked at the materials you’ll need to get started with using your Raspberry Pi to process guitar. Here in Part 2, we’ll install and configure Pure Data on your Pi, as well as pass audio through the Griffin iMic.
Pure Data (aka Pd) is an extremely powerful and free digital signal processing tool for audio and video. It is a real-time graphical programming environment that lets you build effects and algorithms by connecting components together in the same way you would connect stompboxes in the real world. The whole experience, while not conventionally pretty (yet beautiful in it’s own way), feels really natural for a guitar player. Words can’t express what an extreme amount of gratitude I feel towards Miller Puckette and his incredible team for creating Pure Data. While working at Line 6, I had the good fortune to work side by side with Pd contributor Joe Sarlo. Not only was Joe a DSP powerhouse, I learned tons about system design from Joe and his work.
Let’s get started! While the Raspberry Pi is powered down, connect the iMic to one of the Raspberry Pi’s available USB ports. Now power up the Pi. If you pay close attention, you should be able to see the iMic getting enumerated in the boot sequence, don’t worry if you miss it, we’ll verify that it is connected later in this post.
To install Pd, type the following at the command prompt after booting up:
sudo apt-get install puredata, press enter, and acknowledge that you want to install.
After the installation is complete, start up LXDE by using the startx command. You should see Pure Data in the Sound & Video tab of the LXDE start menu in the bottom left corner.
Go ahead and click on Pure Data to launch the application.
Let’s start by selecting the iMic as the audio input and output device. First, navigate to the Media menu in the main Pd window, scroll down to Preferences, and select Audio Settings. While here, select the iMic hardware as both the input and output device and save your settings:
Not So Quick Side Note on Audio Settings
While you are looking at the Audio Settings page, you probably can’t help but notice the other interesting settings available. Or more accurately, I can’t resist mentioning them. These parameters (Sample rate, Delay, Block size) directly affect the performance of Pure Data.
Sample rate determines how many samples per second are used to represent the audio signal. Higher sample rates means higher audio fidelity, but also higher settings also mean that your Raspberry Pi will be doing more work across the same interval of time.
Delay, in this case, represents how much latency Pure Data is adding to the system. A longer delay setting means that your Raspberry Pi will have more time to do the work necessary for the current effect, but longer delay times will also introduce a noticeable lag between the time you pluck a note and the time you hear it.
Block Size is a little bit less intuitive, but like the other two parameters, gives you some flexibility in trading off latency vs available horsepower. Pure Data processes audio in blocks (also known as frames) as opposed to processing each sample, one at a time. You can think of each object in Pure Data as a function call. One of the advantages to block processing is reducing function call overhead. What this means is that, instead of setting up the memory necessary for the dsp process about to be performed each and every time you get a new sample, Pure Data will do this setup once for a group of samples in a frame. One of the negative effects of block processing is that any feedback loops will always have a minimum delay of the block size. I keep this setting at it’s default (64 samples).
These parameters give you the ability to trade off latency and frequency response for more available horsepower for Pure Data to run your effect. Once you have Pd running and passing audio feel, free to revisit these settings and experiment to find a compromise that is right for you.
Let’s set up an input source and an output destination in Pd so that we can pass some audio through the system. In the main window of Pure Data, navigate to File and click New.
This will create a new patch where you will place audio and control objects.
Raspberry Pi Tip: Depending on your monitor and screen resolution, part of the new window may appear off of the screen, if that happens, no worries just drag the window hold the Alt key to drag the window around to a more convenient location.
After you’ve created your empty patch, we will need to fill it with objects. Navigate to the Put menu and click Object (or just hit Ctrl+1) to add your first object.
At first the object will appear empty. You’ll need to type inside the box in order to change the object into the processing element that you need. In this first object let’s type adc~ this will give us an analog to digital converter to bring audio in from the iMic. Now, using the same method as before, add a second object. In this object type dac~ this will give us a digital to analog converter to send audio back to the iMic and out to whatever amp and speaker we are using. Now that you have created your input and output, it’s time to wire them together. Since the iMic has a mono input, connect both inputs of the dac block to the left output of the adc.
The patch should look like this when you are done:
In order run your patch you’ll need to check the DSP box in main window like this:
You should now have audio passing from the input of the iMic, through your Raspberry Pi, and then back out the iMic. Congrats! If you aren’t passing audio, now would be a good time to check and double check your cables, connections, guitar volume knob, and speaker settings. You may also want to switch your iMic slider from Line to Mic, this will give a little boost to your signal, and is useful if you are troubleshooting and need more gain.
For extra credit, add another object and type rev2~ 100 90 3000 20 into it. This will setup a simple reverb with some reasonable default parameters. Running the patch the way I have wired it below will give you dry guitar on the left channel and reverb on the right channel.
There is so much more useful Pure Data ground to cover: Edit vs. Run Mode, Hot Inlets vs Cold Inlets, Control Signals vs Audio Signals, but that will have to wait for a future post. Until then, you can watch YouTube user cheetomoskeeto’s tutorial series on Pure Data for more tips, tricks, and ideas.
In the next post, we’ll connect a USB foot controller to the Raspberry Pi and use it to control Pure Data. Stay tuned and thanks for reading.
(Angelo Mazzocco is a DSP Engineer/VP at Meris)