Introduction: Beginner Pure Data Tutorial: Basic Synth

Pure Data is a free, open source, real-time graphical dataflow programming environment for audio, video, and graphics processing.  It is especially great for writing interactive audio, video, and graphics applications because it can be easily hooked up to hardware (sensors, cameras, kinect, arduino...) and other software (processing, ableton...) to create some really amazing work.

Programming in pd is not command line, instead it uses a graphical interface where data flows through objects via inlets and outlets.  This interface makes it much easier for non-programmers to get their ideas down quickly and easily and makes designing a graphical user interface for your applications very straightforward.  Pd runs in real-time which is helpful for debugging and understanding how objects are interacting with each other.

Step 1: Getting Started

The first step is to download Pure Data.  There are many versions available, start with Pd extended.

When you open pd a dialog box like the one pictured above will appear, ignore this for now.  Programming in pd is done in files called "patches," to open a new patch go to File>>New.  Once you have a new file open go to Put>>Object or ctrl/command + 1 to start building your patch.  A box will appear near your cursor; click somewhere within the space of your new patch.  You can then type the name of the object into the box and click to create the object.  Try out some simple objects like "slider" or "+", right click and select Help to learn more about how these objects are used.

Step 2: Basic Synth Patch

This patch will introduce some objects that are useful for audio processing.  All audio processing objects in pure data are denoted with a "~" at the end of their name.  For example, a "+" object will add together two numbers, but a "+~" will add together two audio signals, or an audio signal and a number.  If you try to connect a signal into the inlet of a regular "+", the connection will disappear.

The most fundamental object in a synth patch is "osc~", this object generates a sine wave.  You can specify the frequency of the sine wave by including an argument such as "osc~ 440"; this oscillator will generate a sine wave with a frequency of 440Hz.  You can also send the frequency of the osc~ object through it's top left inlet.  Remember if you want to find more info about any of the objects, right click on the object and select "Help".

Next create a "dac~" object, dac stands for digital to audio converter.  This object will route audio from pd to speakers or the audio output jack of your computer.  The left inlet sends audio to the left channel and right inlet sends it to the right channel.  Connect the outlet of the osc~ 440 to the inlets of the dac~ as shown in the first image.

No sound is coming out of your speakers yet.  This is because we have to tell pd to turn on its digital signal processing.  Do this by selecting "compute audio" on the pd-extended main window (figure 2).  You should hear a sine wave, if you want it to stop, uncheck compute audio.

The sine wave output from osc~ has an amplitude of 1 by default; signals sent to the dac~ must be between -1 and 1 or they will be clipped and sound distorted.   If we want to change the overall gain/volume of the signal we need to add some more objects.   As shown in figure 4, create a "slider" and "*~" object and connect them so that the output from osc~ is multiplied by the slider value.  Notice the "/ 127" object in the path between the slider and *~.  The slider object outputs values between 0 and 127, but if we multiply our sine wave by anything larger than 1 it will be distorted in the dac~ (go ahead and try it).  Dividing by 127 scales this number so that it is always between 0 and 1, now dragging the slider up and down should raise and lower the volume of the sine wave.   Use numberbox objects ("nbx") to double check that everything is working properly (figure 4).

Next attach a numberbox ("nbx") to the left inlet of osc~ as shown in figure 5- this object will modulate the frequency of the osc~ object.  Use control/command + e to switch out of edit mode  (also Edit>>Edit Mode) and click and drag the numberbox to change its value.  Once you get above about about 30Hz you will hear a low frequency sine (make sure compute audio is checked!).

In figure 6 I have included some additional objects and connected them to the left inlet of osc.  These objects will give our main sine wave some vibrato (wavering frequency).  The osc~ 5 object outputs a sine wave of frequency 5Hz.  Next and *~ gives the 5Hz sine wave an amplitude of 20.  And finally, The sine wave is offset by 440 by the +~ object, this means that this signal coming out is a sine wave which oscillates between the numbers 420 and 460 at a frequency of 5Hz.  When this signal is fed into the left inlet of another osc~, it sets the frequency of that osc~ to waiver between 420 and 460Hz at a frequency of 5Hz.  This is called frequency modulation.  Get out of Edit Mode and use the numberboxes to change the amplitude, rate, and center frequency of the frequency modulation to get a better understanding of how it works.

I've attached this patch below.