// Pitch
Pd works with two kinds of pitches -
Hertz or
MIDI numbers. The traditional signs: A, B-flat, G-sharp, etc. are not used at all in Pd. Instead all chromatic pitches have MIDI numbers: A4 is the number 69, B-flat4 is 70, etc. The other way to describe pitch in Pd is in Hertz. To understand this, we'll need to understand a bit about musical acoustics.
Sound is air in vibration. Traditional instruments are used to vibrate air at specific frequencies. You can do this with strings (violin), lips (trumpet), or membranes (timpani). We even have a membrane in our ears - the eardrum - that vibrates sympathetically with vibrations in the air. Our brain transforms these vibrations into a different form, which is what we would call sound.
In electronic music, speakers are used to generate sound. They also have a membrane that vibrates back and forth, which causes the air to vibrate.
The vibrations of the speaker membrane are controlled by the computer. In Pd, the
dac~ object (digital audio converter) handles this. Here's how it works: sound is a physical phenomenon - vibrations in the air to be precise - and, as such, it is analog. Computers, however, work only with numbers, which means they are digital. The
dac~ object turns numbers into sound by converting numbers into fluctuations of electrical current that - once amplified - cause the speaker membrane(s) to vibrate accordingly.
A speaker's membrane can move back and forth. The outermost position (the most convex) is understood by the computer as position 1. The innermost position (the most concave) is position -1. When the membrane is precisely in the middle, as when at rest, this is position 0. All other positions are values of between -1 and 1.

The number of times per second a speaker
vibrates makes the frequency (the note, tone or pitch) of the sound you hear.
Waves
This is what a membrane that moves from one extreme limit to the next (most convex, most concave) at a constant tempo:

If you marked the individual stages:

In an abstracted form with membrane position on the y-axis and time on the x-axis, you could represent such motion like this:

In physics terminology, this is called a wave. Here you can clearly see the waveform - a triangle. There are different waveforms for different kinds of membrane movement. Their names reflect their visual resemblance:
In Pd
Sine Wave oscillator

Sawtooth Wave oscillator

Square Wave oscillator

In order to to create sound, each oscillator object takes a numerical input which represents a frequency in
Hertz. This number determines the number of times the oscillator will make its waveform during one second.
By using a creation argument (a default setting typed into the object box when the object is first created), you
can set the initial frequency of an oscillator. And by using an
hslider (Horizontal Slider), a
Number or a
Message, you can send numerical messages to change the frequency of the oscillator.
A period is one complete cycle of a vibration that constantly repeats.

What makes periodic vibrations special is that we hear them as clear tones with definite pitch. In contrast, noises are aperiodic vibrations.

If you counted the number of periods in a second, this number would be the vibration's frequency and is measured in
Hertz (Hz); frequency in this context always means how often something repeats in one second (expressed mathematically: 1/second).
A tone's frequency determines its pitch. A440, also called A4, is the standard pitch that orchestras use for tuning. A440 means that the air vibrates periodically at a rate of 440 times per second; C5 vibrates 523 times per second; the low G on a cello vibrates about 100 times per second.
The slower the frequency, the lower the pitch appears to your ear. In fact, humans - depending on age - hear pitches between 20 Hz and 15000 Hz. Children can hear up to 20000 Hz; elderly people can often only hear up to 10000 Hz. Dogs and bats can hear well over 20000 Hz. This range is referred to as
ultrasonic. In contrast to this is the
infrasonic range, which is lower than the bottom of the audible threshold - i.e., between 0 and 20 Hz. This range is perceived by us as rhythm.
Try this:

