xxxxxxxxxx
let freqs;
function preload() {
sound = loadSound('right.MP3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
fft = new p5.FFT();
sound.amp(1);
setData();
background(0);
noStroke();
setTimeout(start, 1000);
}
function draw() {
background(0, 5);
noStroke();
strokeWeight(1);
noFill();
rect(0.1 * width, 0.1 * height, 0.8 * width, 0.8 * height, 0.05 * height);
strokeWeight(2);
let spectrum = fft.analyze();
let x = 0.11 * width;
let span = (0.78 * width / (freqs.length - 1));
for (let i = 0; i < freqs.length - 1; i += 1) {
let y = 0.8 * height;
let e = fft.getEnergy(freqs[i], freqs[i + 1]);
if (e > 50) y = map(e, 50, 255, 0.8 * height, 0.1*height);
stroke(15 +(2 * e));
line(x, y, x + span, y);
//line(x+span/2, 0.8*height, x+span/2, y);
x += span;
}
noStroke();
}
function start() {
sound.play();
}
function mousePressed() {
if (sound.isPlaying() && frameCount > 100) {
sound.pause();
} else if (frameCount > 100) {
sound.play();
}
}