next up previous contents index
Next: Exercises Up: Examples Previous: major triad   Contents   Index

conversion between frequency and pitch

Patch A06.frequency.pd  (figure 1.9) shows Pd's object for converting pitch to frequency units (mtof, meaning "MIDI to frequency") and its inverse ftom. We also introduce two other object classes, send and receive:

Figure 1.9: Conversion between pitch and frequency in A06.frequency.pd.
\begin{figure}\psfig{file=figs/fig01.11.ps}\end{figure}


\fbox{ $ \mathrm{mtof} $}, \fbox{ $ \mathrm{ftom} $}: Converts MIDI pitch to frequency units according to the PITCH/FREQUENCY CONVERSION formulas. Inputs and outputs are messages (but "tilde" equivalents of the two also exist, although like dbtorms~ they're expensive in CPU time). The ftom object's output is -1500 of the input is zero or negative; and likewise, if you give mtof -1500 or lower it outputs zero.


\fbox{ $ \mathrm{receive} $}, \fbox{ $ \mathrm{r} $}: Receive messages non-locally. The receive object, which may be abbreviated as ``r" waits for non-local messages to be sent by a send object (below) or by a message box using redirection (the ``;" feature discussed in the earlier example, A01.sinewave.pd). The argument (such as ``frequency" and ``pitch" in this example) is the name to which messages are sent. Multiple receive objects may share the same name, in which case any message sent to that name will go to all of them.


\fbox{ $\mathrm{send}$}, \fbox{ $\mathrm{s}$\ }: The send object, which may be abbreviated as ``s", directs messages to receive objects.

Two new properties of number boxes are used here. Heretofore we've used them as controls or as displays; here, the two number boxes each function as both. If a number box gets a number in its inlet, it not only displays the number but also repeats it to its output. However, a number box may also be sent a ``set" message, such as ``set 55" for example. This would set the value of the number box to 55 (and display it) but not cause the output that would result from the simple ``55" message. In this case, numbers coming from the two receives are formatted (using message boxes) to read ``set 55" instead of just ``55", and so on. (The special word ``$1" is replaced by the incoming number.) This is done because otherwise we would have an infinite loop: frequency would change pitch which would change frequency and so on forever, or at least until something breaks.


next up previous contents index
Next: Exercises Up: Examples Previous: major triad   Contents   Index
Miller Puckette 2005-04-01