xxxxxxxxxx
28
var theCurrentVolume = 0;
function setup() {
createCanvas(400, 400);
mic = new p5.AudioIn();
mic.start();
}
//----------------------------------------------
function draw() {
background(220);
// Get the overall volume (between 0.0 and 1.0);
// Smooth the volume variable with a running average
let v = mic.getLevel();
let smoothing = 0.9; // must be between 0...1
let A = smoothing;
let B = 1.0-A;
theCurrentVolume = (A * theCurrentVolume) + (B * v);
fill('black');
noStroke();
let diam = map(theCurrentVolume, 0,1, 10,1000);
circle(200, 200, diam);
textSize(24);
text(nf(theCurrentVolume,1,3), 20,30);
}