xxxxxxxxxx
let sound;
let analyzer;
function preload() {
sound = loadSound("./beat.wav");
}
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(0);
if (mouseIsPressed) {
if (sound.isPlaying() == false) {
sound.loop();
analyzer = new p5.Amplitude();
analyzer.setInput(sound);
}
var rms = analyzer.getLevel();
fill(31, 127, 255);
noStroke();
let diameter = map(rms, 0, 1, 10, width);
circle(width / 2, height / 2, diameter);
} else {
sound.stop();
}
}