/**
* Randomly coloured audio monitor
* Code based on example code from Minim documentation which can be found at
* http://code.compartmental.net/minim/audioinput_class_audioinput.html
*/
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup()
{
size(displayWidth, displayHeight, P3D);
minim = new Minim(this);
// use the getLineIn method of the Minim object to get an AudioInput
in = minim.getLineIn();
}
void draw()
{
background(0);
stroke(255);
// draw the waveforms so we can see what we are monitoring
for(int i = 0; i < in.bufferSize() - 1; i++)
{
float percent = (float)i / (float)in.bufferSize();
float getLeft = in.left.get(i);
float getRight = in.right.get(i);
//stroke(random(getLeft*500), random(getLeft*500), random(getLeft*500));
line( percent*width, height*0.25 + getLeft*400, percent*width+1, height*0.25 + getLeft*200 );
line( percent*width, height*0.50 + getLeft*400, percent*width+1, height*0.55 + getLeft*200 );
line( percent*width, height*0.75 + getRight*400, percent*width+1, height*0.75 + getRight*200 );
}
String monitoringState = in.isMonitoring() ? "enabled" : "disabled";
//text( "Input monitoring is currently " + monitoringState + ".", 5, 15 );
}
void keyPressed()
{
if ( key == 'm' || key == 'M' )
{
if ( in.isMonitoring() )
{
in.disableMonitoring();
}
else
{
in.enableMonitoring();
}
}
}