schoolofma_interactiveSpaces2014code/chris/audio/audio_waveform_and_fft/audio_waveform_and_fft.pde
import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;  
AudioInput input;
FFT fft;

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

  minim = new Minim(this);
  input = minim.getLineIn(Minim.STEREO, 1024); 
  fft = new FFT(input.bufferSize(), input.sampleRate());
}

void draw() {

  background(0, 0, 0);

  //println(input.mix.level()*1000);

  float radius =10+ (int)map(input.mix.level()*1000, 0, 50, 0, 20);
  fill(255);
  noStroke();
  ellipse(width-50, 50, radius, radius);
  
    stroke(255);

  for (int i = 0; i < input.mix.size (); i++) {
    float inValue = input.mix.get(i)*200;
    line(i, height/2, i, height/2+inValue);
  }

  fft.forward(input.mix);

  for (int i = 0; i < fft.specSize (); i++) {
    float amp = fft.getBand(i); // get amplitude of frequency 
    line(i, height, i, height-amp*100);
  }
}

