<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Video and Graphics 8: Audio into a matrix">

<previous name="jitterchapter00i_Generating Geometry">Generating Geometry</previous>
<next name="jitterchapter00k_Building live video effects">Building live video effects</next>
<parent name="jitindex">Jitter Tutorials</parent>

<openfile name="Audio into a matrix" patch="jitter_core_-_8_-_Audio_into_a_matrix_1.maxpat"/>

<h1>Video and Graphics Tutorial 8: Audio into a matrix</h1>



<h2>Intro</h2>



<p>Whether it’s for installations or your next VJ set, audio-responsive visuals can be one of the most exciting aspects of working with real-time images in Max. In this section we will look at several ways of using sound in combination with Jitter.
</p>

<h2>Setup</h2>

<p>To get started, set up the usual combination of a <o>jit.world</o> object with a named rendering context (we'll use <b>jit.world loud</b> here) and <o>toggle</o>, and add an <o>ezadc~</o> object anywhere in your patch. The <o>ezadc~</o> object lets use our built-in microphone as a source for live audio input.</p>

<illustration><img src="images/jitter_core - 8a.png"/></illustration>

<p>If you’d rather work with audio samples, you can create an audio <o>playlist~</o> object using the same
technique as we used in the very first of these tutorials: Click on the audio icon (it's the eighth note directly above the video icon on the left sidebar) of your patcher window to show the Audio Browser, click on the name of an audio file and drag it from the browser to an empty spot in your patcher window to create a <o>jit.playlist</o> loaded with the audio you selected.</p>

<h2>Amplitude</h2>

<p>If you are looking for a one-to-one correlation between sound and changes in an image, amplitude (loudness) is often the simplest and most directly observable.  </p>

<p>Create a <o>peakamp~</o> object and connect its output to a <o>flonum</o> object. Connect the left outlet of <o>ezadc~</o> to the left inlet of <o>peakamp~</o>. We're going to need a way to trigger readings from the <o>peakamp~</o> object, so we'll connect the middle outlet of <o>jit.world</o> to the <o>peakamp~</o> object's left inlet. Lock your patch, click on the <o>toggle</o> to turn on <o>jit.world</o>, and then the click on
the <o>ezadc~</o> object to turn audio on. Make some noise to see how your voice, typing, or sound in your environment translates into number values.</p>

<illustration><img src="images/jitter_core - 8b.png"/></illustration>

<div>
	<techdetail>

		<p> The <o>peakamp~</o> object takes in a signal. Each time it receives a <m>bang</m>, it outputs the highest amplitude value received value since the last <m>bang</m>. The center outlet of <o>jit.world</o> object automatically sends out a <m>bang</m> each time it completes rendering a frame - so you automatically get one new value per frame, in sync with your frame rate. </p>

	</techdetail>
</div>

<p>Now that you have some values to work with, you can use the amplitude to control any aspect of your patch. Let’s start with something simple like adjusting brightness of incoming video. Add a <o>jit.grab</o> object with a <o>message</o> box containing the word <m>open</m> attached to its inlet, and a <o>jit.brcosa</o> with an <o>attrui</o> displaying <i>brightness</i> or <i>contrast</i> attributes to the upper and lower parts of your patch, respectively. Patch the output of <o>jit.grab</o> into <o>jit.brcosa</o> object's inlet, and the <o>jit.brcosa</o> object's outlet to the <o>jit.world</o>. Finally, connect the output of the <o>peakamp~</o>
to the inlet of the <o>attrui</o>. Click on the <m>open</m> <o>message</o> box to start the camera to see how the audio affects the brightness.</p>

<illustration><img src="images/jitter_core - 8c.png"/></illustration>

<p>You can also use audio filters to extend what’s possible with amplitude control. By emphasizing or reducing certain frequencies of audio input, we can take a single input source and use it to control a variety of parameters. Let’s try this now with an <o>svf~</o> filter (state-variable filter).</p>

<p><openfilelink filename="jitter_core_-_8_-_Audio_into_a_Matrix_3.maxpat">Open the example patch</openfilelink>.</p>

<p>In this example, we take a drum sample and split it off into three filtered streams - a low pass, high-pass and bandpass - and use each of them to control aspects of the scale of an object created using <o>jit.gl.gridshape</o>. </p>

<illustration><img src="images/jitter_core - 8d.png"/></illustration>

<p>The low-end controls the x-scale of the object, the mids control the z-scale, and the high-end controls the y-scale. Try out the different sound files see how they affect the shape.</p>

<p>The raw output of <o>peakamp~</o> can be offset, scaled and smoothed to achieve a variety of behaviors. Some objects to look at are <o>scale</o>, <o>zmap</o> (which scales an input and clips the low and high range) and <o>slide</o>.</p>

<h2>Catching Audio</h2>

<p>The <o>jit.catch~</o> object allows us to sample incoming audio values and store them in a matrix. In our example, we use input signal data to manipulate a <o>jit.gl.gridshape</o> geometry matrix. Open up the <openfilelink filename="jitter_core_-_8_-_Audio_into_a_Matrix_1.maxpat">example patch</openfilelink>. Click on the <o>jit.world</o> object's <o>toggle</o> and the <o>ezdac~</o> to start things up, then select an audio source and begin playback to see the patch in action.</p>

<p>Let’s walk through the patch: The audio data is connected directly to <o>jit.catch~</o> - one of a few Jitter objects made to work directly with signal data. </p>

<illustration><img src="images/jitter_core - 8h.png"/></illustration>

<p>Each time it receives a <m>bang</m>, the <o>jit.catch~</o> object outputs the most recent frame of audio samples as a 1-plane matrix containing float32 (32-bit floating point) number values. Since our audio data is now converted into a regular jitter matrix, we can use other Jitter objects to perform operations on it.</p>

<p>Sending the output of the <o>jit.catch~</o> object to a <o>jit.matrix</o> object lets us adjust the output dimensions of the matrix, which will control the resolution of the changes made to the final form. Try adjusting the number value connected to the <m>dim $1 1</m> <o>message</o> box and see how it interacts. Lower <i>dim</i> values affect larger regions of the form, while higher values are more subtle. The matrix data then passes a <o>gate</o> object with an optional <o>jit.transpose</o>. Toggle the gate on/off to select which dimension is affected by the audio matrix. Next, the matrix passes through a <o>jit.*</o> object that scales how much the audio affects the image. The <o>jit.slide</o> eases the changes in data over time.</p>

<illustration><img src="images/jitter_core - 8i.png"/></illustration>

<p>The final output of our audio matrix is being displayed in a <o>jit.pwindow</o> as both raw matrix data and also as output formatted by a <o>jit.graph</o> object. Audio signal values are typically represented using data in the range of -1. to 1. (i.e. both positive and negative). In the raw form negative number values are represented as black in jit.pwindow. By converting the values for display with <o>jit.graph</o> object, we get a meaningful representation of <i>both</i> positive and negative values.</p>

<illustration><img src="images/jitter_core - 8e.png"/></illustration>

<p>To the right is the <b>jit.gl.gridshape @matrixoutput 1</b> object (setting the <i>matrixoutput</i> attribute will output the object as a matrix). The resulting matrix contains more planes of data than we really need for our patch, so we use the <b>jit.unpack 1 @jump 3</b> object to grab only the parts of the geometry matrix we are interested in - the x, y and z coordinates. The two matrices are combined using a <o>jit.op</o> object and then sent into a <o>jit.gl.mesh</o> object to be drawn. The default behavior for <o>jit.op</o> object is to pass the first two planes (x and y) unaltered and add the audio data to the z plane. Try some other options by clicking the various <m>op</m> messages.</p>

<illustration><img src="images/jitter_core - 8f.png"/></illustration>

<p>Try manipulating the settings in the patch and use a variety of input sources to see what’s possible. </p>

<div>
	<techdetail>

		<h2>Explore Further</h2>

		<p>Visualization of audio signals is a complex area of study and the methods that we have looked at are just a few possibilities. Some good places to explore more in this territory are the Jitter Recipes. Also, take a look through the Jitter examples to be found in the File Browser. Some other objects worth exploring in this area are <o>jit.poke~</o> and <o>jit.peek~</o>, as well as <o>jit.buffer~</o> and <o>jit.release~</o>.</p>


	</techdetail>
</div>



</chapter>
