import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
Minim minim;
AudioInput in;
FFT fft;
int grid = 50;
float gridWidth;
float[][] zs;
void setup(){
size(500, 500, P3D);
smooth();
minim = new Minim(this);
in = minim.getLineIn(Minim.STEREO, 1024);
fft = new FFT(in.bufferSize(), in.sampleRate());
zs = new float[grid + 1][grid + 1];
for(int w = 0; w < grid; w++){
for(int h = 0; h < grid; h++){
zs[w][h] = 0.0;
}
}
gridWidth = width / float(grid);
}
void draw(){
lights();
fft.forward(in.mix);
for(int w = grid - 1; w >= 0; w--){
for(int h = grid - 1; h >= 0; h--){
if(h == 0){
zs[w][h] = fft.getBand(w) * 3;
} else {
zs[w][h] = zs[w][h - 1];
}
}
}
background(0);
translate(0, 0, -300);
rotateX(PI / 4.0);
for(int w = 0; w < grid; w++){
for(int h = 0; h < grid; h++){
beginShape();
vertex(w * gridWidth, h * gridWidth, zs[w][h]);
vertex((w + 1) * gridWidth, h * gridWidth, zs[w + 1][h]);
vertex((w + 1) * gridWidth, (h + 1) * gridWidth, zs[w + 1][h + 1]);
vertex(w * gridWidth, (h + 1) * gridWidth, zs[w][h + 1]);
endShape(CLOSE);
}
}
}