p5((s) => {
let mic;
let fft;
s.setup = function () {
s.createCanvas(width, height);
mic = new pSound.AudioIn();
mic.start();
fft = new pSound.FFT();
fft.setInput(mic);
};
s.draw = function () {
s.background(255);
s.stroke("blue")
let spectrum = fft.analyze();
for (let n = 0; n < height; n += height / range) {
s.beginShape();
s.curveVertex(0, n);
for (let i = 0; i < width; i += width / range) {
let index = s.floor((i / width) * spectrum.length);
let amp = spectrum[index];
let d = s.dist(i, n, width / 2, n);
let y = n - s.map(amp, 0, 255, 0, width / 2 - d);
s.curveVertex(i, y);
}
s.curveVertex(width, n);
s.curveVertex(width, n);
s.endShape();
}
};
})