Namespaces

Variants
Actions

MSP Polyphony Tutorial 1: Turning Signals On and Off

From Cycling '74 Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
Click here to open the tutorial patch: [[Media:01hTurningSignalsOn-Off.maxpat]]
+
<openpatchlink>Open the tutorial</openpatchlink>.                                  
  
===Introduction===
+
===Turning audio on and off selectively===
  
In the next group of tutorials we'll look at ways to manage
+
There are two elementary ways of turning audio processing on and off in an MSP patcher:
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.
+
  
===DSP Resources in MSP===
+
# Send a <code>start</code> or <code>stop</code> message to a {{maxword|name=ezdac~}}, {{maxword|name=ezadc~}}, {{maxword|name=dac~}}, or {{maxword|name=adc~}} object.
  
Consider the following piece of patcher logic:
+
# Click on a {{maxword|name=ezdac~}} or {{maxword|name=ezadc~}} object.
  
[[Image:Polychapter01a.png|border]]
+
For the first tutorial that introduces the {{maxword|name=poly~}} object and the idea of polyphony in general, we are going to take a step back and think more broadly about allocating resources in a signal processing patch - when you think about it, that is what polyphony is ''about,'' in a general way.
  
''A silent MSP patcher''
+
There are two other ways of turning audio processing on and off in an MSP patcher we have not yet mentioned:
  
