import ddf.minim.analysis.*;
import ddf.minim.*;
// Declare and construct three objects
Minim minim;
AudioPlayer test;
FFT fft;
void setup() {
size(1280, 720);
// Draws all geometry with smooth (anti-aliased) edges at level two
smooth(2);
// Initialize the objects
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.
test = minim.loadFile("final.mp3", 1024);
// Create an FFT object that has a time-domain buffer
// the same size as test'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(test.bufferSize(), test.sampleRate());
// Play the song
test.play();
}
void draw() {
// Clean the background in order to present new patterns
background(0);
// Perform a forward FFT on the samples in test's mix buffer,
// which contains the mix of both the left and right channels of the file
fft.forward(test.mix);
// Set center of screen as initial point
translate(width / 2, height / 2);
// Set the transparency of stroke according to the amplitude of the requested frequency band i in spectrum size
float alpha = map(fft.getBand(7), 0, 100, 100, 255);
stroke(255, alpha);
noFill();
// Draw rectangles according to the amplitude of the requested frequency band i in spectrum size
// It is drawn in a polar coordinate system
for (int i = 0; i < fft.specSize(); i++) {
float angle = map(fft.getBand(i), 0, 100, 0, 360);
float r = fft.getBand(i);
float x = r *cos(angle);
float y = r *sin(angle);
rect(x, y, fft.getBand(i), fft.getBand(i));
}
}