Processing

Now we had to put all the images in processing, the initial processing code was too graphic intensive for the computer to handle, so we had to reduce the quality slightly, here's the final code...

import ddf.minim.*;
import processing.opengl.*;

Minim minim;
AudioInput in;
//sets a name for all the images
PImage a;
PImage b;
PImage c;
PImage d;
PImage e;
PImage f;
PImage g;
PImage h;

float audinL;
float audinR;
float audin;
int audinInt;
int audinAvg;
int audinCount;
int samplecount = 1;

void setup()
{
size(1000, 679, P2D);
//defines the size of the screen and the graphic format;

minim = new Minim(this);

//loads all the images
a = loadImage("a.jpg");

b = loadImage("b.jpg");

c = loadImage("c.jpg");

d = loadImage("d.jpg");

e = loadImage("e.jpg");

f = loadImage("f.jpg");

g = loadImage("g.jpg");

h = loadImage("h.jpg");


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

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 audinL = in.left.get(i)*10000; // right channel audinR = in.right.get(i)*10000; // average of the two channels audin = (audinL + audinR) / 2; if(audin < 0) { audin = -audin; } audinInt = int(audin); audinCount = audinCount + audinInt; samplecount ++; // only check values after 10 samples if (samplecount == 10) { samplecount = 1; audinAvg = audinCount / 10; println(audinAvg); audinCount = 0; // if statements to change image depending on level if (audinAvg > 2000) {
background(a);
}
else if (audinAvg > 2100) {
background(b);
}
else if (audinAvg > 1800) {
background(c);
}
else if (audinAvg > 1500) {
background(d);
}
else if (audinAvg > 1200) {
background(e);
}
else if (audinAvg > 900) {
background(f);
}
else if (audinAvg > 600) {
background(g);
}

else {
background(h);
}
}
}
}

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

super.stop();
}