As we can see, this patcher, as illustrated, makes no sound -
+
# Send an <code>int</code> to a {{maxword|name=dac~}}, {{maxword|name=adc~}}, {{maxword|name=ezdac~}}, or {{maxword|name=ezadc~}} object. <code>0</code> is the same as <code>stop</code>, and a non-zero number is the same as <code>start</code>.
the volume of the {{maxword|name=line~}} has been set to <code>0</code> by
+
the {{maxword|name=number}} box. However, the signal processing chain
+
computing the samples is still going: the {{maxword|name=cycle~}} object
+
is still sending signal vectors that resemble a full-amplitude
+
cosine wave, the {{maxword|name=line~}} object is sending a constant
+
signal value of <code>0</code>, and the {{maxword|name=*~}} object is
+
multiplying the two together, generating values of <code>0</code> as
+
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,
+
# Double-click on a {{maxword|name=dac~}} or {{maxword|name=adc~}} object to open the Audio Status window, then use its Audio on/ off pop-up menu. You can also choose <b>Audio Status...</b> from the Options menu to open the Audio Status window.
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 {{maxword|name=*~}} 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
+
Any of those methods of starting MSP will turn the audio on in all open Patcher windows and their subpatches. There are also a several ways to turn audio processing on and off in a single Patcher.
patcher consists of an MSP signal network with a {{maxword|name=selector~}} object
+
in-line before the final volume scaling. The {{maxword|name=selector~}} object
+
is the opposite of an MSP {{maxword|name=gate~}} object, and is roughly
+
analogous to the Max {{maxword|name=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 {{maxword|name=selector~}} determines
+
how many selectable inlets there are in addition to the leftmost
+
('chooser') inlet.
+
  
* Start the audio in the patcher by clicking the {{maxword|name=message}} box
+
===Local control with the startwindow message===
labeled <code>startwindow</code> at the top of the tutorial patcher.
+
Using the {{maxword|name=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 {{maxword|name=selector~}} object.
+
+
The <code>startwindow</code> message to a {{maxword|name=dac~}} or {{maxword|name=ezdac~}} object
+
turns on the audio in one patcher ''only'' (as opposed to all
+
open patchers in Max). If other audio-generating Max documents
+
are open, it mutes them.
+
  
===Begin the {{maxword|name=begin~}}===
+
Sending the message <code>startwindow</code> -- instead of <code>start</code> -- to a {{maxword|name=ezdac~}}, {{maxword|name=ezadc~}}, {{maxword|name=dac~}}, or {{maxword|name=adc~}} object turns the audio on ''only'' in the Patcher window that contains that object, and in its subpatches. It turns audio off in all other Patchers. The <code>startwindow</code> message is very useful because it allows you to have many different signal networks loaded in different Patchers, yet turn audio on only in the Patcher that you want to hear. If you encapsulate different signal networks in separate patches, you can have many of them loaded and available but only turn on one at a time, which helps avoid overtaxing your computer's processing power. (Note that <code>startwindow</code> is used in all MSP help files so that you can try the help file's demonstration without hearing your other work at the same time.)
  
Under normal circumstances, the {{maxword|name=selector~}} object would
+
In some cases (e.g. when you have multiple helpfile patcher windows open), using the <code>startwindow</code> message is more appropriate than start.
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 {{maxword|name=selector~}} would still be generating their
+
signal vectors, regardless of whether they were actually sending
+
any audio past the {{maxword|name=selector~}} or not.
+
  
However, in our tutorial patcher different parts of the signal
+
===Using the Mixer Engine to control audio===
processing chain ''are'' being turned off. The {{maxword|name=begin~}} object
+
declares the start of a signal-processing chain; other than that, it
+
does nothing (it outputs a constant value of <code>0</code> no matter what
+
happens). When a {{maxword|name=selector~}} or other signal-switching MSP
+
object cuts off a signal-processing path with a {{maxword|name=begin~}} at
+
the top, the {{maxword|name=begin~}} object mutes everything downstream,
+
freeing their DSP resources.
+
  
* Double-click the {{maxword|name=patcher}} object named <code>triangle</code>.
+
Every top-level patcher in Max has its own DSP chain, and is equipped with a ''mixer engine'' that lets you turn audio on and off in the patcher. You'll find the Mixer engine controls in the patcher window toolbar. By default, the Mixer control panel controls for the {{maxword|name=dac~}} or {{maxword|name=ezdac~}} object in your patcher window (you can add additional {{maxword|name=dac~}} objects to your patch as described <link  type="vignette" module="core" name="mixer" anchor="multidac">here</link>).
Notice that there is a {{maxword|name=begin~}} object inside. Notice also
+
that the {{maxword|name=triangle~}} object needs a {{maxword|name=sig~}} object to
+
set its frequency when used in conjunction with {{maxword|name=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 {{maxword|name=selector~}} object. The {{maxword|name=cycle~}} object
+
at the left is always processing samples. The {{maxword|name=patcher}}
+
on the right (labeled <code>square</code>) is as well; we have a
+
different strategy for muting it.
+
  
===Two ways to mute a subpatcher===
+
To display the Mixer engine control panel for your patcher, click on the Mixer button in the patcher toolbar.
  
* Enable the 'Square' option from the {{maxword|name=umenu}} so that you
+
[[Image:Mixerpanel.png|border]]
hear the square wave. Click the {{maxword|name=toggle}} object connected
+
to the {{maxword|name=mute~}} object in the patcher. Notice that, when
+
checked, the square wave is silenced. Click it again to hear
+
the square wave.
+
The {{maxword|name=mute~}} object in MSP allows you to disable signal
+
processing in a {{maxword|name=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 {{maxword|name=mute~}} object to work properly,
+
however, one more object is needed, within the patcher being
+
muted.
+
  
* Double-click the {{maxword|name=patcher}} named 'square'. Connected to
+
You can click and drag on the volume knob to set the output volume for the patcher window, and mute or solo the audio output using the M (Mute) or S (Solo) buttons.
the {{maxword|name=rect~}} object is an object called {{maxword|name=pass~}}.
+
The {{maxword|name=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 {{maxword|name=patcher}} or abstraction. In our example, we are
+
using {{maxword|name=mute~}} to switch off a patcher containing
+
a {{maxword|name=rect~}} object, which outputs <code>-1</code> or <code>1</code>.
+
When we mute it, we want it to output a <code>0</code>, 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 {{maxword|name=pass~}} object guarantees this won't ever happen.
+
  
* Switch the sound off in the main patcher by selecting 'Off'
+
The Mixer Engine also allows you to fade the audio in or out when you turn audio on and off in a patcher window by adding an amount of latency to the patcher outputs. You can set the length of the fade in/out in milliseconds by setting mixer latency and crossfade time in the <link module="core" name="mixer_preferences" type="vignette">Mixer Preferences</link>.
from the {{maxword|name=umenu}}. In the area of the tutorial patcher
+
 
labeled '2' (in the upper-right), click the {{maxword|name=toggle}} object
+
===Selecting one of several signals: selector~===
connected to the {{maxword|name=message}} box containing the
+
 
message <code>enable $1</code>. Double-click the {{maxword|name=patcher}} object
+
In the previous chapter, we saw the {{maxword|name=gate~}} object used to route a signal to one of several possible destinations. Another useful object for routing signals is {{maxword|name=selector~}}, which is comparable to the Max object {{maxword|name=switch}}. Several different signals can be sent into {{maxword|name=selector~}}, but it will pass only one of them -- or none at all -- out its outlet. The left inlet of {{maxword|name=selector~}} receives an <code>int</code> specifying which of the other inlets should be opened. Only the signal coming in the opened inlet gets passed on out the outlet.
named 'harmonics'. Inside, turn on and off the {{maxword|name=selector~}} object
+
 
controlling the output for the {{maxword|name=cycle~}} object on the right.
+
[[Image:Image079.gif|border]]
Back in the main patcher, click the {{maxword|name=toggle}} again to mute the
+
 
subpatch.
+
<caption>''The number in the left inlet determines which other inlet is open''</caption>
A second way to turn on and off signal processing in
+
 
a {{maxword|name=patcher}} or abstraction is by using the {{maxword|name=pcontrol}} object.
+
As with {{maxword|name=gate~}}, switching signals with {{maxword|name=selector~}} can cause a very abrupt change in the signal being sent out, resulting in unwanted clicks. So if you want to avoid such clicks it's best to change the open inlet of {{maxword|name=selector~}} only when audio is off or when all of its input signal levels are 0.
The <code>enable</code> message to {{maxword|name=pcontrol}} turns
+
 
off ''all'' activity within a subpatcher, both MSP signals
+
In the tutorial patch, {{maxword|name=selector~}} is used to choose one of four different classic synthesizer wave types: sine, sawtooth, triangle, or square. The {{maxword|name=umenu}} contains the names of the wave types, and sends the correct number to the control inlet of {{maxword|name=selector~}} to open the desired inlet.
and Max scheduling. Notice that within the subpatch, we have
+
 
a number of {{maxword|name=cycle~}} objects computing different
+
* Choose a wave type from the pop-up menu, then click on the <code>startwindow</code> {{maxword|name=message}}. Use the pop-up menu to listen to the four different waves. Click on the <code>stop</code> {{maxword|name=message}} to turn audio off.
harmonics of the fundamental frequency used throughout the
+
 
tutorial patcher. In the subpatch, the {{maxword|name=selector~}} object
+
===Turning off part of a signal network: pcontrol===
allows us to disable the ''fundamental'' frequency. Even
+
 
with the fundamental missing, our ears still resolve the same pitch.
+
If you want to enable or disable signal processing in a {{maxword|name=patcher}} or abstraction, you can use the {{maxword|name=pcontrol}} object. The <code>enable</code> message to {{maxword|name=pcontrol}} turns off ''all'' activity within a subpatcher - both MSP signals and Max scheduling.
 +
 
 +
----
 +
 
 +
'''Technical detail:''' If you double-click on the {{maxword|name=pcontrol}} object named harmonics and look inside, you'll hotice that we have a number of {{maxword|name=cycle~}} objects computing different harmonics of the fundamental frequency used throughout the tutorial patcher. In the subpatch, the {{maxword|name=selector~}} object allows us to disable the ''fundamental'' frequency. Even with the fundamental missing, our ears still resolve the same pitch.
 +
 
 +
----
 +
 
 +
===Turning off part of a signal network: poly~===
 +
 
 +
You have seen that the {{maxword|name=selector~}} and {{maxword|name=gate~}} objects can be used to listen selectively to a particular part of the signal network. The parts of the signal network that are being ignored — for example, any parts of the network that are going into a closed inlet of selector~ — continue to run even though they have been effectively disconnected. That means MSP continues to calculate all the numbers necessary for that part of the signal network, even though it has no effect on what you hear. It would be preferable if one could actually shut down the processing for the parts of the signal network that are not needed at a given time.
 +
 
 +
The {{maxword|name=poly~}} object allows us to do just that.
 +
 
 +
The {{maxword|name=poly~}} object is very powerful - to describe it simply, it lets us create and manage multiple copies of the same MSP subpatch within one object, and is very useful for creating polyphonic synths. We'll describe its use for that purpose in greater detail in a <link type="tutorial" module="msp" name="mspchapter21">later tutorial</link>. For now, we'll show you how to use it to conserve CPU usage.
 +
 
 +
The tutorial patch contains an example of the {{maxword|name=poly~}} object used to enable and disable signal processing in a patch.
 +
 
 +
[[Image:Polymute.png|border]]
 +
 
 +
The {{maxword|name=poly~}} object takes as its argument the name of a patcher file, followed by a number that specifies the number of copies (or instances) of the patch to be managed (in this case, it's only a single instance). When you launch the patch, a {{maxword|name=toggle}} object automatically sends the message <code>mute 0 1</code> to the {{maxword|name=poly~}} object.
 +
 
 +
To look inside the {{maxword|name=poly~}} object, double-click on it to open a new patcher window.
 +
 
 +
The {{maxword|name=in}} and {{maxword|name=out~}} objects function in a matter similar to {{maxword|name=inlet}} and {{maxword|name=outlet}} objects in a subpatcher. The second {{maxword|name=in}} object receives the <code>mute</code> message and routes it to the {{maxword|name=thispatcher}} object. Sending the <code>mute 0 1</code> message to the {{maxword|name=thispatcher}} object located in the patch will shut down the processing of the loaded subpatcher completely (the first zero indicates that you are sending the message to the first and only instance of the subpatcher loaded in the {{maxword|name=poly~}} object).
 +
 
 +
When the tutorial patch opens for the first time, {{maxword|name=toggle}} object connected to the {{maxword|name=message}} box that contains the control message is on, and the oscillators in the wobbler abstraction inside the {{maxword|name=poly~}} object are shut down. If you click on the {{maxword|name=toggle}} to send the message <code>mute 0 0</code> to the {{maxword|name=thispatcher}} object, you will hear the oscillators. If you have the Mixer Engine window open, you will also notice that the percentage CPU usage increases, indicating that there is more audio processing going on.
 +
 
 +
===Creating your own stompbox===
 +
 
 +
The final portion of our tutorial patch - the stompbox patcher - combines two different techniques used in this tutorial with some clever patching to imitate a stompbox that not only selects direct or processed output, but also turns processing ''off'' when it is not selected.
 +
 
 +
[[Image:Stompbox1.png|border]]
 +
 
 +
Our patcher contains a {{maxword|name=trigger}} object to route and control the order of events. The right outlet of the {{maxword|name=trigger}} object takes a 0 or 1 input value and uses it with the <code>mute 0</code> message to turn processing on or off inside the patcher loaded in the {{maxword|name=poly~}} object. Since we want to send the <code>mute 0 1</code> message that mutes the subpatcher when the stompbox button is <b>on</b>, we use the {{maxword|name=!-}} object to invert the switch input.
 +
 
 +
Our patcher also contains a {{maxword|name=selector~}} object that switches between the straight patcher input (the center inlet) and the output of a {{maxword|name=poly~}} object that contains a simple distortion patch. Since the {{maxword|name=selector~}} switch uses a zero indicate that no output is selected, we'll need to add 1 to our stompbox {{maxword|name=toggle}} object's output.
 +
 
 +
So when we press the {{maxword|name=toggle}} attached to the right inlet of the stompbox patcher file, we do two things:
 +
 
 +
* We send the message <code>mute 0 0</code> to turn the processing inside of the poly~ object on or off.
 +
 
 +
* We send a 1 or 2 to the {{maxword|name=selector~}} object to choose the straight or processed input to the {{maxword|name=selector~}} and output it.
 +
 
 +
[[Image:Stompbox2.png|border]]
  
 
===Summary===
 
===Summary===
  
There are a number of strategies for turning on and off parts
+
The <code>startwindow</code> message to {{maxword|name=dac~}} (or {{maxword|name=adc~}}) starts audio processing in the Patcher window that contains the {{maxword|name=dac~}}, and in any of that window's subpatches, but turns audio off in all other patches. The {{maxword|name=mute~}} object, connected to an inlet of a subpatch, can be used to disable all MSP objects in that subpatch. An <code>enable 0</code> message to a {{maxword|name=pcontrol}} object connected to an inlet of a subpatch can also be used to disable all MSP objects in that subpatch. (This disables all MIDI objects in the subpatch, too.) The {{maxword|name=pass~}} object silences the output of a subpatcher when it is muted.
of a signal chain in MSP. The <code>startwindow</code> message to
+
 
a {{maxword|name=dac~}} turns on audio only in one open Max document.
+
You can use a {{maxword|name=selector~}} object to choose one of several signals to be passed on out the outlet, or to close off the flow of all the signals it receives. All MSP objects that are connected in a signal flow between the outlet of a {{maxword|name=begin~}} object and an inlet of a {{maxword|name=selector~}} object (or a {{maxword|name=gate~}} object) get completely disconnected from the signal network when that inlet is closed.
The {{maxword|name=begin~}} and {{maxword|name=selector~}} objects allows us to
+
 
declare and selectively disable parts of an MSP signal
+
Any of these methods is an effective way to play selectively a subset of all the MSP objects in a
processing network within a Max patcher. MSP signal objects
+
given signal network (or to select one of several different networks). You can have many signal
within {{maxword|name=patcher}} objects and abstractions can be disabled
+
networks loaded, but only enable one at a time; in this way, you can switch quickly from one
as well, either by using a {{maxword|name=mute~}} object or
+
sound to another, but the computer only does processing that affects the sound you hear.
the <code>enable</code> message to a {{maxword|name=pcontrol}} object.
+
 
The {{maxword|name=pass~}} object, when used within a mutable subpatch,
+
You can use the {{maxword|name=poly~}} object to disable the processing for the parts of the signal network that are not needed at a given time.
zeroes the audio coming out of the subpatch to prevent
+
clicks or DC noise.
+
  
 
 
===See Also===
 
===See Also===
  
{{maxword|name=selector~}} - Assign one of several inputs to an outlet
+
{{maxword|name=poly~}} - Manage polyphony/DSP for patchers
  
{{maxword|name=pcontrol}} - Open and close subwindows within a patcher
+
{{maxword|name=selector~}} - Assign one of several inputs to an outlet
 +
</seealsolist>
  
[[Category:Teaching Material]]
+
</chapter>

Revision as of 19:51, 5 July 2012

<openpatchlink>Open the tutorial</openpatchlink>.

Contents

Turning audio on and off selectively

There are two elementary ways of turning audio processing on and off in an MSP patcher:

  1. Send a start or stop message to a ezdac~, ezadc~, dac~, or adc~ object.
  1. Click on a ezdac~ or ezadc~ object.

For the first tutorial that introduces the poly~ object and the idea of polyphony in general, we are going to take a step back and think more broadly about allocating resources in a signal processing patch - when you think about it, that is what polyphony is about, in a general way.

There are two other ways of turning audio processing on and off in an MSP patcher we have not yet mentioned:

  1. Send an int to a dac~, adc~, ezdac~, or ezadc~ object. 0 is the same as stop, and a non-zero number is the same as start.
  1. Double-click on a dac~ or adc~ object to open the Audio Status window, then use its Audio on/ off pop-up menu. You can also choose Audio Status... from the Options menu to open the Audio Status window.

Any of those methods of starting MSP will turn the audio on in all open Patcher windows and their subpatches. There are also a several ways to turn audio processing on and off in a single Patcher.

Local control with the startwindow message

Sending the message startwindow -- instead of start -- to a ezdac~, ezadc~, dac~, or adc~ object turns the audio on only in the Patcher window that contains that object, and in its subpatches. It turns audio off in all other Patchers. The startwindow message is very useful because it allows you to have many different signal networks loaded in different Patchers, yet turn audio on only in the Patcher that you want to hear. If you encapsulate different signal networks in separate patches, you can have many of them loaded and available but only turn on one at a time, which helps avoid overtaxing your computer's processing power. (Note that startwindow is used in all MSP help files so that you can try the help file's demonstration without hearing your other work at the same time.)

In some cases (e.g. when you have multiple helpfile patcher windows open), using the startwindow message is more appropriate than start.

Using the Mixer Engine to control audio

Every top-level patcher in Max has its own DSP chain, and is equipped with a mixer engine that lets you turn audio on and off in the patcher. You'll find the Mixer engine controls in the patcher window toolbar. By default, the Mixer control panel controls for the dac~ or ezdac~ object in your patcher window (you can add additional dac~ objects to your patch as described <link type="vignette" module="core" name="mixer" anchor="multidac">here</link>).

To display the Mixer engine control panel for your patcher, click on the Mixer button in the patcher toolbar.

File:Mixerpanel.png

You can click and drag on the volume knob to set the output volume for the patcher window, and mute or solo the audio output using the M (Mute) or S (Solo) buttons.

The Mixer Engine also allows you to fade the audio in or out when you turn audio on and off in a patcher window by adding an amount of latency to the patcher outputs. You can set the length of the fade in/out in milliseconds by setting mixer latency and crossfade time in the <link module="core" name="mixer_preferences" type="vignette">Mixer Preferences</link>.

Selecting one of several signals: selector~

In the previous chapter, we saw the gate~ object used to route a signal to one of several possible destinations. Another useful object for routing signals is selector~, which is comparable to the Max object switch. Several different signals can be sent into selector~, but it will pass only one of them -- or none at all -- out its outlet. The left inlet of selector~ receives an int specifying which of the other inlets should be opened. Only the signal coming in the opened inlet gets passed on out the outlet.

Image079.gif

The number in the left inlet determines which other inlet is open

As with gate~, switching signals with selector~ can cause a very abrupt change in the signal being sent out, resulting in unwanted clicks. So if you want to avoid such clicks it's best to change the open inlet of selector~ only when audio is off or when all of its input signal levels are 0.

In the tutorial patch, selector~ is used to choose one of four different classic synthesizer wave types: sine, sawtooth, triangle, or square. The umenu contains the names of the wave types, and sends the correct number to the control inlet of selector~ to open the desired inlet.

  • Choose a wave type from the pop-up menu, then click on the startwindow message. Use the pop-up menu to listen to the four different waves. Click on the stop message to turn audio off.

Turning off part of a signal network: pcontrol

If you want to enable or disable signal processing in a patcher or abstraction, you can use the pcontrol object. The enable message to pcontrol turns off all activity within a subpatcher - both MSP signals and Max scheduling.


Technical detail: If you double-click on the pcontrol object named harmonics and look inside, you'll hotice that 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.


Turning off part of a signal network: poly~

You have seen that the selector~ and gate~ objects can be used to listen selectively to a particular part of the signal network. The parts of the signal network that are being ignored — for example, any parts of the network that are going into a closed inlet of selector~ — continue to run even though they have been effectively disconnected. That means MSP continues to calculate all the numbers necessary for that part of the signal network, even though it has no effect on what you hear. It would be preferable if one could actually shut down the processing for the parts of the signal network that are not needed at a given time.

The poly~ object allows us to do just that.

The poly~ object is very powerful - to describe it simply, it lets us create and manage multiple copies of the same MSP subpatch within one object, and is very useful for creating polyphonic synths. We'll describe its use for that purpose in greater detail in a <link type="tutorial" module="msp" name="mspchapter21">later tutorial</link>. For now, we'll show you how to use it to conserve CPU usage.

The tutorial patch contains an example of the poly~ object used to enable and disable signal processing in a patch.

Polymute.png

The poly~ object takes as its argument the name of a patcher file, followed by a number that specifies the number of copies (or instances) of the patch to be managed (in this case, it's only a single instance). When you launch the patch, a toggle object automatically sends the message mute 0 1 to the poly~ object.

To look inside the poly~ object, double-click on it to open a new patcher window.

The in and out~ objects function in a matter similar to inlet and outlet objects in a subpatcher. The second in object receives the mute message and routes it to the thispatcher object. Sending the mute 0 1 message to the thispatcher object located in the patch will shut down the processing of the loaded subpatcher completely (the first zero indicates that you are sending the message to the first and only instance of the subpatcher loaded in the poly~ object).

When the tutorial patch opens for the first time, toggle object connected to the message box that contains the control message is on, and the oscillators in the wobbler abstraction inside the poly~ object are shut down. If you click on the toggle to send the message mute 0 0 to the thispatcher object, you will hear the oscillators. If you have the Mixer Engine window open, you will also notice that the percentage CPU usage increases, indicating that there is more audio processing going on.

Creating your own stompbox

The final portion of our tutorial patch - the stompbox patcher - combines two different techniques used in this tutorial with some clever patching to imitate a stompbox that not only selects direct or processed output, but also turns processing off when it is not selected.

Stompbox1.png

Our patcher contains a trigger object to route and control the order of events. The right outlet of the trigger object takes a 0 or 1 input value and uses it with the mute 0 message to turn processing on or off inside the patcher loaded in the poly~ object. Since we want to send the mute 0 1 message that mutes the subpatcher when the stompbox button is on, we use the !- object to invert the switch input.

Our patcher also contains a selector~ object that switches between the straight patcher input (the center inlet) and the output of a poly~ object that contains a simple distortion patch. Since the selector~ switch uses a zero indicate that no output is selected, we'll need to add 1 to our stompbox toggle object's output.

So when we press the toggle attached to the right inlet of the stompbox patcher file, we do two things:

  • We send the message mute 0 0 to turn the processing inside of the poly~ object on or off.
  • We send a 1 or 2 to the selector~ object to choose the straight or processed input to the selector~ and output it.

Stompbox2.png

Summary

The startwindow message to dac~ (or adc~) starts audio processing in the Patcher window that contains the dac~, and in any of that window's subpatches, but turns audio off in all other patches. The mute~ object, connected to an inlet of a subpatch, can be used to disable all MSP objects in that subpatch. An enable 0 message to a pcontrol object connected to an inlet of a subpatch can also be used to disable all MSP objects in that subpatch. (This disables all MIDI objects in the subpatch, too.) The pass~ object silences the output of a subpatcher when it is muted.

You can use a selector~ object to choose one of several signals to be passed on out the outlet, or to close off the flow of all the signals it receives. All MSP objects that are connected in a signal flow between the outlet of a begin~ object and an inlet of a selector~ object (or a gate~ object) get completely disconnected from the signal network when that inlet is closed.

Any of these methods is an effective way to play selectively a subset of all the MSP objects in a given signal network (or to select one of several different networks). You can have many signal networks loaded, but only enable one at a time; in this way, you can switch quickly from one sound to another, but the computer only does processing that affects the sound you hear.

You can use the poly~ object to disable the processing for the parts of the signal network that are not needed at a given time.

See Also

poly~ - Manage polyphony/DSP for patchers

selector~ - Assign one of several inputs to an outlet </seealsolist>

</chapter>