Hello,
I am trying to write a code that will use a song's frequency to change the color of a line that moves across the campus to create some sort of abstract picture. Currently, I am stumped on how to achieve this effect. If anyone has any advice on how to do this, it would be much appreciated.
This is my code currently (which probably has a great amount of errors in it; I'm still new to processing):
import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; float k; float r; float g; float b;
Minim minim; AudioPlayer player; FFT fft;
void setup() { size( 800, 600 );
minim = new Minim( this );
player = minim.loadFile("Little Secrets.mp3");
player.play();
fft = new FFT( player.bufferSize(), player.sampleRate() );
}
void draw() {
float x = map( player.position(), 0, player.length(), 0, width );
float e = 0;
for ( int i = 0; i < fft.specSize(); i++ ) {
e += abs( fft.getBand( i ) ) / 1000;
}
{ int k = color(r-e,g/e,b+e); float r = red(pixels[k]); float g = green(pixels[k]); float b = blue(pixels[k]);
}
stroke( color(r-e, g/e, b+e) );
strokeWeight (5);
line( x, 0, x, height );
}
void stop() { player.close(); minim.stop(); super.stop(); }