Skip to main content

Module dsp

Module dsp 

Source
Expand description

Deterministic analysis of the PCM stream: windowed FFT spectrum plus an onset envelope and beat flag, delivered once per hop as an AnalysisFrame.

Everything here is a pure function of the samples fed in — no wall clock, no unseeded randomness (NFR section 6). Window and hop sizes fit the 60 ms latency budget at 48 kHz: one hop is ~10.7 ms (NFR section 3).

Two FFT windows feed one band axis (ADR-0049): WINDOW_SIZE carries everything it can resolve — including all of onset, beat and tempo, so the transient path keeps its speed — and LOW_WINDOW_SIZE carries the bands below the crossover, which a 23 kHz-wide bin cannot. See fft::BandLayout.

Modules§

bands
Band-energy split: fixed Hz cutoffs over the linear FFT magnitudes into three mean energies — bass, mid, treble — for scenes and presets.
downbeat
Downbeat estimation: which beat is beat 1 (ADR-0050 Layer 2).
fft
Windowed FFT producing linear magnitudes plus a log-frequency band spectrum for scenes.
gain
Running normalization: turns raw magnitudes into “loud relative to this track’s recent past” (ADR-0049).
grid
The bar-scale grid Layer 2 folds over (ADR-0109, Plan 0095 Phase 3).
novelty
Long-window spectral novelty for experimental track-change detection (Plan 0009 Phase 4). Feeds the standalone’s scene director a nudge: a large spectral shift (a new track / section with a different frequency distribution) raises the novelty score, and the director lets that pull scene rotation earlier — but never triggers a change on novelty alone, since beatmatched DJ blends have no hard edge (NFR section 10).
onset
Onset envelope (spectral flux) and beat flagging with an adaptive threshold. Deterministic: state depends only on the magnitude sequence.
tempo
Deterministic tempo (BPM) and beat-phase (bar) from the onset envelope.

Structs§

AnalysisFrame
One hop’s worth of analysis.
Analyzer
Stateful per-stream analyzer: accumulates interleaved samples into mono hops, runs FFT + onset detection each completed hop, and hands the latest frame to the render side. Deterministic for a given sample sequence.

Constants§

HOP_SIZE
Samples between successive analysis hops (~10.7 ms at 48 kHz).
LOW_WINDOW_SIZE
Second, longer FFT window feeding the bands below the crossover (~171 ms at 48 kHz). Chosen by measurement in Plan 0048 Phase 1 against one rule — 4096 first, 8192 only if 4096 still leaves sub-bass bands bin-starved. Of the 20 bands below the crossover, 4096 leaves all 20 still one bin wide and 8192 leaves 8, pulling the unresolved boundary down from 246 Hz to 76 Hz. See fft::BandLayout and ADR-0049; the_long_window_was_chosen_by_measurement pins all three candidates.
SPECTRUM_BINS
Log-frequency bands exposed to scenes.
WARMUP_HOPS
Hops the analyzer consumes before it publishes its first frame — the time the longer window takes to fill (~171 ms at 48 kHz).
WAVE_SAMPLES
How many time-domain samples an AnalysisFrame carries in waveform.
WINDOW_SIZE
FFT window length in samples (~43 ms at 48 kHz).