xxxxxxxxxx
83
var cnv, soundFile, fft, peakDetect;
var ellipseWidth = 10;
var h_ellipseWidth = -10;
function preload() {
soundFile = loadSound('assets/Wavess_solo.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
noStroke();
fill(255);
textAlign(CENTER);
angleMode(DEGREES);
// p5.PeakDetect requires a p5.FFT
//BBT = new p5.FFT();
fft = new p5.FFT();
peakDetect = new p5.PeakDetect(100, 200, .1);
h_peakDetect = new p5.PeakDetect(1500, 2500, .4);
}
function draw() {
background(0);
text('click to play/pause', width / 2, height / 2);
// peakDetect accepts an fft post-analysis
fft.analyze();
peakDetect.update(fft);
// BBT.analyze();
h_peakDetect.update(fft);
if ( h_peakDetect.isDetected ) {
h_ellipseWidth = 180;
} else {
h_ellipseWidth *= .95;
}
fill(255,0,0);
arc(windowWidth/2,windowHeight/2 , 400, 400, 180, h_ellipseWidth, PI);
if (peakDetect.isDetected) {
ellipseWidth = 360;
} else {
ellipseWidth *= .95;
}
fill(255);
arc(windowWidth / 2, windowHeight / 2, 400, 400, 180, ellipseWidth);
}
//I TRIED
// toggle play/stop when canvas is clicked
function mouseClicked() {
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
if (soundFile.isPlaying()) {
soundFile.pause();
} else {
soundFile.play();
}
}
}