Hello everybody, I'm new with Processing and I'm having some troubles with my code.. I would like Processing to upload different images, depending on the value of the AudioInput.. Depending on the frequency of the sound, the image should change.
Here is the code, but what I can see is only a white square so I guess that something is wrong.. Maybe the values? How can I get the frequencies of a live sound?
Thanks for your advices, and.. sorry for my English!
PImage a;
import ddf.minim.*;
Minim minim;
AudioInput in;
int val;
void setup()
{
size (600,600,P2D);
a = loadImage("2.jpg");
background (255,255,255);
minim = new Minim(this);
minim.debugOn();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 512);
}
void draw()
{
val=Math.abs(int(in.mix.get(0)*512));
println(val);
if(val > 0 && val < 85){loadImage("1.jpg");
}
else { if (val > 85 && val < 170) {a=loadImage ("2.jpg");
}
}
if (val > 170 && val < 255) {a=loadImage ("3.jpg");
}
else { if (val > 255 && val < 340) {a=loadImage ("4.jpg");
}
}
if (val > 340 && val < 425) {a=loadImage ("5.jpg");
}
else { if (val > 425 && val < 512) {a=loadImage ("6.jpg");
}
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.
stop();
}