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

Musical pitch tracker: PitchDetector + the logic that makes it usable. More...

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

Go to the source code of this file.

Classes

class  dspark::PitchFollower< T >
 Gated, octave-safe, semitone-smoothed pitch tracking source. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Musical pitch tracker: PitchDetector + the logic that makes it usable.

A raw pitch detector is not directly usable as a modulation source: it reports octave errors on transients, garbage with high confidence during noise bursts, and jumps that would make any controlled parameter zipper. PitchFollower wraps Analysis/PitchDetector.h with the control logic every pitch-driven effect needs:

  • Confidence gating - readings below the confidence threshold (or outside the configured frequency range) never move the output; the last reliable pitch is held through consonants and silence.
  • Octave-jump correction - a reading ~1-2 octaves away from the tracked pitch is folded back to the closest octave of the current target before being considered (the classic YIN 2x/0.5x failure on transients).
  • Jump confirmation - a genuinely large interval must persist for three consecutive readings before the target moves (one bad frame never jerks the output).
  • Glide in semitone domain - the public value slews toward the target at a constant rate expressed in milliseconds per octave, so the movement is musically uniform across the whole range (Hz-domain smoothing is faster at high pitches and sluggish at low ones).

Threading:

  • prepare(): setup thread (allocates; not concurrent with processing).
  • processBlock() / pushSamples() / reset(): audio thread (stream owner).
  • setRange() / setConfidence() / setGlide(): any thread (relaxed atomics; non-finite values are ignored).
  • getSmoothedHz() / getRawHz() / getConfidence() / isTracking() and the parameter getters: any thread, lock-free.
follower.prepare(spec);
follower.setRange(70.0f, 800.0f); // vocal range
follower.setGlide(60.0f); // ms per octave
// per block:
follower.processBlock(buffer); // internal mono sum
eq.setFrequency(follower.getSmoothedHz() * 0.9f); // low-cut under tonic

Dependencies: PitchDetector.h, AudioSpec.h, AudioBuffer.h, DspMath.h.

Definition in file PitchFollower.h.