Specifications

36 Using Pure Data
Rounding
+ 0.5
i
0.51
1
0.99
0
int
fig 3.30: Rounding
An integer function,
int
, also abbreviated
i
gives the
whole part of a floating point number. This is a trun-
cation, which just throws away any decimal digits. For
positive numbers it gives the floor function, written x
which is the integer less than or equal to the input va lue.
But take note of what happens for negative values, apply-
ing
int
to 3.4 will give 3.0, an integer greater than or
equal to the input. Truncation is shown on the left of Fig. 3.30. To get a reg-
ular rounding for positive numb e rs, to pick the closest integer , use the method
shown on the right side of Fig. 3.30. This will return 1 for an input of 0.5 or
more and 0 for an input of 0.49999999 or less.
Scaling
inlet value
inlet scale
inlet offset
outlet
127
9.999
+ 1
* 0.070866
* $1
+ $2
fig 3.31: Scaling
This is such a common idiom you will see it almos t
everywhere. Given a range of values such as 0 to 127
we may wish to map this onto another set of values,
the domain, such as 1 to 10. This is the same as
changing the slope and zero inter sect of a line following
y = mx + c. To work out the values you first obtain
the bottom value or offset, in this case +1. Then a
multiplier value is needed to scale for the upper value, which given an input of
127 would satisfy 10 = 1 + 127x, so moving the offset we get 9 = 1 27x, and
dividing by 127 we get x = 9/127 or x = 0.070866. You can make a subpatch
or an abstraction for this as shown in Fig. 6.1, but since only two objects are
used it’s more sensible to do scaling a nd offset as you need it.
Looping with until
t b b
f + 1
0
until
t f f
cheby
tabwrite cheby
swap 129
-
/ 128
t f f
*
* 2
- 1
sel 256
fig 3.32: Using until
Unfortunately, because it must be designed
this way,
until
has the potential to cause
a complete s ystem lock-up. Be very care-
ful to understand what you are doing with
this. A bang message on the left inlet of
until
will set it producing bang messages
as fast as the system can handle! These do
not stop u ntil a bang message is received on
the right inlet. Its purpose is to behave as a
fast lo op construct performing mess age do-
main computation quickly. This way you
can fill an entire wavetable or calculate a
complex formula in the time it takes to pro-
cess a single audio block. Always make sure
the right inlet is connected to a valid terminating condition. In Fig. 3.32 you
can see an example that computes the second Chebyshev p olynomial according