SF syn.fun
← snippets SNIPPET JS

fftToBands

Bucket a raw FFT array into a few stable, normalized bands you can actually use.

#audio-reactive#fft#utility

Snippets are where setup and explanation matter as much as the code itself.

export function fftToBands(values, bandCount) {
  const size = Math.max(1, Math.floor(values.length / bandCount));

  return Array.from({ length: bandCount }, (_, index) => {
    const start = index * size;
    const slice = values.slice(start, start + size);
    const average = slice.reduce((sum, value) => sum + value, 0) / Math.max(1, slice.length);
    return average / 255;
  });
}
{
  "bands": 8,
  "smoothing": 0.88
}
submitted by
@Frost.byte_
author
community remix
source
Submitted directly
license
Mixed provenance; keep attribution notes with the snippet
Related · #audio-reactive