Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

create a line using an audio sample

$
0
0

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

Viewing all articles
Browse latest Browse all 2896

Trending Articles