top of page

import ddf.minim.analysis.*;

import ddf.minim.*;

 

// Declare and construct three objects

Minim minim;

AudioPlayer test;

FFT fft;

 

// Declare two global variables as constant according to the equation

float d = 8;

float n = 5;

 

void setup() {

  size(1280, 720);

 

  // Draws all geometry with smooth (anti-aliased) edges at level two

  smooth(2);

 

  // Initialize the object

  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);

 

  // Assign the values accoring to the equation

  // Re-maps the variables according to the amplitude of the requested frequency band 7

  float d = map(fft.getBand(7), 0, 100, 1, 7);

  float n = map(fft.getBand(7), 0, 100, 1, 9);

  float k = n / d;

 

  // 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, 180, 255);

  

  stroke(255, alpha);

  noFill();

 

  // Draw patterns as points and connect them togather

  beginShape();

 

  for (float a = HALF_PI; a < TWO_PI * d; a += 0.05) {

 

    // Re-maps the diameter according to the amplitude of the requested frequency band 7

    float w = map(fft.getBand(7), 0, 100, 8, 15);

 

    // It is drawn in a polar coordinate system

    float r = w * 200 * cos(k * a);

    float x = r * cos(a);

    float y = r * sin(a);

 

    // It is better to use vertex to connect to each other

    vertex(x, y);

 

    // Draw ellipse on each point

    ellipse(x, y, 2, 2);

  }

  endShape();

}

bottom of page