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);
// Load the song
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, 50, 255);
stroke(255, alpha);
noFill();
// Set ellipseMode to RADIUS
ellipseMode(RADIUS);
// Draw ellipses and lines 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 r = fft.getFreq(i);
float angle = map(i, 0, fft.specSize(), 0, 360);
float x = r * cos(angle);
float y = r * sin(angle);
line(0, 0, x * 2, y * 2);
ellipse(0, 0, fft.getBand(i)*8, fft.getBand(i)*8);
}
}