Pure Data Lab Guide

Five projects that build a synthesizer out of boxes and wires.

Before you start

Basics of Pure Data

Pd has two kinds of things you place on the page. An object box does a job, like making a sine wave. A message box sends a number or word when you click it.

Objects ending in a tilde (~) work with audio, like osc~. Objects without a tilde work with plain numbers.

You connect boxes with wires: drag from the outlet (small dark rectangle at the bottom of a box) to the inlet (top of the next box).

Shortcuts on the Pd patch: Ctrl+1 makes an object box. Ctrl+2 makes a message box. Ctrl+3 makes a number box. After you place the box, type in it and click on an empty part of the patch to finish it.

To make the audio work, turn on DSP (audio processing). In many versions this is a checkbox or a button labeled DSP or “audio on”.

Edit mode lets you move boxes and draw wires. Run mode lets you click and change numbers. Ctrl+E switches between them.

Good practice

Connections to other tools

Terms


PD1 Hello Oscillator

Goal

Make your first sound: a steady tone from an oscillator, with a volume control that keeps it safe for your ears.

What you need

Pure Data open in your browser (see the Sound tools page for the link), and headphones. Time: about 20 minutes.

Steps

1. Turn the volume down

Turn your Chromebook volume low. Put on headphones.

2. Open a new patch

Open a new empty patch in Pure Data. Click on the patch so it has focus.

Checkpoint: you see a blank patch window.

3. Make the oscillator

Press Ctrl+1 to place an object box. Type osc~ 440 and click on an empty part of the patch.

Checkpoint: a box that says osc~ 440 with one outlet at the bottom and two inlets on top.

4. Make the volume control

Press Ctrl+1 again and place a second box under the first. Type *~ 0.1 and click on an empty space.

Checkpoint: a box that says *~ 0.1. This multiplies the sound by 0.1, which makes it much quieter.

5. Make the speaker box

Press Ctrl+1 once more and place a third box at the bottom. Type dac~ and click on an empty space.

Checkpoint: a box that says dac~. It has two inlets: the left speaker and the right speaker.

6. Connect them

Drag a wire from the outlet of osc~ 440 (bottom left) to the left inlet of *~ 0.1. Then drag a wire from the outlet of *~ 0.1 to the left inlet of dac~, and another wire from the same outlet to the right inlet of dac~.

Checkpoint: three wires. The sound goes oscillator, then volume, then both speakers.

7. Turn the sound on

Turn DSP on (the checkbox or button labeled DSP or “audio on”).

Checkpoint: you hear a steady quiet tone. It is the note A.

8. Change the volume

Turn DSP off. Double-click on the *~ 0.1 box while in edit mode, change 0.1 to 0.3, click away, and turn DSP on again.

Checkpoint: the tone is louder. Be careful. Do not go above 0.5.

Try it

What’s happening

osc~ makes a sine wave at the frequency you give it. The number after osc~ is the frequency in Hz. The wave is a list of numbers made 44,100 times each second. The *~ multiplies each number, so a smaller number gives a smaller wave and a quieter sound. dac~ (digital to analog converter) sends the numbers to your speakers.

If you hear nothing

Note

Pd steps were written from memory and have not been tested. The browser version of Pd may use different menu names. If a step doesn’t match what you see, flag it so the page can be fixed.


PD2 Pitch and Volume

Goal

Change the pitch and volume while the sound plays, then add vibrato (a wobbling pitch) and tremolo (a pulsing volume) using a slow oscillator, called an LFO.

What you need

Your PD1 patch (osc~, *~, dac~). Headphones. Time: about 30 minutes.

Steps

1. Open your PD1 patch

Open it and save a copy as “PD2”. Turn DSP on and check that you can hear the tone.

2. Add a pitch control

Place a number box (Ctrl+3) above the osc~ box. Connect its outlet to the left inlet of osc~. Switch to run mode (Ctrl+E). Click and drag the number box up and down.

Checkpoint: the pitch changes as you drag. Try 220, 440 and 880.

3. Add a volume control

Place a second number box above *~. Edit the *~ box to be just *~ with no number, then connect the new number box to the right inlet of *~. Switch to run mode and drag the number between 0 and 0.3.

Checkpoint: you control the volume with a number. Keep it below 0.5.

4. Make vibrato

Switch back to edit mode. Make this chain of boxes to the left of your main patch, and wire each to the next:

osc~ 5
*~ 10
+~ 440

Connect the +~ 440 output to the left inlet of your main osc~ (replace the pitch number box connection, or remove the number box for now).

Checkpoint: the pitch now wobbles around 440, 5 times a second, by about 10 Hz above and below. This is vibrato.

5. Change the vibrato

