Minim - song starts a second late and is choppy on start

edited November 2014 in Library Questions

Howdy,

I am using the minim library to do a basic visualization, but the audio is coming in a second late. What I'm assuming is happening is that when I press "Run", the sketch loads the data, starting with the audio, then the visualizing info, then actually plays the audio - so the first notes I hear are actually (roughly) 1 second into the actual song. And, the first half second or so, it is choppy/sounds a little laggy...I've increased buffer size, maybe I need to do so more?

Here's the code:

/* Found from
/r/processing/comments/2iw0bw/cool_music_visualizer_try_it_yourself/
*/

import ddf.minim.*;
int colorwheel = 0;

Minim minim;
AudioPlayer player;
int liney;

void setup()
{
  frameRate(40);
  size(600,400, P3D);
//  selectInput("Select song:", "fileSelected");
  minim = new Minim(this);
  player = minim.loadFile("Audio.mp3",2048);
  println(player.bufferSize());
  player.play();
  loop();
//  noLoop();
liney = height/2;
}

void draw()
{
  background(0);
  colorMode(HSB);
  colorwheel++;
  colorwheel=colorwheel%255;
  stroke(colorwheel,255,255);

  rectMode(CORNERS);

  for(int k = 0; k<player.bufferSize(); k++){
    double heightleft = player.left.get(k);
    double heightright = player.right.get(k);
    line(k,liney+(int)(heightleft*liney),liney/2,k,liney,0);
    line(k,liney,0,k,liney+(int)(-1*heightright*liney),liney/2);
  }
}

void fileSelected(File selection){
  if(selection == null){
    selectInput("Select song:","fileSelected");
  }else{
    filename = selection.toString();
    print(filename);
    player.close();
    player = minim.loadFile(filename);
    player.play();
    loop();
  }
}

Any ideas on what may be causing this? Thanks for any advice!

Tagged:
Sign In or Register to comment.