|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Gated, octave-safe, semitone-smoothed pitch tracking source. More...
#include <PitchFollower.h>
Classes | |
| struct | TrackPoint |
| One detection of an offline pitch track (see track()). More... | |
| struct | TrackSettings |
| Settings of track(). More... | |
Public Member Functions | |
| PitchFollower () noexcept | |
| Creates a follower with the detector's noise suppression off. | |
| void | prepare (const AudioSpec &spec, int windowSize=0) |
| Prepares the follower and the wrapped detector. | |
| void | reset () noexcept |
| Forgets the tracked pitch (parameters are kept). Allocation-free; call from the stream owner (it touches the same plain tracking state update() writes). | |
| void | setRange (T minHz, T maxHz) noexcept |
| Accepted pitch range in Hz (default 60 to 1200). Non-finite values are ignored (the old max() passed NaN through and closed the validity gate forever). | |
| void | setConfidence (T threshold) noexcept |
| Confidence threshold [0, 1] below which readings are ignored (default 0.85). | |
| void | setGlide (T msPerOctave) noexcept |
| Glide time in milliseconds per octave (default 60). 0 disables smoothing (the output snaps to each accepted reading). Non-finite values are ignored. | |
| T | getMinHz () const noexcept |
| Returns the lower bound of the accepted pitch range in Hz. | |
| T | getMaxHz () const noexcept |
| Returns the upper bound of the accepted pitch range in Hz. | |
| T | getConfidenceThreshold () const noexcept |
| Returns the confidence gating threshold [0, 1]. | |
| T | getGlide () const noexcept |
| Returns the glide time in milliseconds per octave. | |
| int | getWindowSize () const noexcept |
| void | setNoiseSuppression (bool on) noexcept |
| Reads tones through broadband noise (opt-in, default off): the wrapped detector's PitchDetector::setNoiseSuppression(). | |
| bool | getNoiseSuppression () const noexcept |
| Whether the detector's noise suppression is on. | |
| T | getSmoothedHz () const noexcept |
| T | getRawHz () const noexcept |
| T | getConfidence () const noexcept |
| bool | isTracking () const noexcept |
| bool | isVoiced () const noexcept |
| void | processBlock (AudioBufferView< const T > buffer) noexcept |
| Feeds a block (any channel count); channels are averaged to mono. | |
| void | pushSamples (std::span< const T > samples) noexcept |
| Feeds mono samples directly (alternative to processBlock). | |
Static Public Member Functions | |
| static std::vector< TrackPoint > | track (std::span< const T > mono, double sampleRate, const TrackSettings &settings) |
| Offline: reads a whole mono signal and decodes its pitch track over the complete sequence of detections. | |
| static std::vector< TrackPoint > | track (std::span< const T > mono, double sampleRate) |
| track() with the default settings (60 to 1200 Hz, noise suppression on, automatic window). | |
Gated, octave-safe, semitone-smoothed pitch tracking source.
| T | Sample type (float or double). |
Definition at line 101 of file PitchFollower.h.
|
inlinenoexcept |
Creates a follower with the detector's noise suppression off.
The follower gates readings at a confidence of 0.85 by default, which a reading taken through noise never reaches (about 0.5 at 0 dB SNR), so the detector's second reading would be paid for and discarded. Turn it on together with a lower confidence (setNoiseSuppression(), setConfidence()) to follow a note through noise.
Definition at line 115 of file PitchFollower.h.
|
inlinenoexcept |
Definition at line 256 of file PitchFollower.h.
|
inlinenoexcept |
Returns the confidence gating threshold [0, 1].
Definition at line 219 of file PitchFollower.h.
|
inlinenoexcept |
Returns the glide time in milliseconds per octave.
Definition at line 222 of file PitchFollower.h.
|
inlinenoexcept |
Returns the upper bound of the accepted pitch range in Hz.
Definition at line 216 of file PitchFollower.h.
|
inlinenoexcept |
Returns the lower bound of the accepted pitch range in Hz.
Definition at line 213 of file PitchFollower.h.
|
inlinenoexcept |
Whether the detector's noise suppression is on.
Definition at line 242 of file PitchFollower.h.
|
inlinenoexcept |
Definition at line 253 of file PitchFollower.h.
|
inlinenoexcept |
Definition at line 247 of file PitchFollower.h.
|
inlinenoexcept |
Definition at line 228 of file PitchFollower.h.
|
inlinenoexcept |
Definition at line 259 of file PitchFollower.h.
|
inlinenoexcept |
Definition at line 269 of file PitchFollower.h.
|
inline |
Prepares the follower and the wrapped detector.
An invalid spec (non-finite or non-positive fields) is ignored, keeping the previous state.
| spec | Audio environment specification. |
| windowSize | Detector analysis window. Values <= 0 (the default) select PitchDetector's AUTOMATIC window: 2048 at 44.1/48 kHz, 4096 at 88.2/96 kHz, 8192 at 176.4/192 kHz. Explicit positive values are forwarded as given (with a hop of windowSize/4). |
The tracked register is the detector's: the lowest reachable fundamental is sampleRate/(windowSize/2 - 1), so it depends on the RATIO, never on the count. The automatic window is good down to ~47 Hz at every rate from 44.1 to 192 kHz. A fixed 2048-sample window would instead stop at ~94 Hz at 96 kHz and ~188 Hz at 192 kHz: measured, a 55 Hz or 82 Hz sawtooth then never leaves getSmoothedHz() at 0 and isTracking() stays false, whatever setRange() says – the range gate cannot widen a register the detector cannot reach. For a lower floor pass an explicit window (doubling it halves the floor and doubles the analysis latency).
Definition at line 140 of file PitchFollower.h.
|
inlinenoexcept |
Feeds a block (any channel count); channels are averaged to mono.
| buffer | Read-only audio block. |
Definition at line 280 of file PitchFollower.h.
|
inlinenoexcept |
Feeds mono samples directly (alternative to processBlock).
| samples | Mono audio span. |
Definition at line 316 of file PitchFollower.h.
|
inlinenoexcept |
Forgets the tracked pitch (parameters are kept). Allocation-free; call from the stream owner (it touches the same plain tracking state update() writes).
Definition at line 157 of file PitchFollower.h.
|
inlinenoexcept |
Confidence threshold [0, 1] below which readings are ignored (default 0.85).
The default accepts the clean readings only. The detector reads a tone in noise at its honest, lower confidence (about 0.76 at 5 dB SNR): a gate of 0.7 follows such a tone (measured: a 220 Hz tone at 5 dB SNR tracked 100% of the time, within 15 cents), where 0.85 holds the last clean pitch.
Definition at line 195 of file PitchFollower.h.
|
inlinenoexcept |
Glide time in milliseconds per octave (default 60). 0 disables smoothing (the output snaps to each accepted reading). Non-finite values are ignored.
Definition at line 206 of file PitchFollower.h.
|
inlinenoexcept |
Reads tones through broadband noise (opt-in, default off): the wrapped detector's PitchDetector::setNoiseSuppression().
Those readings carry the honest, low confidence of a reading taken through the noise (about 0.5 at 0 dB SNR), so the confidence gate (setConfidence()) must be lowered for the follower to use them. Control thread; relaxed atomic.
Definition at line 239 of file PitchFollower.h.
|
inlinenoexcept |
Accepted pitch range in Hz (default 60 to 1200). Non-finite values are ignored (the old max() passed NaN through and closed the validity gate forever).
Definition at line 177 of file PitchFollower.h.
|
inlinestatic |
track() with the default settings (60 to 1200 Hz, noise suppression on, automatic window).
| mono | Mono samples of the whole signal. |
| sampleRate | Sample rate in Hz. |
Definition at line 447 of file PitchFollower.h.
|
inlinestatic |
Offline: reads a whole mono signal and decodes its pitch track over the complete sequence of detections.
The follower judges every detection with the past alone, so a note change costs it a detection of confirmation, an octave error can only be folded towards what came before, and a detection the detector declines stays empty. With the whole sequence known, every detection offers its own reading, the octaves of it, the readings of the three detections on each side and the line between them, and the track is the cheapest path through those and "unvoiced" (a Viterbi decode): a pitch change costs its size up to six semitones, another octave of a reading or a neighbour's pitch a fixed amount, and entering or leaving a note more than filling a gap of a few detections. The detection before a note's first reading joins the note: the detector does not read a window until the note fills it.
Measured at 48 kHz on the material of the class description, against the follower at its best settings there and against the HMM note tracker decoded over the whole file (Viterbi). Frames within 50 cents (RPA) / overall accuracy (voicing and pitch right) / voicing false alarms: clean legato 95.2 / 95.3 / 2.4% (follower 93.7 / 94.2 / 1.9, HMM 94.2 / 94.3 / 5.1); 100 cents of vibrato 95.7 / 95.7 / 4.0 (94.6 / 94.8 / 2.9, HMM 95.0 / 94.7 / 5.6); 5 dB SNR white noise 96.7 / 96.3 / 0.0 (93.8 / 94.1 / 0.0, HMM 95.1 / 94.8 / 4.7); 5 dB pink noise 96.3 / 95.9 / 0.0 (93.3 / 92.9 / 0.0, HMM 95.1 / 95.1 / 4.3); 0 dB white noise 92.3 / 91.6 / 1.6 (86.2 / 87.3 / 0.0, HMM none); tones with a fundamental 15 dB below their partials 100 / 99.5 / 0.6 (97.8 / 98.0 / 0.6, HMM 99.8 / 98.4 / 6.9). Octave errors: at most 0.2% of voiced frames (follower up to 0.9%).
Not real-time: it allocates (the result, one detector and about 200 bytes per detection for the decode) and runs on the calling thread. Any thread; it shares no state with a follower instance.
| mono | Mono samples of the whole signal. |
| sampleRate | Sample rate in Hz. |
| settings | Range, noise suppression and analysis window. |
Definition at line 399 of file PitchFollower.h.