DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
PitchDetector.h File Reference

Real-time monophonic pitch detection using the YIN algorithm. More...

#include "../Core/DspMath.h"
#include "../Core/FFT.h"
#include <algorithm>
#include <atomic>
#include <cmath>
#include <cstddef>
#include <memory>
#include <span>
#include <vector>
Include dependency graph for PitchDetector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::PitchDetector< T >
 Thread-safe YIN pitch detector with lock-free readout. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Real-time monophonic pitch detection using the YIN algorithm.

Implements the YIN autocorrelation method (de Cheveigne & Kawahara, 2002) with the difference function computed as a frequency-domain cross-correlation (YIN-FFT, 3 FFTs per detection). A mirrored input buffer keeps every analysis window fully contiguous in memory.

Threading:

  • prepare(): setup thread (allocates; not concurrent with pushSamples()).
  • pushSamples() / reset(): audio thread (stream owner); reset() is not thread-safe with pushSamples().
  • getFrequencyHz() / getConfidence() / getMidiNote() / getCentsOffset(): any thread, lock-free. Frequency and confidence are published as two independent atomics, so a reader may pair a fresh frequency with the previous confidence for one detection (benign for tracking/metering).
  • setThreshold(): any thread (atomic; non-finite values are ignored).

Dependencies: DspMath.h, FFT.h.

Definition in file PitchDetector.h.