xxxxxxxxxx
let mySound;
let amplitude;
function preload() {
sound = loadSound('02-My_Fair_Lady-05.mp3');
}
function setup() {
createCanvas(500, 500);
background(100);
sound.setVolume(1);
sound.loop();
amplitude = new p5.Amplitude();
}
function draw() {
background(100, 5);
stroke(255);
noFill();
let amp = map(amplitude.getLevel(), 0, 1, 10, 500);
ellipse(width/2, height/2, amp, amp);
}
function mouseDragged()
{
let v = map(mouseY, 0, height, 1, 0);
sound.setVolume(v);
let p = map(mouseX, 0, width, -1, 1);
sound.pan(p);
}
function mousePressed()
{
if (sound.isPlaying() == false)
sound.loop();
}
function mouseReleased()
{
if (sound.isPlaying() == true)
sound.pause();
}