import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
Minim minim;
AudioInput in;
FFT fft;
float[][] values;
int timeWidth = 200;
void setup(){
size(500, 500, P3D);
minim = new Minim(this);
in = minim.getLineIn(Minim.STEREO, 1024);
fft = new FFT(in.bufferSize(), in.sampleRate());
values = new float[fft.specSize()][timeWidth];
for(int i = 0; i < fft.specSize(); i++){
for(int j = 0; j < timeWidth; j++){
values[i][j] = 0.0;
}
}
fill(0);
stroke(255);
strokeWeight(2);
}
void draw(){
fft.forward(in.mix);
for(int i = 0; i < fft.specSize(); i++){
for(int j = 0; j < timeWidth - 1; j++){
if(j != timeWidth - 2){
values[i][j] = values[i][j + 1];
} else {
values[i][j] = fft.getBand(i);
}
}
}
background(0);
translate(width / 2, height / 2, -100);
rotateX(PI / 3);
rotateZ(PI / 12);
for(int i = 0; i < fft.specSize(); i += 10){
beginShape();
for(int j = 0; j < timeWidth; j++){
float x = map(j, 0, timeWidth - 1, -width / 2, width / 2);
float y = map(i, 0, fft.specSize() - 1, height / 2, -height / 2);
float z = values[i][j] * 10;
vertex(x, y, z);
}
endShape();
}
}