|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Thread-safe YIN pitch detector with lock-free readout. More...
#include <PitchDetector.h>
Public Member Functions | |
| void | prepare (double sampleRate, int windowSize=2048, int hopSize=512) |
| Prepares the detector and allocates internal structures. | |
| void | pushSamples (std::span< const T > samples) noexcept |
| Pushes audio samples into the analysis buffer. | |
| T | getFrequencyHz () const noexcept |
| Returns the detected frequency in Hz safely from any thread. | |
| T | getConfidence () const noexcept |
| Returns the detection confidence [0.0 - 1.0] safely from any thread. | |
| int | getMidiNote () const noexcept |
| Returns nearest MIDI note (69 = A4), or -1 if unvoiced. | |
| T | getCentsOffset () const noexcept |
| Returns cent offset from the nearest MIDI note [-50, +50]. | |
| void | setThreshold (T threshold) noexcept |
| Sets the sensitivity threshold (clamped to 0.01 - 0.5). Lower is stricter. Non-finite values are ignored. | |
| T | getThreshold () const noexcept |
| Returns the sensitivity threshold. | |
| void | reset () noexcept |
| Resets state buffers. Not thread-safe with pushSamples(). | |
Thread-safe YIN pitch detector with lock-free readout.
A non-finite stretch in the input signal simply reads as "unvoiced" (frequency 0, confidence 0) and flushes out of the analysis window on its own: the pipeline holds no recursive state, so the detector self-recovers once clean samples refill the window.
| T | Sample type (float or double). |
Definition at line 53 of file PitchDetector.h.
|
inlinenoexcept |
Returns cent offset from the nearest MIDI note [-50, +50].
Definition at line 166 of file PitchDetector.h.
|
inlinenoexcept |
Returns the detection confidence [0.0 - 1.0] safely from any thread.
Definition at line 152 of file PitchDetector.h.
|
inlinenoexcept |
Returns the detected frequency in Hz safely from any thread.
Definition at line 146 of file PitchDetector.h.
|
inlinenoexcept |
Returns nearest MIDI note (69 = A4), or -1 if unvoiced.
Definition at line 158 of file PitchDetector.h.
|
inlinenoexcept |
Returns the sensitivity threshold.
Definition at line 185 of file PitchDetector.h.
|
inline |
Prepares the detector and allocates internal structures.
Must be called before audio processing begins. Zero allocations happen after this point. Release-safe: a non-finite or non-positive sample rate is ignored (no-op keeping the previous configuration); windowSize is clamped to [64, 1 << 20].
| sampleRate | The system sample rate in Hz. |
| windowSize | Analysis window size in samples (default: 2048). |
| hopSize | Number of samples between detections (overlap). Lower is smoother. |
Definition at line 68 of file PitchDetector.h.
|
inlinenoexcept |
Pushes audio samples into the analysis buffer.
Automatically triggers pitch detection when the hop size is reached. Lock-free and allocation-free. No-op before prepare().
| samples | Span of input audio data (mono). |
Definition at line 119 of file PitchDetector.h.
|
inlinenoexcept |
Resets state buffers. Not thread-safe with pushSamples().
Definition at line 191 of file PitchDetector.h.
|
inlinenoexcept |
Sets the sensitivity threshold (clamped to 0.01 - 0.5). Lower is stricter. Non-finite values are ignored.
Definition at line 178 of file PitchDetector.h.