This is the second post in a series about re-creating the patches from the book Programming Sound with Pure Data in the Max environment. The introduction to the series can be read here.
In Pd, an oscillator is created using the
osc~ object. In Max, we use the
cycle~ object to do the same thing. Sending audio from the computer to an output is done using
dac~ in Pd, and
ezdac~ in Max.
Sending an audio signal to the speaker
To send an audio signal with a frequency of 440 Hz to an output in max is done by connecting these two objects. The patch below, Concert A, shows how this is done:
Switching an audio signal on and off
If we want to control the audio signal with a switch, we can multiply the output from the oscillator with either 0 or 1 before sending it to the
ezdac~ object. Multiplication is done with the
*~ object. There is an object called the
toggle which sends the value 1 when it is on, and 0 when it is off. If we multiply the
toggle value with the
cycle~ output, we can effectively turn the sound on and off. This is shown in the Concert A With Toggle patch below.
Changing the frequency of an audio signal
If we want to change the frequency of the oscillator, we can use the
mtof object. This object takes a MIDI note value (a number from 0 to 127) and converts it to a frequency.
In the patch below we send MIDI note value 60 (which corresponds to middle C on a piano keyboard) to the
mtof object. The number is translated into a frequency value (in this case roughly 261.62) which is passed on to the
cycle~ object, and then to the
Adding a delay to start and stop the sound
delay object can pause a signal for a given amount of time. The
trigger object can take an incoming message, format it, and pass it on to one or more outlets. In a Max patch, the message order is from right to left, so a trigger object with three outputs will first send a message through the rightmost output and move to the left.
We can take advantage of this and send a number to a trigger object, and create three outlets for it. The arrguments to the trigger function is the format for which we want the output to be sent, so if we want the output to be one integer and two bangs, the arguments would be
trigger int bang bang. The
trigger objects will have as many outputs as there are arguments
In the patch below we send MIDI note value 73 to the
trigger object. The
trigger object has three arguments,
int bang bang. This means that when the trigger receives a message, it will trigger three new messages. Two of them are
bang messages, and the other is an
The rightmost message is handled first, triggering the value '1' to be sent to the multiplier object, turning the sound on. The second bang is sent to a
delay object, which causes the signal to wait for 500 ms before passing the value '0' on to the multiplier object, turning the sound off. The
int argument is passed on to the
mtof object as we have seen in the earlier patches.
The result is that when the first message is triggered, we will hear a sound for half a second.
There are comments.