LightingOrganism_TouchMagnetTable/interfaces.pde

/// abstract class for audio visualization

abstract class AudioRenderer implements AudioListener {
  float[] left;
  float[] right;
  synchronized void samples(float[] samp) { 
    left = samp;
  }
  synchronized void samples(float[] sampL, float[] sampR) { 
    left = sampL; 
    right = sampR;
  }
  abstract void setup();
  abstract void draw();
}


// abstract class for FFT visualization

import ddf.minim.analysis.*;

abstract class FourierRenderer extends AudioRenderer {
  FFT fft; 
  float maxFFT;
  float[] leftFFT;
  float[] rightFFT;
  FourierRenderer(AudioSource source) {
    float gain = .125;
    fft = new FFT(source.bufferSize(), source.sampleRate());
    maxFFT =  source.sampleRate() / source.bufferSize() * gain;
    fft.window(FFT.HAMMING);
  }

  void calc(int bands) {
    if (left != null) {
      leftFFT = new float[bands];
      fft.linAverages(bands);
      fft.forward(left);
      for (int i = 0; i < bands; i++) leftFFT[i] = fft.getAvg(i);
    }
  }
}

