xxxxxxxxxx
59
/**
* Audio file: 'Rouge' by Raw Stiles
* Creative Commons, BY NC ND
* http://freemusicarchive.org/music/Raw_Stiles/STOP_2X2_04/A2_Raw_Stiles_-_Rouge_1291
*/
let song;
let cnv;
let fft;
let peakDetect;
let pulseSize = 0;
function preload(){
song = loadSound('assets/Raw_Stiles_-_02_-_-smRouge.mp3');
}
function setup() {
createCanvas(400, 400);
textAlign(CENTER, CENTER);
fft = new p5.FFT();
peakDetect = new p5.peakDetect();
noStroke();
fill(0, 255, 0, 200);
}
function draw() {
background(0);
push();
fill(255);
noStroke();
if (song.isPlaying()){
text("Click to pause", width / 2, height / 2);
} else {
text("Click to play", width / 2, height / 2);
}
pop();
fft.analyze();
peakDetect.update(fft);
if (peakDetect.isDetected){
pulseSize = 250;
}
pulseSize = max(pulseSize - 20, 0);
ellipse(width / 2, height / 2, pulseSize);
}
function mousePressed(){
if (song.isPlaying()){
song.pause();
} else {
song.play();
}
}