xxxxxxxxxx
49
//var mic;
var song;
var button;
var amp;
var volhistory = [];
function toggleSong() {
if (song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
function preload() {
song = loadSound("rnb.mp3");
}
function setup() {
createCanvas(400, 400);
song.play();
button = createButton("toggle");
button.mousePressed(toggleSong);
amp = new p5.Amplitude();
}
function draw() {
background(0);
var vol = amp.getLevel();
console.log(vol);
volhistory.push(vol);
stroke(255);
noFill();
beginShape();
for (var i = 0; i < volhistory.length; i++) {
var y = map(volhistory[i], 0, 1/3, height/2, 0);
vertex(i, y);
}
endShape()
if(volhistory.length > width-50){
volhistory.splice(0,1);
}
stroke(255,0,0);
line(volhistory.length,0, volhistory.length,400)
}