Geometric Animation pulsating to audio mp3 file - audio visualizer

edited November 2017 in Library Questions

I want to pair this animation with an audio mp3 file of a heartbeat. I have imported the file and I know how to make a simple reactive sound wave to the heartbeat but I'm having trouble plugging it into main code here. Would I use a for loop like this?

``for (int i = 0; i< track.bufferSize()-1; i++)

(as I used in my simple soundwave sketch) and if so, where would i put it?

import ddf.minim.*;       //import minim library
AudioPlayer track;        
Minim minim;              //minim class

float t;
float theta, theta2;
int maxFrameCount = 150;
float numRot = 25;
float numOne = 50;
float numTwo = 150;



int a = 49;
int b = 44;


void setup() {
  size(700, 600);
  strokeJoin(ROUND);
  strokeCap(ROUND);
  frameRate(35);
  smooth();

  minim = new Minim(this);                  //minim class
  track = minim.loadFile("heart.mp3");      //import audio file
  track.loop();                             //play audio file on repeat



}

void draw() {
  translate(width/2, height/2);             
  background(255);

  t = (float)frameCount/maxFrameCount;
  theta = TWO_PI*t;                    //angle of rotation for wave1
  theta2 = TWO_PI*t*2;                  //angle of rotation for wave2


for ( int x= -500; x <= 500; x+= 5) {
    float offSet = (x*a); 
    float offSetRot = (x*b); 
    float w1 = map(sin(-theta+offSet), -1, 1, -numOne, numOne);        //wave1 along sine curve
    float w2 = map(cos(-theta2+offSet), -1, 1, -numTwo, numTwo);        //wave2 along cosine curve
    float rotValue = map(sin(-theta+offSetRot), -1, 1, numRot, -numRot);

    noFill();
    stroke(171, 232, 242);        
    strokeWeight(0.5);
    waves(x, 0, w1, w2, rotValue);  //void waves 
}
}


void waves(float xPos, float yPos, float s1, float s2, float rot) {        //code waves of repeating quads
  pushMatrix();
  translate(xPos, yPos);
  rotate(TWO_PI*(rot/300));
  quad(0+numOne, mouseY/3, s2, 0, mouseY/3, mouseY/3, 0, s1);             //(waves are composed of quadrilaterals)
  popMatrix();
}
Tagged:
Sign In or Register to comment.