xxxxxxxxxx
40
let mic;
let currentXPos = 0;
function setup() {
createCanvas(600, 400);
// https://p5js.org/reference/#/p5.AudioIn
mic = new p5.AudioIn();
mic.start();
background(100);
}
function draw() {
//background(100);
// sound level from 0 to 1
let micLevel = mic.getLevel();
stroke(255);
strokeWeight(10);
const yStart = height;
const yLineHeight = micLevel * height;
const yEnd = yStart - yLineHeight;
line(currentXPos, yStart, currentXPos, yEnd);
currentXPos++;
if(currentXPos > width){
background(255, 0, 0);
currentXPos = 0;
}
}