xxxxxxxxxx
51
// This template was modified from a template created by Lauren Lee McCarthy: https://lauren-mccarthy.com/
// click on the canvas to enable the mic
let mic;
let vol = 0;
function setup() {
createCanvas(600, 600);
}
function draw() {
if (mic) updateVol();
background(200);
console.log("vol is: " + vol);
// map(value, min, max, new min, new max)
// if the min-max is 0 - 10, and new min, new max is 0 - 100
// 3 --> 30
// 8 --> 80
// if the min-max is 0 - 1, and new min, new max is 0 - 20
// .1 --> 2
// .5 --> 10
let eyeS = map(vol, 0, 1, 10, 500);
console.log("eyeS is: " + eyeS);
ellipse(200, height/2, eyeS, eyeS);
// put the code for your drawing here
}
function mousePressed() { // setup audio
mic = new p5.AudioIn();
mic.start();
userStartAudio();
}
function updateVol() {
// get the overall volume (between 0 and 1)
let v = mic.getLevel();
// "smooth" the volume variable with an easing function
vol += (v-vol)/3;
}