xxxxxxxxxx
let sound;
let analyzer;
//サウンドファイルをプリロード
function preload() {
sound = loadSound('./beat.wav');
}
function setup() {
createCanvas(windowWidth, windowHeight);
//音量アナライザーを初期化
analyzer = new p5.Amplitude();
//サウンドを音量アナライザーに入力
analyzer.setInput(sound);
}
function draw() {
background(0);
//マウスクリックでサウンドループ再生
if(mouseIsPressed && sound.isPlaying() == false){
sound.loop();
}
//音量のRMS(二乗平均平方根)を計算
var rms = analyzer.getLevel();
fill(31, 127, 255);
noStroke();
//RMSの値を直径にして円を描く Draw an ellipse with size based on volume
ellipse(width / 2, height / 2, rms * width);
}