Pure Data - Visual Programming Language for Audio

fihra

Fabian Fabro

Posted on August 7, 2024

Pure Data - Visual Programming Language for Audio

What is Pure Data?

It is an open-source programming language that is used to process and generate audio, video, 2D/3D graphics, interface sensors, input devices, and MIDI.

This was developed by Miller Puckette, who is also the author behind Max/MSP, the more well-known visual programming language for audio and multimedia.

The way the language is set up is using boxes of objects and placed in a window on a "patch" file.

Here is an example of how it looks.
Note: This is using "PlugData" program, which is more modern looking version from the original PureData program.

You can download Plugdata here: Plugdata
To check out and download the original PureData: PureData

Hello World

There are 3 types of objects that are being used here for this "Hello World" app.

How to input objects:
In PlugData, at the top left menu, there is the "Add Object" button that opens a list of objects to drag and drop.

For keyboard shortcuts, I used for the following objects:
Bang: Control + Shift + B
Message: Control + 2
Print: Control + 1

At the top, is a GUI object known as a "Bang" operator.

The middle is a "Message" object. Notice at the right side with the darken edges.

And the bottom is a general object using [print].

When the user clicks the "Bang" button, it sends an immediate trigger action to its outlet (the cable connected from the bottom to the next object).

Following the strings of lines, the "Message" object can contain any type of data: a string, int, float, symbol, etc. As it is object that represents data. In this case, it represents as a string "Hello World."

And to the last box, "Print" which in code terms, is a keyword that's part of PureData, which basically prints to the console on the right pane.

The 2nd Hello World also allows to set the string as a 'parameter' to the right of "print," though the console does print it slightly different with the message being first, and printing the "Bang" operator.

Hello World 2

Alright enough with words, Pure Data is meant to sounds, so I'll demonstrate a simple sound synthesis.

Note: Make sure to check your audio settings from PlugData/PureData that way you know you'll get audio feedback. Make sure your Audio Output "Output Device" is set to your designated speaker you're using. Sample rate should be fine with either 44100 or 44800. Buffer size is fine at 480, usually I'd go higher to at least 1024 just to get more audio buffers.

Settings

IMPORTANT NOTE: I'm glad PlugData included this, but adjusting your volume here is important since anything could happen when testing sound. So keeping at lower volumes is highly recommended. I've had moments where audio blasts and pops up while I'm experimenting around, which could damage your speakers, AND YOUR EARS!

Volume Setting

LET THERE BE SOUND!!!!

osc

Congrats, you made your first oscillator sine wave! OMG MAKE IT STOP!! Just disconnect the last two cables under [dac~].

Now what's going on here?

You noticed something about the colors with these objects. The sockets above the box are called "Inlets" while the bottom ones are called "Outlets." Basically they are the inputs and outputs that are connected through each box. But notice the colors too. These have orange sockets on the left side, and blue on the right side. If we look back on the Hello World, they were all blue.

The way the objects interact is through the "Audio Rate" and the "Control Rate."

In a nutshell, Audio Rate is connected through the orange inlets and outlets, while the Control Rate is connected by the blue inlets and outlets. Also if you notice the squiggly line on the audio rate objects (Tilde), is also mainly for audio rate objects.

Audio Rate objects handle anything that affects the audio signal directly, while Control Rate objects handles any informational or calculations to set values to audio rate objects.

Alright, let's at least go over what is going on with this oscillator.

[osc~ 440]

'osc' is built-in PureData that generates a cosine wave. Adding 440 gives the frequency input of 440hz, which is A4 (musical note A above middle C).

[*~ 0.5]

This multiplies the signal by 0.5. In this case, this multiples the oscillator to lower its volume.

[dac~]

This stands for "Digital to Analog Converter." The opposite of this is [adc~] for "Analog to Digital Converter."


For digital to analog, this means that we are taking a digital signal, in this case the oscillator we are feeding it, and outputting it to a speakers on the Analog side.

If it was analog to digital, it would be at the top of the patch file, and it could take in microphone input, because the analog signal is coming from what's being heard from the microphone, then translating it to digital data to be able to process the audio signals in the rest of Pure Data objects connects, and finally end with a dac~ to output it.


Notice that [dac~] is connected by 2 inlets from above. This is to output on the left and right speaker. Try to remove one of the cables, and you will hear the audio from that speaker only.

What's at least nice on this interface, and also on Pure Data's program, is that when you right click on objects, and click "help," it opens a new tab with descriptions and examples of that object.

There are keyboard shortcuts you get used to when adding objects around. PlugData is nice that it gives you the toolbox at the top bar to add all the objects.

Here are samples of my Pure Data sound design project that I worked on where I designed sound effects for a small RPG game I developed called "The Mysterious Gate."

Excuse the mess of all the objects scattered everywhere. I wish Plug Data had more features to organize sections across the patch. Or maybe there is, I just haven't figured it out yet.

Mysterious Gate

Few examples:

Charge up Magic
Charge Up Magic

Ice Damage
Ice Damage

Check out the game here.
Free to play on browser at itch io: Play The Mysterious Gate

From what I learned so far, visual programming is a nice gateway for non-programmers to get into programming if code is overwhelming. I do come from a coding background and at first I was intimidated or perplexed seeing visual programming because of not seeing them as lines of code. However, I decided to keep an open mind and now I appreciate both worlds of traditional code and visual programming.

And especially for my journey in learning more audio programming, I think learning Pure Data has helped me grasp a little more understanding in this topic because going into the traditional code route for audio programming was extremely difficult for me at least.

How did I pick up Pure Data? I took a course from School of Video Game Audio.

Why I learned Pure Data? Since being interested in Audio Programming but not having a Computer Science degree feels like it's made my journey tougher to learn, but Pure Data feels like a nice stepping stone to understand a little bit of what's happening in a visual perspective with audio signal processing.

What other visual programming languages can this transfer to after learning Pure Data?

Max/MSP is a common one that I've seen musicians and media artists use, although it is not free.

Max/MSP

MetaSounds in Unreal Engine is a pretty recent tool within the engine.

MetaSounds

I just wanted to write this quick short introduction to Pure Data since I've been working with this recently, especially with my sound design work with sound synthesis. I hope this helped with taking a little jump start into it. I'd say YouTube tutorials really help to follow, especially since this is also for getting listening feedback that you can't always get through following a 'words only' tutorial.

Resources:

School of Video Game Audio
Plugdata
PureData

QCGInteractiveMusic YouTube Playlist

Sound Simulator Playlist

💖 💪 🙅 🚩
fihra
Fabian Fabro

Posted on August 7, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related