<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>
<chapter name="MSP Polyphony Tutorial 3: Audio-Rate Control Data">
	<previous module="msp"  name="11_polychapter02"></previous>
	<next module="msp" name="12_sequencingchapter01"></next>
	<parent name="00_mspindex">MSP Tutorials</parent>


<setdocpatch name="03hAudioRateControl" patch="03hAudioRateControl.maxpat"/>
	<h1>
		Polyphony Tutorial 3: Audio-Rate Control Data
	</h1>

	<h2>
		Low-frequency oscillators
	</h2>
	<p>
		This tutorial looks at using the <o>poly~</o> object to generate
		low-frequency oscillators (LFOs) to generate control-rate data for
		Max objects. There are many tasks in Max (such as graphics) that don't
		require control updates at audio rate (44,100 per second, or higher),
		and simply need to receive new values regularly at a lower speed. For
		example, a video processing patcher running at 30 frames per second
		would only need new information for all of its parameters every 33
		milliseconds. At the same time, MSP signal generators make excellent
		choices for designing periodic sources of control information.
		The <o>poly~</o> object has a simple way to <i>downsample</i> the audio
		processing in an abstraction, so that it can be used to create control-rate
		data in Max without the CPU overhead of working at audio rate.
	</p>
	<bullet>
		Take a look at the tutorial patcher. Turn on the <o>dac~</o> (on the right)
		and the <o>metro</o> (on the left) using the <o>toggle</o> objects. You
		should see a line being drawn in the <o>lcd</o> object on the right of
		the patcher. At any point, you can hit the space bar to <m>clear</m> the
		drawing.
	</bullet>
	<bullet>
		In the <o>number</o> boxes labeled <m>X</m> and <m>Y</m>, type <m>1.</m> and <m>1.3</m>,
		respectively. Look at the curve drawn in the <o>lcd</o>. Clear the <o>lcd</o>
		with the space bar and change the values to <m>1.</m> and <m>4.</m>. Notice
		that when the values are in an integer ratio the pattern begins redrawing itself
		after a while. Try your own numbers, or changing them as they go.
	</bullet>
	<p>
		Using cosine waves of different frequencies as the X and Y inputs of a drawing
		surface (such as an oscilloscope) creates something called <i>lissajous</i> curves.
		These patterns visually describe complex harmonic motion, so that X and Y
		patterns in simple ratios will create pre-determined repeating shapes.
	</p>
	<h2>
		Using <o>snapshot~</o>
	</h2>
	<bullet>
		Double-click one of the <o>poly~</o> objects to see inside
		the <m>polylfo1~</m> abstraction.
	</bullet>
	<p>
		Notice how simple our abstraction seems, with an <o>in</o> object
		allowing use to set the frequency of a <o>cycle~</o> object. A
		second <o>in</o> object provides <m>bang</m> messages to
		a <o>snapshot~</o>. The <o>snapshot~</o> object allows us to
		capture single values of MSP signals as floating-point numbers
		generated as Max events. Whenever a <o>snapshot~</o> receives
		a <m>bang</m>, it <i>samples</i> the current MSP signal at its
		inlet and outputs that one sample as a floating-point value.
		In our tutorial, this value then goes to an <o>out</o> object,
		and back into our main patcher.
	</p>
	<h2>
		Changing abstractions
	</h2>
	<bullet>
		Close the abstraction <m>polylfo1~</m> and return to the main
		tutorial patcher. Click on the <o>message</o> boxes in the middle
		that begin with the message <m>patchername</m>. The <m>patchername</m>
		message <i>reloads</i> a <o>poly~</o> object with a new abstraction.
		Notice the effect on the drawing, depending on which you select and
		whether it applies to the X or Y <o>poly~</o> object.
		Select <m>polylfo2~</m> and double-click the <o>poly~</o> object to
		see it.
	</bullet>
	<p>
		The <m>polylfo2~</m> abstraction does the same as <m>polylfo1~</m>,
		but generates its output as a sawtooth wave rather than a cosine wave.
		The <o>phasor~</o> object generates ramps from <m>0</m> to <m>1</m>,
		so we scale the output to go between <m>-1</m> and <m>1</m> with
		the <o>*~</o> and <o>-~</o> objects before we sample it with
		the <o>snapshot~</o>
	</p>
	<bullet>
		Switch one of the <o>poly~</o> objects to <m>polylfo3~</m> and look inside.
	</bullet>
	<p>
		The <m>polylfo3~</m> object generats a triangular output by using
		a <o>triangle~</o> object. The <o>triangle~</o> object wraps
		a <o>phasor~</o> around a midpoint, essentially translating it
		into a triangular waveform. This object outputs values between <m>-1</m>
		and <m>1</m>, so it doesn't require any scaling.
	</p>
	<h2>
		Resampling arguments
	</h2>
	<bullet>
		Close any open abstractions and return to the main patcher. Look at
		the arguments to the <o>poly~</o> objects.
	</bullet>
	<p>
		When working with an abstraction inside of a <o>poly~</o> object,
		you can decide to work at a lower or higher <i>sampling rate</i>
		than your main MSP patcher. This rate is not specified directly,
		but as a divisor or multiplier of the main rate. The arguments <m>up 2</m>
		will make the <o>poly~</o> run at twice the sampling rate of the
		main patcher. The arguments <m>down 8</m>, as shown here, run the
		audio within the <o>poly~</o> objects at one <i>eighth</i> the
		normal speed (i.e. 5.5125kHz if the main patcher runs at 44.1kHz).
		Since we're only sampling our oscillator values once every frame
		of the drawing (set by the <o>metro</o> speed at 50Hz or every 20ms),
		this is more than enough resolution for our control data.
	</p>
	<bullet>
		Mix and match different LFO curves by choosing different <o>poly~</o>
		abstractions run at different frequencies. Notice how the Lissajous
		curves behave with the different waveforms.
	</bullet>
	<h2>
		Summary
	</h2>
	<p>
		The <o>poly~</o> object can work at a different sampling rate than
		its host MSP patcher. The <m>up</m> and <m>down</m> arguments allow
		you to specify a multiplier or divisor for the main sampling rate.
		When designing LFOs (low frequency oscillators), it's often useful
		to use massively downsampled MSP patchers inside of <o>poly~</o>
		objects to generate the curves efficiently. the <o>snapshot~</o>
		object allows you to sample a single value from an MSP signal in
		response to a <m>bang</m>.
	</p>
	<seealsolist>
		<seealso name="snapshot~">Convert signal values to numbers</seealso>
	</seealsolist>
</chapter>

