← All examples

03 Canvas 2D · Intermediate

Draw the whole spectrum.

Go beyond three values. Map raw frequency bins to a detailed, real-time spectrum.

bass
0.00
mid
0.00
high
0.00

What you’ll learn

Normalize FFT bytes from 0–255 and draw them in a canvas animation loop.

The complete setup, with playback and cleanup →

Download the working example component ↓

The key idea · excerpt
const { fft } = audio.snapshot();
if (fft) {
  ctx.clearRect(0, 0, width, height);
  const step = width / fft.length;
  fft.forEach((value, i) => {
    const bar = (value / 255) * height;
    ctx.fillRect(i * step, height - bar, step - 1, bar);
  });
}

Music: I dunno by grapes · Drive by AlexBeroza · Parametaphoriquement by gmz · nightWalk by airtone. From ccMixter, under CC BY 3.0.