Course Specifics:

Syllabus

Assignments

Course Notes

Course Books

readings

 

Processing LInks:

processing.org

openprocessing.org

learningprocessing.com

 

Art / Design / Code:

CreativeApplications.net

CreateDigitalMotion.com

Marius Watz

Generator X

Code & Form

Casey Reas

Ben Fry

Golan Levin

Dan Shiffman

Jared Tarbell

PostSpectacular

Flight 404

Robert Hodgin

 

 

Course Notes 4 - Audio and Audio Input:

Advanced Beauty from mate on Vimeo.

 

* Relavant course book pages: 579-600

* Relevant online reference:

http://code.compartmental.net/tools/minim/

Audio Input:

While much can be done in terms of audio processing and audio generation in processing (see pp. 579-600 for examples) through the use of third-party libraries and audio processing functions, Processing comes pre-packaged with teh MINIM libraries, which allow for relatively straightforward handling of audio recording, input, and playback, which we will be primarily focused upon for the upcoming project.

 

The MINIM library:

The Minim ilbrary contains all of the tools you'll need for basic use of audio in Processing. It handles the various methods of playing back sound files, and samples, as well as recording audio coming in through a microphone, as well as audio generated by processing itself.

Full documentation of the Minim LIbraries can be found here: http://code.compartmental.net/tools/minim/

 

For the time being, we're going to focus on how to open an audio input in processing, and use the amplitude (volume) of the incoming signal to drive events and objects in processing.

 

Using Minim:

The process of getting minim up and running in processing is fairly straightforward, and is as follows:

 

1. Import the Minim Library:

import_minim

 

2. Declare a Minim object: Just as with declaring and creating classes, you must first create a minim 'object' in processing by doing the following:

 

Minim minim;

 

This creates a Minim object with the name 'minim.' This object will then have associated with it all of the necessary methods of the Minim object as described on the website.

 

3. Declare an AudioInput: In order to access the audio input functions, we must create an audioinput object like so:

 

AudioInput input;

 

4. Instantiate the minim and audioinput objects: Now that the minim and audioinput objects have been declared, we need to create, or instantiate, them in the setup() function:

 

void setup()

{

size(500,500);

minim = new Minim(this);

input = minim.getLineIn(Minim.MONO,512);

}

 

Here we have told 'input' to function as a 'getLineIn' which listens to a mono Minim audio stream of 512 samples at a time.

 

Listening:

Now that we have created an AudioInput object called 'input' we can access what it is hearing by doing the following:

 

 

void draw()

{

float a = in.left.get(1);

println(a);

}

 

Wherein the variable 'a' would be equal to the amplitude of the left channel of audio at the 1st sample.

 

Amplitude: The numbers being fed to 'input' are the amplitude of the audio signal at a given sample, this will always range from negative one to positive one.

If you were to only want positive numbers from the audio signal, you could do:

 

float a = abs(in.left.get(1));

This would ensure you'd only be getting positive numbers from the audio input.

 

CLOSING MINIM:

Important!

One thing you must do with the minim objects is ensure that they have been 'closed' at the time your sketch quits. Not doing so can lead to unpredictable behaviour. Whenever using the minim objects, you must have the following code somewhere in your sketch:

 

void stop()
{

// the AudioInput you got from Minim.getLineIn()
input.close();
minim.stop();

// this calls the stop method that
// you are overriding by defining your own
// it must be called so that your application
// can do all the cleanup it would normally do
super.stop();
}

 

In-Class exercise:

Please download the following code, which has all the elements in place to move particles around the screen autonomously. In class, we will plug in the minim objects in order to make the particles move based on their reaction to audio-input:

Download 'noise_starter.pde'.