Skip to content

Instantly share code, notes, and snippets.

@claytical
Created November 3, 2015 14:30
Show Gist options
  • Save claytical/07f877dac8d786df0df5 to your computer and use it in GitHub Desktop.
Save claytical/07f877dac8d786df0df5 to your computer and use it in GitHub Desktop.
p5js using mic input
var mic;
var micOn;
function setup() {
// uncomment this line to make the canvas the full size of the window
createCanvas(windowWidth, windowHeight);
// the volume is a number between 0 and 1
mic = new p5.AudioIn();
micOn = false;
}
function draw() {
// draw stuff here
background(255);
if (micOn) {
var micLevel = mic.getLevel();
var circleSize = map(micLevel, 0, 1, 0, width);
fill(0);
ellipse(width/2, height/2, circleSize, circleSize);
}
}
function mousePressed() {
micOn = !micOn;
if (micOn) {
mic.start();
}
else {
mic.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment