How do I let my music visualizer detect the frequency of the song when its high it display a smiley face(which i already did) and a frown face when the song is slow with low frequency. I have already able to draw the faces but dont know how to make my code detect the beat and change
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer groove;
AudioMetaData meta;
BeatDetect beat;
float yoff = 0.0;
float slowChange;
int screen=0;
void setup()
{
selectInput("Select a file to process:", "fileSelected");
size(640, 360, P3D);
ellipseMode(CENTER);
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
screen = 1;
} else {
println("User selected " + selection.getAbsolutePath());
minim = new Minim(this);
groove = minim.loadFile(selection.getAbsolutePath(), 2048);
groove.play();
beat = new BeatDetect();
screen = 2;
}
}
void draw()
{
if (screen ==2)
{
background(#7A9EB9);
fill(#FFA00F);
ellipse(320, 180, 300, 300);
beat.detect(groove.mix);
stroke(#40FAFF);
strokeWeight(2);
if(beat.isOnset()==true)
{
fill(#FF0808);
ellipse(270, 120, 60, 60);
fill(#2CE823);
ellipse(370, 120, 90, 90);
}
else
{
fill(#3B0D37);
ellipse(270, 120, 60, 60);
fill(#2754CB);
ellipse(370, 120, 90, 90);
}
if(keyPressed)
{
//sad
noFill();
for(int i = 0; i < groove.bufferSize() - 2; i++){
slowChange = lerp(slowChange, groove.left.get(0), 0.2);
//Left right, up down, (how high)
arc(310, 320 + (30 * slowChange), 100, 300, PI+QUARTER_PI, TWO_PI, OPEN);
}
}
else //happy
{
noFill();
for(int i = 0; i < groove.bufferSize() - 2; i++){
slowChange = lerp(slowChange, groove.left.get(0), 0.2);
arc(320, 180 + (50 * slowChange), 300, 200, 0, PI, OPEN);
}
}
fill(#0220D8);
beginShape();
float xoff = 0;
for (float x = 0; x <= width; x += 10) {
float y = map(noise(xoff, yoff), 10, 1, 0, 300);
vertex(x, y);
xoff += 0.10;
}
yoff += 0.10;
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
}
else
{
rect(10,50,60,20);
}
}