Specifications

4.2 Audio objects and principles 43
Audio input and output
Audio IO is achieved with the
adc~
and
dac~
objects. By default these offer two
inlets or outlets for stereo operation, but you can request as many additional
sound channels as your sound system will handle by giving them numer ical
arguments.
Example: A simple MIDI monosynth
notein
stripnote
mtof
osc~ vline~
*~
dac~
/ 127
*~
0, 1 10 0, 0 100 20
t f b
fig 4.6: MIDI note
control
Using the objects we’ve just discussed let’s create a little
MIDI keyboard controlled music synthesiser as shown in
Fig. 4.6. Numbers appearing at the left outlet of
notein
control the frequency of an oscillator. MIDI numbers
are converted to a Her tz frequency by
mtof
. The MIDI
standard, or rather general adherence to it, is a bit woolly
by allowing note-off to a lso be a note-on with a velocity of
zero. Pd follows this definition, so when a key is released
it produces a note with a zero velo city. For this simple
example we remove it with
stripnote
, which only passes
note-on messages when their velocity is greater than zero.
The veloc ity value, ranging be tween 1 and 127 is sc aled to between 0 and 1 in
order to provide a rudimentary amplitude control.
0, 1 10 0, 0 100 20
vline~
Time
Level
start at zero
move to 1
in 10 milliseconds
after a 0 millisecond delay
after a 20 millisecond delay
taking 100 milliseconds
return to zero
100ms
10ms10ms
20ms
at zero
so really start
fig 4.7: Anatomy of vline message
So, here’s a great place to elaborate on the anatomy of the message used
to control
vline~
as shown in Fig. 4 .7. The syntax makes perfect sense, but
sometimes it’s hard to visualise without practice. The ge ne ral form has three
numbers per list. It says: “go to some value”, given by the first number, then