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

Real-time chord detection: Goertzel chroma + template matching. More...

#include "../Analysis/Goertzel.h"
#include "../Core/AudioBuffer.h"
#include "../Core/AudioSpec.h"
#include "../Core/DspMath.h"
#include "../Core/WindowFunctions.h"
#include "HarmonyConstants.h"
#include <algorithm>
#include <array>
#include <atomic>
#include <cmath>
#include <cstdint>
#include <span>
#include <vector>
Include dependency graph for ChordDetector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::ChordDetector< T >
 Monophonic-buffer chord recognition with confidence gating. More...
 
struct  dspark::ChordDetector< T >::Result
 One detection result. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Real-time chord detection: Goertzel chroma + template matching.

Classic music-information-retrieval pipeline, allocation-free:

  1. A mono sum is windowed (Hann) every hop and analyzed with one exact Goertzel per note over MIDI 36..83 (four octaves) - no FFT-grid compromise at low pitches.
  2. Note energies fold into a 12-bin chroma vector.
  3. The chroma is cosine-matched against chord templates (major, minor, diminished, augmented, sus2, sus4, dom7, maj7, min7, half-dim7) at all 12 roots; the winner and its margin over the runner-up produce a confidence in [0, 1].

The reading is gated: while confidence is below the threshold the last confident chord is held, so brief transients and silences do not flicker the display.

Threading: prepare() is setup-thread only (allocates). processBlock / pushSamples and reset() belong to the thread that owns the stream. setConfidenceThreshold() may be called from any thread, and getChord() is a lock-free readout safe from any thread (single packed atomic word, never torn).

Dependencies: Goertzel.h, HarmonyConstants.h, AudioSpec.h, AudioBuffer.h, WindowFunctions.h, DspMath.h.

Definition in file ChordDetector.h.