Audio Visualizer

Here's an example of a basic visualiser made in processing, followed by the code. The green bars get longer when the volume of the audio input increases and eventually reach a red bar when the input is really loud.





//------------

import ddf.minim.*;

Minim minim;
AudioInput in;

float leftCh;
float rightCh;

void setup()
{
size(512, 200, P2D);
textMode(SCREEN);

minim = new Minim(this);

// get a stereo line-in: sample buffer length of 2048
// default sample rate is 44100, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 2048);

textFont(createFont("SanSerif", 12));
stroke(255);

}

void draw()
{
background(0);
text("Listening to current sound input", 5, 15);
// draw the left and right audio levels
// values returned by left.get() and right.get() will be between -1 and 1,
// so we need to scale them up to see the waveform
for(int i = 0; i < in.bufferSize() - 1; i++) { // this line below gets the level of the left channel leftCh = in.left.get(i)*500; // if statements to change colour of the bar depending on level if (leftCh > 400) {
fill(255,0,0);
stroke(255,0,0);
} else {
fill(0,255,0);
stroke(0,255,0);
}
// the line below draws a horizontal bar of width: left signal x 500
rect(0, 50, leftCh, 10);

rightCh = in.right.get(i)*500;
if (rightCh > 400) {
fill(255,0,0);
stroke(255,0,0);
} else {
fill(0,255,0);
stroke(0,255,0);
}
rect(0, 150, rightCh, 10);
}
}

void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();

super.stop();
}

//------------