Change osc~ 5 to osc~ 2 for slower, then to osc~ 8 for faster. Change *~ 10 to *~ 30 for a deeper wobble.

Checkpoint: you hear the wobble change speed and depth.

6. Make tremolo

Undo or delete the vibrato chain. Keep the pitch at osc~ 440. Now make this chain, with each box wired to the next:

osc~ 4
*~ 0.5
+~ 0.5

Connect the +~ 0.5 output to the right inlet of a new *~ box (with no number) placed between your osc~ 440 and your volume *~ 0.1. That is, osc~ 440 goes into the left inlet of the new *~, and the new *~ goes on to *~ 0.1.

Checkpoint: the volume pulses 4 times a second, which is tremolo.

Try it

What’s happening

An LFO is just an oscillator that runs too slowly to hear as a note. Instead we use it to control another sound. For vibrato, the LFO moves the main pitch up and down. For tremolo, it moves the volume up and down. Here *~ sets how strong the effect is, and +~ sets the middle value it moves around. Most synthesizers are built this way: one wave controlling another.

If it doesn’t work

Note

Pd steps were written from memory and have not been tested. If a step doesn’t match what you see, flag it so the page can be fixed.


PD3 Waveforms

Goal

Hear how three wave shapes (sine, saw, square) sound different at the same pitch, and learn to build each one from simple boxes.

What you need

Pure Data and headphones. Time: about 30 minutes. You can start a fresh patch.

Steps

1. Start with the safe output

Place these two boxes, with the *~ above the dac~, and wire *~ 0.1 to both inlets of dac~:

*~ 0.1
dac~

Turn DSP on later, only after the oscillator is connected.

2. Sine wave

Place osc~ 220 above the *~ 0.1 box and wire it in. Turn DSP on.

Checkpoint: a smooth, pure, soft tone. Turn DSP off.

3. Saw wave

Place a new box phasor~ 220 off to the side and wire its outlet to the left inlet of *~ 0.1. Take the sine wire out first. A phasor~ counts from 0 up to 1 and then drops back to 0, over and over, so it makes a saw wave. Turn DSP on.

Checkpoint: a buzzy, bright tone at the same pitch. Same note, different color. That color is called timbre.

4. Center the saw

Between phasor~ 220 and *~ 0.1 insert a new box -~ 0.5, and wire phasor~ into -~ 0.5 and then into *~ 0.1.

Checkpoint: it sounds almost the same, but the wave now goes below and above zero, like the sine did. The speaker moves evenly in both directions.

5. Square wave

Take the -~ 0.5 box out for a moment. Make this chain and wire each to the next:

phasor~ 220
>~ 0.5
-~ 0.5

Send the end of the chain into *~ 0.1.

Checkpoint: a hollow, nasal tone. A square wave is made by turning the saw into either 0 or 1 depending on whether it is above 0.5.

6. Compare the three

Wire all three oscillators into three separate *~ boxes with a different volume each, and mix them into dac~, or simply swap the wire from one to another as you listen. Say out loud what each one sounds like.

Checkpoint: you can describe each: sine (smooth), saw (buzzy and bright), square (hollow).

7. Try the same on a higher and lower note

Change 220 to 110 and then to 440 in each of the oscillators.

Checkpoint: the timbre stays the same, but the pitch changes.

Try it

What’s happening

Every sound is a wave, and the shape of the wave is its timbre. A sine wave has only one frequency in it. A saw or square wave is made of the main frequency plus many higher ones (harmonics) added together, which is why they sound brighter. In Data Science DS4 you can measure this: record or build the tones, and compare their spectra. A sine has a single spike. A saw has many.

If it doesn’t work

Note

Pd steps were written from memory and have not been tested. If a step doesn’t match what you see, flag it so the page can be fixed.


PD4 Filters

Goal

Shape a bright, buzzy sound by cutting out some of its frequencies with a filter, and sweep the filter by hand to make the classic synth “wah” sound.

What you need

Pure Data and headphones. Your saw wave from PD3. Time: about 30 minutes.

Steps

1. Build a saw wave patch

Place and wire these boxes, in order from top to bottom:

phasor~ 110
-~ 0.5
*~ 0.1
dac~

Wire *~ 0.1 into both inlets of dac~. Turn DSP on.

Checkpoint: a low buzzy tone.

2. Add a low-pass filter

A low-pass filter lets low frequencies through and cuts the highs. Place a new box lop~ 1000 between -~ 0.5 and *~ 0.1. Wire -~ 0.5 into lop~ 1000, and lop~ 1000 into *~ 0.1.

Checkpoint: the tone sounds duller and softer. The number 1000 is the cutoff frequency in Hz.

3. Change the cutoff

Place a number box (Ctrl+3) and connect it to the right inlet of lop~. Switch to run mode (Ctrl+E). Click and drag the number box between 100 and 5000.

