K0F_2014/02-unor/epSittinOnChairs/epSittinOnChairs.pde
/**
 * This sketch demonstrates how to use an FFT to analyze
 * the audio being generated by an AudioPlayer.
 * <p>
 * FFT stands for Fast Fourier Transform, which is a 
 * method of analyzing audio that allows you to visualize 
 * the frequency content of a signal. You've seen 
 * visualizations like this before in music players 
 * and car stereos.
 */

import ddf.minim.analysis.*;
import ddf.minim.*;

ArrayList waves;

Minim       minim;
AudioPlayer jingle;
FFT         fft;

void setup()
{
  size(512, 512, P3D);

  minim = new Minim(this);

  // specify that we want the audio buffers of the AudioPlayer
  // to be 1024 samples long because our FFT needs to have 
  // a power-of-two buffer size and this is a good size.
  jingle = minim.loadFile("out.mp2",2048);

  // loop the file indefinitely
  jingle.loop();

  // create an FFT object that has a time-domain buffer 
  // the same size as jingle's sample buffer
  // note that this needs to be a power of two 
  // and that it means the size of the spectrum will be half as large.
  fft = new FFT( jingle.bufferSize(), jingle.sampleRate() );

  waves = new ArrayList();
}

void draw()
{
  background(0);
  stroke(255);

  // perform a forward FFT on the samples in jingle's mix buffer,
  // which contains the mix of both the left and right channels of the file
  fft.forward( jingle.mix );

  waves.add(new float[512]);
  float [] tmp = (float[])waves.get(waves.size()-1);


  if(waves.size()>200)
    waves.remove(0);

  float top = 0.0;
  for(int i = 0; i < 512; i++)
  {
    tmp[i] = fft.getBand(i)*pow(i,1.2)/100.0;
    top = max(top,tmp[i]);
    // draw the line for frequency band i, scaling it up a bit so we can see it
    //line( i, height, i, height - fft.getBand(i)*8 );
  }

  println(top);

  pushMatrix();
  translate(0,0,-1412);
  noFill();
  stroke(255,35);
  
  for(Object o: waves){
    float [] tmp2 = (float[])o;
    beginShape();
    for(int i = 0; i < 512; i++)
    {
      stroke(255,constrain(tmp2[i]*9,0,90));
      vertex(i,-tmp2[i]+512,waves.indexOf(tmp2)*10-1080);
    }
    endShape();

  }
  popMatrix();
}
