SonicFrame v1.3.2

Spectrogram

A picture of time and frequency: low sounds at the bottom, high at the top, loud in bright colors. It is computed in the browser with a dependency-free FFT, in slices, so the page never freezes.

Adding it

import { spectrogram } from 'sonicframe';

frame.use(spectrogram({ source: '/voice.mp3', map: 'magma' }));

// On the player, in the palette's colors:
createPlayer({ container, src, spectrogram: true });

Like the peaks, it is computed only once the frame comes near the screen. The sound is decoded once; a function given as source lets the app share one decode between plugins.

Options

Option Default What it does
source An address or blob to decode, or a function that gives decoded audio.
samples Ready-made mono samples (skips decoding).
sampleRate 44100 The sample rate of samples, per second.
map 'magma' viridis, magma, gray, ice, fire, ocean, or your own { from, via, to }.
fftSize Window size, a power of two from 32 to 32,768 (1024 by default).
columns, rows The picture's size in time and frequency: 512 × 256 by default, up to 16,384 × 4096.
minDb, maxDb Decibels mapped to the quietest and the brightest color.
scale 'linear' or 'log' (rows spread over octaves).
detail false Zoomed in, a sharp picture of the part in view once the view rests.
detailDelay, detailColumns 200, the width How long the view rests first (ms), and the sharp picture's columns (at most 4096).

Your own map colors take any CSS color or var(--name, fallback), so a palette works; after refresh(), the picture is repainted in the new colors without computing again.