<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<!-- Tutorial -->
<chapter name="MSP panning Tutorial 3: Multi-channel panning">


<setdocpatch name="03pQuadpanning" patch="03pQuadpanning.maxpat"/>
<previous name="13_panningchapter02"></previous>
<next name="14_analysischapter01"></next>
<parent name="00_mspindex">MSP Tutorials</parent>

	<!-- Heading -->
	<h1>MSP panning Tutorial 3: Multi-channel panning</h1>
	<p>
		This tutorial discusses panning around four channels and blendiing four sound sources.
	</p>


	<!-- First section -->
	<h2>Panning in Quad</h2>
	<p>
		Even though "Quad Sound" went out of style in the '80s, there are still many situations where sound needs to be distributed to four locations. For instance, four of the six signals in 5.1 movie soundtracks are located in the four corners of the theater. (The other two being dialog center and low frequency effects). The preferred controller for four channel panning is a joystick or a two dimensional control such as <o>pictslider</o>.
	</p>
	<bullet>Open the <m>Quad_pan</m> subpatcher and start the window audio.</bullet>
	<techdetail>
		If you don't have a four channel listening environment, you should open <m>Audio Status</m> in the Options menu and select <i>I/O Mappings</i>. Route channel 3 to output 1 and channel 4 to output 2.
	</techdetail>
	<p>
		The signal_source subpatch has three sources in it&#x2014;a simple tone generator, a short audio file, and an <o>adc~</o> object so you can apply your own test signal. You can choose the source with a <o>umenu</o> and use the <o>toggle</o> to start the tone generator and audio file. The output of this patch is a four channel <o>dac~</o>, but since four channel listening environments are not all that common, channels 3 and 4 are piped through <o>cverb~</o> objects so they will have a distinct (somewhat distant) sound in stereo.
	</p>

<bullet>Select the <m>tones</m> option in the <o>umenu</o> and set the toggle to start playing.</bullet>
<p>
	Begin exploring the patch by moving the circle in the <o>pictslider</o> left and right while keeping it at the bottom of the frame. The pan function is linear, derived by scaling the <o>pictslider</o> X output to 0-1 and taking the square root. This is the same as the <m>pow($f1, 0.5)</m> formula shown in <link type="tutorial" module="msp" name="13_panningchapter02">Stereo Panning</link>. As before, the value derived is applied to the right channel and and <m>pow((1-$f1), 0.5)</m> is applied to the left channel. But there is a twist, as you can see by moving the circle up in the <o>pictslider</o>. Both values are multiplied by similar values derived from the Y axis. The result of this is the sound is also panned forward and back. Each of the four channels is controlled by some combination of X and Y or 1-X and 1-Y. The colors in the patch should make the control pathways easy to follow. Note that the Y values are attached to the right inlet of each <o>*~</o> object and must be accompanied by <m>bangs</m> to update the calculation when they change.
</p>
<h2>Stereo to quad</h2>
<p>
	Now try the music example with the play option. Note that these are mono signals (left channel only). To inject a stereo signal into a quad space, you need to combine a balance control with the front to back panning. This is shown in the <m>Stereo_quad_pan</m> subpatch. When you open it up, it should look familiar. All we had to do was include a stereo signal souorce and route the left and right channels as shown. I also changed to a 4.5 dB panning law for left and right, but that is optional. (Again, see <link type="tutorial" module="msp" name="13_panningchapter02">Stereo Panning</link>.) This kind of circuit is found in many automobile sound systems.
</p>


<h2>Mixing four sources</h2>
<p>
	Two dimensional controls are also found in some synthesizers where they are used to blend waveforms, a technique called <i>vector synthesis</i> or <i>morphing</i> depending on the nature of the signals. The <m>Quad_mix</m> subpatch contains an instrument that works in this way. The heart of the patch is the same set of calculations used above, although they have been encapsulated into the <m>Quad_level_control</m> subpatch here. The new part of the patch is a simple beep instrument with a possibility of four waveforms blended by the <o>pictslider</o> object. You can set the duration of the notes to explore the effect of moving the control while a note plays.
</p>




	<!-- Summary -->
	<summary>Summary</summary>
	<p>
		This tutorial demonstrates the principles of working with four channel sound, either distributing sound to four separate speakers or combining sounds from four sources. The main control used is the <o>pictslider</o> object, which is the Max version of a joystick.
	</p>

	<!-- See Alsos -->
	<seealsolist>
		<seealso name="pictslider"  />
	</seealsolist>

</chapter>
