LCCMX_Audio/LibreriasAudioProcessing/Minim/Extras/AudioReactiveParticles/AudioReactiveParticles.pde
import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer player;
FFT fft;

Particle [] particles;

boolean fade = false;

void setup() {
  size(640, 480);
  smooth();
  minim = new Minim(this);
  player = minim.loadFile("05.mp3", 1024);
  player.loop();

  fft = new FFT(player.bufferSize(), player.sampleRate());

  particles = new Particle[fft.specSize()];
  for (int i = 0; i < fft.specSize(); i++) {
    particles[i] = new Particle(i);
  }
}

void draw() {
  pushStyle();
  colorMode(RGB, 255);
  if (fade) {
    noStroke();
    fill(0, 8);
    rect(0, 0, width, height);
  } else {
    background(0);
  }
  popStyle();

  fft.forward(player.mix);
  for (int i = 0; i < fft.specSize()-1; i++) {
    particles[i].update(fft.getBand(i), player.mix.get(i*2));
    particles[i].render();
  }
}

void keyPressed() {
  if (key == 'f') {
    fade = !fade;
  }
}


void stop() {
  player.close();
  minim.stop();
  super.stop();
}