You should hear a rhythm of clicks (that's the sound of a sawtooth wave) that gradually gets faster. After a certain speed (over 20 clicks per second), our perception 'shifts gears' and begins to hear a low pitch. For the air (and for the computer), this is still a
rhythm. But for the human ear (ca. 20 Hz) it's a pitch! The faster this rhythm becomes, the higher the pitch we hear.
Another defining characteristic of the human ear is that it hears pitches
logarithmically. This means when a given frequency is doubled, we perceive this as an octave leap. If you change from A4 (440 Hz) to its double (880 Hz), you hear A5, which is exactly one octave higher:

What number would you need to move to the next octave?
From 30 Hz to 60 Hz, you hear an octave, but from 1030 Hz to 1060 Hz, you hear just a small step. In fact, the jump from 10000 Hz to 20000 Hz is only an octave!
The Pd object
osc~ creates a sine wave.
Microphones
A microphone also has a membrane that responds to vibrations in the air.
A microphone converts these vibrations into electric current, which it sends to the computer. The computer then converts the current into numbers. In Pd, this input can be received with the
adc~ object.
This is an example of a linear and logarithmic equation:
Exercise: Create a patch that outputs 8 different frequencies from 100 to 800 that increments by 100. This should prove that
while you are involved in an additive process in which the same amount is added each time, our ears, perceive that this amount gets smaller and smaller with every step.
If you want to hear a linear progression - i.e., a process by which the same interval is added, for example the octave - the mathematical function has to be exponential. Double the frequency each step.
MIDI
For many musical applications, the MIDI scale is a useful way of controlling the frequency of an oscillator.
Think of the MIDI scale as a piano keyboard with 128 keys on it, and each key has been marked with
a frequency in Hertz which represents that musical note.
The most important thing to notice is that a note which is one octave
higher than another note (for example, the three A notes of 55 Hz, 110 Hz and 220 Hz) has a frequency
which is twice that of the lower note.

You can convert entries in frequencies and MIDI numbers in Pd:

Here's an example patch that uses a slider:
Oscillators like
osc~ or
phasor~ have to receive their input in Hertz
Sample Rate
Objects like
osc~ generate a very fast sequence of numbers between -1 and 1 sent to the speaker by the
dac~ object. 44100 numbers per second are generated and sent. The loudspeaker makes 44100 tiny movements between -1 and 1 within one second. This number, 44100, is called the
sample rate.
Every sound in Pd is produced using numbers between -1 and 1 at a rate of 44100 numbers per second. A single individual number is called a sample.
All Pd objects that generate or process data at this speed have a tilde
~ in the object box. These objects are connected to each other with thick cables. These numbers are referred to as signals.

While the object that supplies the
osc~ is not constantly transmitting, the
osc~ object's outlet is. It is constantly sending signals, or numbers between -1 and 1, 44100 per second (per second means: Hertz). The thick cable indicates to the programmer that this outlet is a constant transmission.
Number boxes can only be used for control connections, not signal connections. Signal connections are too fast: you can't see 44100 different numbers per second. You can, however, show selected numbers from a signal with the
snapshot~ object. As inputs, it receives the sound signal and a bang that, when clicked, displays the current number when clicked. To see this number, connect either a number box or a
print object to its output:

If you wanted a constant stream of numbers, you would need to attach a trigger and before the bang. Alternatively, you could use
unsig~ which automatically connects a metronome. Just enter the metronome value as the argument:
Samples
There are two different units in Pd for measuring time:
samples and
milliseconds. Samples are usually used for counting signals while milliseconds are used for control data.
here's how to convert duration in milliseconds to duration in samples:
Why 44100
The number 44100 was chosen for a good reason. Humans can hear up to 20000 Hertz at most. In 1928, U.S. physicist Harry
Nyquist (1889-1976) proposed a theory stating that a frequency of at least twice the signal frequency was necessary to accurately represent a sound signal digitally. This means that one needs the maximum and minimum values for each period to accurately represent a waveform's basic shape, or two points per period:

For a wave with 20000 Hz, which equals 20000 periods per second, you need at least 40000 points per second to accurately represent it. To ensure that the entire spectrum of sounds audible to humans was included, a sample rate of 44100 was chosen for audio CDs. This means that waves of up to 22050 Hz could be captured. For computers, a wide selection of frequency bandwidths exist, all the way down to 8000 Hertz for system sounds. High-quality audio recordings work with sample rates of 48000 Hz (48 kHz = kiloHertz, where kilo = thousand), 96 kHz, or even 192 kHz.
//Volume
Volume is another parameter of sound. In physics, which is what Pd uses as a model, volume is represented with objective values in
deciBel or
root mean square values. Both units are comparable to MIDI numbers and frequencies for pitches.
DeciBel (dB) reflect what you hear, where an
octave in volume corresponds to
6 dB. The scale ranges from
0 to 130 dB — where a value of between 15 and 20 dB is absolute silence and anything over 120 dB is capable of causing serious hearing damage. After 130 dB you perceive sound only as pain.
Root mean square values (
rms), like frequencies, do not correspond to what you hear, but are logarithmic values between 0 and 1, where 0 corresponds to 0 dB and 1 to 100 dB. rms refers to the
geometric mean calculated from a series of amplitude values. These numbers are first squared, then the average is taken (by adding all values and dividing by the number of elements), and then the square root of this average is taken. The rms value for an audio signal is first calculated using a portion of the audio signal that lasts specific duration; for a heavily fluctuating signal like a pitch frequency, it gives you an idea of the average signal amplitude. The following objects can be used to convert from one to the other in Pd:
The volume of a vibration is determined by its amplitude:
You can use this method to set the volume to any level from absolute silence to as loud as possible:
Exercise: Recreate the patch above using a slider with a range from 0-1. The slider's oulet should feed a numbers inlet which should feed a
sig~ object connected to the * object with no argument. You can change the range by opening the Properties—CTRL+click on the object, then select Properties.
Using the
sig~ object which converts the input into exactly 44100 numbers/sec, ensures that the numbers generated by the oscillator and those generated by the factor are synchronized. br />
if a signal is attached to the
*~ object's right inlet, the object must not have an argument. If you were to enter an argument (like 0.7, as used previously) the object would assume that its right input was control data.
Here's an elegant way to use a slider as a volume regulator. This executes a small crescendo/decrescendo between every step. Filling in steps with intermediate values in this way is called
interpolation

There is a GUI-object in Pd for visualizing amplitude: the VU meter (
Put>VU). It takes a dB value as input. However, it works like a traditional mixing board: 100 dB is shown as 0 dB and deviations above or below this are shown in the positive or negative range, respectively. You have to take this into account when entering the input. Simply subtract from the
env~ object's output:

Amplitudes above 1 and below -1 will be
clipped. If
dac~ sends the speaker a value outside the range of 1 to -1, the membrane simply stays at the furthest extreme.

Increasing the volume of a sound to the point of 'clipping' results in an effect called
overdrive.
If the speaker membrane has to span a large interval suddenly, you'll hear a click instead of a tone.
To avoid this click, you need to build what's called a
ramp, a very fast crescendo at the beginning and end:
//Additive Sound
Sound waves are additive. If you have these two oscillators:

and you connect them to
dac~. You'd get this:

Adding a sawtooth wave and a sine wave results in the follwing waveform:
The individual waves only go from -0.5 to 0.5. Taken together, however, they cover a range from -1 to 1 and have a more complex form. This is because sound waves are additive. Simply stated:
all vibrations occur in the same air. This additive quality also entails cancellations. Opposed waves, where one is
moving backwards while the other is
moving forwards cancel one another out. This is what happens when vibrations that have the same frequency are 180 degrees out of phase:
Note that the two waveforms are sent to an audio multiplication [*~] object, which halves (multiplies by 0.5)
the combined signal to reduce the total range of values sent to the sound card.
At full volume, each oscillator goes from either 0 or -1 to 1 many times a second. Because Pd handles
numeric values, not waves, you can add any number of signals. If, however, the combined value of these
signals exceeds the -1 to 1 range when it reaches the digital-to-analog converter [dac~] object (that is, the line
out to the sound card), clipping and distortion occur. Any value outside of the accepted range is treated as a -1
or a 1.
Chords
To create a chord with variable volume for every tone in the chord:
Exercise: Create the following patch, ad a toggle for sound, then say something into the microphone and listen as the sound is played back at a different volume:
Exercise:Create a subpatch named
o1. In the http://www.pd-tutorial.com/english/images/kap3/3-3c.jpgsubpatch create this:

In the main patch add this:
Then create something like this, but add a toggle for sound:
//Subtractive Synthesis
Claude Debussy once responded to the question of how he composed by saying he starts by taking all pitches and then leaves out the ones he doesn't like. He foresaw the idea of filtering. In contrast to additive synthesis - which uses what might be considered the 'atom' of sound, the sine tone, as a starting point - subtractive synthesis begins with all sound and reduces it. It is actually possible to produce all sound. Causing a speaker membrane to vibrate completely chaotically and randomly will produce all audible frequencies simultaneously. The Pd object used to accomplish this is called
noise~:
Like light, noise that contains all audible frequencies is called
white noise. Normal white light contains all light frequencies while, say, red or blue light can be derived from it using filters.
Pd also has filters such as
lowpass, which allows only the low frequencies to pass through while suppressing the high frequencies. This is represented in the following diagram; the x-axis represents frequency and the y-axis amplitude:
A
highpass filter, which only allows high frequencies to pass through:
The Pd objects for these filters are called
hip~ and
lop~. Their argument or right input is the frequency from which the sound should be filtered:
You can intensify their effect by using several filters one after another (cascade):

volume has to be readjusted for each filter, as they reduce the sound's intensity.
Another kind of filter is called a
band-pass. This allows only a small portion of sound surrounding a central frequency to pass through, like a
band of frequencies. As arguments/inlets it receives the central frequency and the width of the band, called
q.
//Making your own waveform
In Pd, you can write waveforms to a table using an
internal message.
An internal message is a message box
which, when clicked, sends the message inside to the Pd application itself.
An example would be the messages
you can use to turn audio processing on and off in Pd:
- To create and load a table with a waveform, you must first create an array
from the Put menu. Then give
it the name waveform in the properties panel
- Create a message, and type the following in it (using the Return key after the semicolon to start
a new line):
;
waveform sinesum 2051 1
- The semicolon indicates that the message is an internal message, and waveform indicates that you
are
sending information to the array named waveform.
-
The word sinesum tells the array that you will be
sending it a series of harmonics to graph.
- The number 2051 tells the array that you want to graph those
harmonics out on 2051 units on the X range, so the array will be resized from 100
(its default size) to 2051.
- The number 1 indicates that you want to write a single
sine wave with a peak amplitude of 1 to the
array.
- When you click the message, we see a pure sine wave graphed to the array:
- Graphing a sawtooth:
- Add another message:
This will keep the lines within the box
- To play back the waveforms you graphed to the arrays, you use the tabread4~ object. It takes an audio
signal as its input, which reads along the X axis of the array and outputs as an audio signal the values that it
finds along the Y axis.
You can use phasor~ to play the array as an oscillator when you scale its output, which is normally 0 to 1, to
fit the whole length of the array. Thus, if your array is 2051 places long, then you can use an Audio
Multiplication [*~] object to get an output of 0 to 2051. Increasing the frequency of the phasor~ will
increase the frequency at which the waveform in the array is played back from start to finish:
- The shape of a triangle wave
is made using only the odd harmonics (1, 3, 5, 7, etc). Zeros are used for the amplitude of the even harmonics
(2, 4, 6, 8, etc). Then 1 is divided by the square of each of those harmonics (i.e. 1/h2). Finally, the amplitude
of every other harmonic is multiplied by -1 (i.e. the amplitudes of the third, seventh, ninth, etc harmonics).
The triangle wave takes shape very quickly with only four harmonics, and as more harmonics are added, the
points of the triangle become sharper.
;
waveform sinesum 2051 1 0 -0.1 0
here is 12 harmonics:
;
waveform sinesum 2051 1 0 -0.111111 0 0.04 0 -0.0204082 0 0.01234567 0 -0.00826446
- A square wave takes a few more added harmonics to get close to its ideal mathematical shape. This waveform
is created also using only the odd-numbered harmonics (1, 3, 5, 9...), and zero is also used for the amplitude of
the even harmonics (2, 4, 6, 8...). Then 1 is divided by the number of the harmonic to get its amplitude (i.e.
1/h). A square wave made up of only four harmonics isn't very square, but when more
harmonics are added its shape becomes very clear:
;
waveform sinesum 2051 1 0 0.33333 0 .2 0 0.142857 0 0.11111 0 0.090909 0 0.07692
//Sampling
A sample is the smallest unit used for measuring and generating sound in a computer. The word
sample unfortunately also has another, quite different meaning in electronic music; it means a smallish section (usually a couple seconds long) of recorded sound.
There are various locations in the computer where files can be saved: main memory or hard disks. Access to main memory is very fast in comparison to the hard disk; however, it has much less available space.
In Pd you can save sound to both locations. Saving to the hard disk means that you are saving a fixed sound file. WAV or AIFF formats are typically used. Use the
writesf~ object to write a sound file to disk. The argument is the number of channels; this creates a corresponding number of inlets to which you attach the sounds you want to record. First you have to use the message
open [name] to choose the name of the file you want to create. Start recording using
start and stop it using
stop.

Sound files that are on an external storage device like a hard disk can be read - that is, played back - in Pd with
readsf~. As with
writesf~, you use the messages
start and
stop (you could also use
1 and
0). Enter the number of channels as the argument. The rightmost output sends a bang when the end of a file is reached.
Exercise:Try this:

Then this:
Source:http://www.pd-tutorial.com/english/
http://en.flossmanuals.net/PureData/