xxxxxxxxxx
35
let mic;
let xCurrentPos = 0;
function setup() {
createCanvas(600, 400);
mic = new p5.AudioIn(); // make audio in object
mic.start(); // start the mic
background(255); // draw background once
}
function draw() {
let micLevel = mic.getLevel();
if(xCurrentPos > width){
background(255);
xCurrentPos = 0;
}
noFill();
let strokeRed = 255;
let strokeBlue = 255;
strokeRed = map(micLevel, 0, 1, 0, 255);
stroke(strokeRed, 0, strokeBlue);
const yStart = height;
//const yLineHeight = micLevel * height;
const yLineHeight = map(micLevel, 0, 0.5, 0, height);
const yEnd = yStart - yLineHeight;
line(xCurrentPos, yStart, xCurrentPos, yEnd);
xCurrentPos = xCurrentPos + 1;
}