create a line using an audio sample

I'm trying to create a lineal drawing using the sound information from an audio sample or the computer internal mic. I did this script but I'm just getting a straight line. Any ideas?

thanks!

import ddf.minim.*;

Minim minim;
AudioInput in;

float x;
float y;
float px;
float py;
float vel; 
float dir; 

void setup(){
  size(400,400);
  stroke(0);
  background(255);
  smooth();
  frameRate(30);

  x=y=px=py=200;


  vel = random(5);  
  dir = random(360);  

  minim = new Minim(this);

  in = minim.getLineIn();
}

void draw(){
  px = x;
  py = y;

  x += cos(radians(dir)) * vel;
  y += sin(radians(dir)) * vel;

  stroke(0);
  line(px,py,x,y);

  float value = 0;

  for(int i = 0; i < in.bufferSize() - 1; i++) {
      value += in.mix.get(i);      
  }
  value /= in.bufferSize();
  dir += random(-30, 30) * value ;
}

void stop() {
  minim.stop();
  super.stop();
}
Tagged:

Answers

  • If the line is straight then dir is probably 0 in line 47 which probably means value is zero. Add debug println before and after line 46.

    And try it with a sample, not just linein

Sign In or Register to comment.