|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Causal SuperFlux onset detector with a Boeck-2012 adaptive peak picker. More...
#include "../Core/DspMath.h"#include "../Core/FFT.h"#include "../Core/WindowFunctions.h"#include "../Core/AudioBuffer.h"#include "../Core/AudioSpec.h"#include <algorithm>#include <atomic>#include <cmath>#include <cstddef>#include <cstdint>#include <memory>#include <span>#include <vector>

Go to the source code of this file.
Classes | |
| class | dspark::OnsetDetector< T > |
| Causal SuperFlux onset detector with lock-free readout. More... | |
Namespaces | |
| namespace | dspark |
| Main namespace for the DSPark framework. | |
Causal SuperFlux onset detector with a Boeck-2012 adaptive peak picker.
Implements the SuperFlux onset-detection function (Boeck & Widmer, DAFx-13): a log-frequency triangular filterbank magnitude spectrogram, a frequency maximum filter that suppresses vibrato/tremolo false positives, and a half-wave-rectified spectral flux to the mu-th previous frame. The onset strength envelope (ODF) is peak-picked with the online-capable rule of Boeck, Krebs & Schedl (ISMIR 2012) – the same recipe used by librosa.util.peak_pick. Two simpler ODFs are also provided: plain SpectralFlux and a rectified ComplexDomain function (Dixon, DAFx-06).
The STFT front-end is built directly on FFTReal + WindowFunctions with a mirrored analysis ring (the same technique as PitchDetector), which gives exact, block-size-independent control over frame timing – a precondition for the deterministic latency contract below. It is the shared onset front-end consumed by BeatTracker (ADR-009).
Latency (ONE definition, D-2). Frame N (default 2048, Hann), hop = round(fs/200) (221 samples at 44.1 kHz, 240 at 48 kHz; ~5 ms). The detector reports every onset at a single fixed causal reporting latency
L = fftSize + hop (getLatencySamples()).
At 44.1 kHz with the defaults this is 2048 + 221 = 2269 samples (~51.4 ms; 2048 + 240 = 2288 at 48 kHz). The onsetDetected() latch asserts exactly L samples after the onset's reference sample (the analysis-frame centre that localises the transient). Detection completes internally earlier (~fftSize/2 + hop); events are held and released at the fixed offset L so a caller sees one deterministic, block-size-independent latency regardless of where in a frame the onset falls (see OA-6). The adaptive threshold's pre_avg look-back (100 ms) is a backward-looking warm-up, NOT part of L: it is history the moving mean needs before its first valid decision and adds zero per-onset reporting latency.
Picker defaults (D-2): pre_max = post_max = 30 ms, pre_avg = 100 ms, post_avg = 70 ms (offline only), combination width = 30 ms. In the causal streaming path post_avg = 0 and post_max is one hop – the single-frame confirmation that a candidate is a maximum, which is exactly the +hop term of L. detectOffline() uses the symmetric (post_* > 0) picker.
Threading:
Embedded/wasm: compiles under -fno-exceptions -fno-rtti (no throw on any path); no file I/O, so it is unaffected by DSPARK_NO_FILE_IO.
Dependencies: DspMath.h, FFT.h, WindowFunctions.h, AudioBuffer.h, AudioSpec.h.
Definition in file OnsetDetector.h.