Checkpoint: low numbers sound muffled, like it is behind a wall. High numbers sound bright again.

4. Sweep it

Now make the sweep move on its own. Make this chain, and wire each to the next:

osc~ 0.5
*~ 800
+~ 1000

The lop~ cutoff only takes a plain number, so for a moving sweep use a filter whose cutoff can be a signal. Place a new box vcf~ 3. Send the saw wave from -~ 0.5 into the left inlet of vcf~ 3. Send the output of +~ 1000 into the middle inlet of vcf~ 3. Send the right outlet of vcf~ 3 (the low-pass output) into *~ 0.1 instead of lop~.

Checkpoint: the sound slowly opens and closes, twice every four seconds. This is the wah sound.

5. Try a high-pass filter

A high-pass filter cuts the lows and lets the highs through. Replace lop~ 1000 with hip~ 1000.

Checkpoint: the tone sounds thin and tinny.

6. Try a band-pass filter

Replace hip~ with bp~ 1000 3. The first number is the center frequency and the second is how narrow it is (Q).

Checkpoint: only a narrow slice of the sound passes. It sounds like a nasal voice.

Try it

What’s happening

A saw wave is full of harmonics. A filter removes some of them. A low-pass filter takes out the high harmonics, so the sound is darker. Moving the cutoff over time makes the sound change in character. This is called subtractive synthesis: start with a rich sound and carve it away. The sweep uses the same LFO idea you built in PD2, now controlling the filter.

If it doesn’t work

Note

Pd steps were written from memory and have not been tested. If a step doesn’t match what you see, flag it so the page can be fixed.


PD5 Delay and Data

Goal

Add an echo to your sound, then play a melody from a list of numbers. This is where data from the other tools can drive your synthesizer.

What you need

Pure Data and headphones. Your saw or sine patch from earlier. Optional: the scale numbers from DS3, or the log from M5. Time: about 45 minutes. Do it in two parts if needed.

Part A: echo

1. Start with a short sound

Place and wire: osc~ 440, then *~ 0.1, then dac~. This is the same patch as PD1.

Place a number box and connect it to the left inlet of osc~ 440. In run mode, change the number between 440 and 0 repeatedly to start and stop the sound. Zero makes a silent tone.

Checkpoint: you can make short tones by hand.

2. Add the delay

Place two new boxes: delwrite~ echo 1000 and delread~ echo 300. The first stores 1000 milliseconds of sound under the name “echo”. The second reads it back 300 milliseconds later.

Wire the output of the *~ 0.1 box to the input of delwrite~ echo 1000 as well as to dac~.

Wire the output of delread~ echo 300 to a new *~ 0.4 box, and then to dac~ (both inlets).

Checkpoint: when you play a short tone, you hear it again 0.3 seconds later, quieter.

3. Feed the echo back

Also wire the output of *~ 0.4 to the input of delwrite~ echo 1000.

Checkpoint: the echo repeats several times, getting quieter each time. Be careful: if the feedback number (0.4) is 1 or above, the echo never dies. Keep it below 0.7.

Part B: play numbers

4. Make a place to hold the numbers

Place an object box with array define data 8. This makes a list called data with 8 slots.

Place a message box (Ctrl+2) with this exact text:

; data 0 440 494 523 587 659 587 523 494

Click it in run mode. (The semicolon at the start sends the numbers to the list named data. The first 0 is where to start. These are 8 note frequencies.)

Checkpoint: the list now holds eight pitches. Double-click the array define box to see them in a graph, if you want.

5. Make a counter

Place these boxes and wire each to the next in a loop:

metro 300
f
+ 1
mod 8

Wire the outlet of mod 8 back into the right inlet of f. Also wire the outlet of f to tabread data.

Place a message box with 1 and another with 0, and wire both to the left inlet of metro 300. Clicking 1 starts the counter and 0 stops it.

Checkpoint: in run mode, the number coming out of f counts 0 to 7 and repeats.

6. Read the numbers

Place tabread data. Wire the outlet of f to the inlet of tabread data. Wire the outlet of tabread data to the left inlet of osc~ 440 (this replaces the number box).

Checkpoint: click the 1 message box. You hear a melody of 8 notes, repeating.

Try it

What’s happening

delwrite~ and delread~ make an echo by storing sound and playing it back later. Feeding it back makes repeats. The counter loop makes the numbers 0 to 7 over and over. tabread reads the list at that position. So a plain list of numbers becomes a tune. Data that you collect (from the Microcontrollers pathway) or compute (in Data Science) can control sound this way. Turning data into sound is called sonification.

If it doesn’t work

Note

Pd steps were written from memory and have not been tested. If a step doesn’t match what you see, flag it so the page can be fixed.