Skip to content

spectrum

diapason.desktop.spectrum

Turn a block of microphone audio into a handful of band energies.

The dictation indicator used to receive one number — the RMS level — which is enough to make a field breathe but not enough to make it behave like an equaliser: a single number cannot say where in the spectrum the energy is, so every part of the display can only ever move together.

This computes that missing information. It is deliberately small and pure: no audio device, no state, no callbacks, so the band layout can be tested without a microphone.

BandSmoother

Holds the previous frame so the bands rise fast and fall slowly.

Raw per-block energies flicker at the block rate, which reads as noise rather than as a voice. Kept separate from the analysis so the maths above stays pure.

band_edges(bands=DEFAULT_BANDS)

Band boundaries in Hz, spaced logarithmically.

Linear spacing would give almost every band to the top octaves, where speech has least to say — the display would look busy at the right and dead at the left. Log spacing matches how pitch is actually heard.

band_energies(samples, sample_rate, *, bands=DEFAULT_BANDS)

Energy per band, 0–1, from a mono block.

Returns all zeros for anything unusable — a block too short to resolve the lowest band tells us nothing, and inventing values would make the display move for no reason.

scaled_by_level(bands, level)

Scale per-block bands by overall loudness.

Band energies are normalised within their own block, so silence and a shout produce the same shape. Multiplying by the level is what makes the display fall quiet when the room is quiet — the shape says what is being said, the level says how loudly.