Click here to open the tutorial patch: Media:01hTurningSignalsOn-Off.maxpat
In the next group of tutorials we'll look at ways to manage the signal chain resources in MSP patchers. We'll start by looking at ways to selectively turn on and off signal processing within patcher logic; this allows us to effectively 'mute' parts of our patchers so that they don't process any samples when we don't want them to.
Consider the following piece of patcher logic:
A silent MSP patcher
As we can see, this patcher, as illustrated, makes no sound -
the volume of the line~ has been set to
the number box. However, the signal processing chain
computing the samples is still going: the cycle~ object
is still sending signal vectors that resemble a full-amplitude
cosine wave, the line~ object is sending a constant
signal value of
0, and the *~ object is
multiplying the two together, generating values of
well. The overhead of this patcher on our computer would be minimal,
obviously, but more in situations where we create complex signal
processing networks that use large amounts of CPU, it's useful
to be able to disable the parts we're not listening to.
When an MSP patcher is created and the audio is turned on, the Max program builds a function graph of all the signal (MSP) objects within the patch. This graph is then organized so that the objects pass their samples to one another in a logical way, much in the way that Max objects pass messages based on their visual layout within the patch. MSP objects communicate by passing packets of audio samples called signal vectors to one another. When an audio object is silenced by passing it through a volume control (e.g. a *~ object), it is still passing values. If we want to actually turn of signal processing within part of a signal network in MSP, we first have to design the patcher so that parts of it can be declared as 'mutable'.
Take a look at the tutorial patcher. The main (lower) part of the patcher consists of an MSP signal network with a selector~ object in-line before the final volume scaling. The selector~ object is the opposite of an MSP gate~ object, and is roughly analogous to the Max switch object; the left-hand inlet allows us to choose which signal input to listen to when sending signals to the output. The argument to selector~ determines how many selectable inlets there are in addition to the leftmost ('chooser') inlet.
startwindow at the top of the tutorial patcher.
Using the umenu labeled 'Wave Type' at the top of the
patcher, select the different waveforms and listen to their results.
Each selection enables a different inlet in the selector~ object.
Under normal circumstances, the selector~ object would switch what part of the signal processing chain you were listening to, but wouldn't turn off any of the signal chain, i.e. all of the objects connected to all of the inlets of the selector~ would still be generating their signal vectors, regardless of whether they were actually sending any audio past the selector~ or not.
However, in our tutorial patcher different parts of the signal
processing chain are being turned off. The begin~ object
declares the start of a signal-processing chain; other than that, it
does nothing (it outputs a constant value of
0 no matter what
happens). When a selector~ or other signal-switching MSP
object cuts off a signal-processing path with a begin~ at
the top, the begin~ object mutes everything downstream,
freeing their DSP resources.
Notice that there is a begin~ object inside. Notice also
that the triangle~ object needs a sig~ object to
set its frequency when used in conjunction with begin~.
In our tutorial patcher, the sawtooth and triangle waveforms
(and any accompanying MSP objects connected to them) are
disabled automatically when their inputs are not being
selected by the selector~ object. The cycle~ object
at the left is always processing samples. The patcher
on the right (labeled
square) is as well; we have a
different strategy for muting it.
hear the square wave. Click the toggle object connected to the mute~ object in the patcher. Notice that, when checked, the square wave is silenced. Click it again to hear the square wave. The mute~ object in MSP allows you to disable signal processing in a patcher or abstraction. This lets you use subpatchers of either type as self-contained signal processing networks that you can turn on and off through patcher logic. In order for the mute~ object to work properly, however, one more object is needed, within the patcher being muted.
the rect~ object is an object called pass~.
The pass~ object performs a very important function when
muting and unmuting parts of the signal processing chain -
it zeroes out the signal vector coming out of
the patcher or abstraction. In our example, we are
using mute~ to switch off a patcher containing
a rect~ object, which outputs
When we mute it, we want it to output a
0, in case
we have its output mixed in with other elements of our signal
chain. Otherwise, it will put out its last (un-muted) value as a
constant signal, leaving us with DC bias in our audio network.
The pass~ object guarantees this won't ever happen.
from the umenu. In the area of the tutorial patcher
labeled '2' (in the upper-right), click the toggle object
connected to the message box containing the
enable $1. Double-click the patcher object
named 'harmonics'. Inside, turn on and off the selector~ object
controlling the output for the cycle~ object on the right.
Back in the main patcher, click the toggle again to mute the
A second way to turn on and off signal processing in
a patcher or abstraction is by using the pcontrol object.
enable message to pcontrol turns
off all activity within a subpatcher, both MSP signals
and Max scheduling. Notice that within the subpatch, we have
a number of cycle~ objects computing different
harmonics of the fundamental frequency used throughout the
tutorial patcher. In the subpatch, the selector~ object
allows us to disable the fundamental frequency. Even
with the fundamental missing, our ears still resolve the same pitch.
There are a number of strategies for turning on and off parts
of a signal chain in MSP. The
startwindow message to
a dac~ turns on audio only in one open Max document.
The begin~ and selector~ objects allows us to
declare and selectively disable parts of an MSP signal
processing network within a Max patcher. MSP signal objects
within patcher objects and abstractions can be disabled
as well, either by using a mute~ object or
enable message to a pcontrol object.
The pass~ object, when used within a mutable subpatch,
zeroes the audio coming out of the subpatch to prevent
clicks or DC noise.
selector~ - Assign one of several inputs to an outlet
pcontrol - Open and close subwindows within a patcher