xxxxxxxxxx
51
// var mic;
var song;
var button;
var amp;
var volhistory=[];
function preload(){
song=loadSound("thisdot.mp3");
}
function setup() {
createCanvas(300,300);
button=createButton('toggle');
button.mousePressed(toggleSong);
song.play();
amp= new p5.Amplitude();
// mic=new p5.AudioIn();
// mic.start();
}
function draw() {
background(100);
// vol=mic.getLevel();
// diam=map(vol,0,1,1,3900);
var vol=amp.getLevel();
volhistory.push(vol);
stroke(255);
noFill();
beginShape();
for(var i=0;i<volhistory.length;i++){
var y=map(volhistory[i],0,1,height/2,1);
vertex(i,y);
}
endShape();
if (volhistory.length>width){
volhistory.splice(0,1);
}
}
stroke(255,0,0);
line(width,0,width1)
function toggleSong(){
if(song.isPlaying()){
song.pause();
}else{
song.play();
}
}