xxxxxxxxxx
54
let mic;
let song;
let button;
let amp;
let volhistory = [];
function playSong() {
if (song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
function preload() {
song = loadSound("peaches.mp3");
}
function setup() {
createCanvas(300, 300);
button = createButton("go/stop");
button.mousePressed(playSong);
song.play();
amp = new p5.Amplitude();
// mic = new p5.AudioIn();
//mic.start();
}
function draw() {
background(0);
let vol = amp.getLevel();
volhistory.push(vol);
console.log(vol);
stroke(255);
noFill();
beginShape();
for (let i = 0; i < volhistory.length; i++) {
let y = map(volhistory[i], 0, 1, height / 2, 0);
vertex(i, y);
}
endShape();
if (volhistory.length > width) {
volhistory.splice(0, 1);
}
stroke(255, 0, 0);
line(volhistory.length, 0, width, 1);
//ellipse(100, 100, 300, vol * 2000);
}