DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::ChordDetector< T > Class Template Reference

Monophonic-buffer chord recognition with confidence gating. More...

#include <ChordDetector.h>

Classes

struct  Result
 One detection result. More...
 

Public Types

enum class  ChordType : uint8_t {
  None = 0 , Major , Minor , Diminished ,
  Augmented , Sus2 , Sus4 , Dominant7 ,
  Major7 , Minor7 , HalfDim7
}
 Recognized chord families. More...
 

Public Member Functions

void prepare (const AudioSpec &spec, int windowSize=4096)
 Prepares the analysis pipeline.
 
void reset () noexcept
 Clears the analysis ring and forgets the held chord.
 
void setConfidenceThreshold (float threshold) noexcept
 Confidence below which the previous chord is held (default 0.55).
 
float getConfidenceThreshold () const noexcept
 
void processBlock (AudioBufferView< const T > buffer) noexcept
 Feeds a block (channels averaged to mono).
 
void pushSamples (std::span< const T > samples) noexcept
 Feeds mono samples directly.
 
Result getChord () const noexcept
 

Static Public Member Functions

static int getChordName (const Result &result, char *dest, int size) noexcept
 Writes a human-readable chord name ("C", "F#m7", "Bbsus4"...).
 

Detailed Description

template<FloatType T>
class dspark::ChordDetector< T >

Monophonic-buffer chord recognition with confidence gating.

Template Parameters
TSample type (float or double).

Definition at line 59 of file ChordDetector.h.

Member Enumeration Documentation

◆ ChordType

template<FloatType T>
enum class dspark::ChordDetector::ChordType : uint8_t
strong

Recognized chord families.

Enumerator
None 
Major 
Minor 
Diminished 
Augmented 
Sus2 
Sus4 
Dominant7 
Major7 
Minor7 
HalfDim7 

Definition at line 63 of file ChordDetector.h.

Member Function Documentation

◆ getChord()

template<FloatType T>
Result dspark::ChordDetector< T >::getChord ( ) const
inlinenoexcept
Returns
The current (possibly held) chord.

Definition at line 176 of file ChordDetector.h.

◆ getChordName()

template<FloatType T>
static int dspark::ChordDetector< T >::getChordName ( const Result result,
char *  dest,
int  size 
)
inlinestaticnoexcept

Writes a human-readable chord name ("C", "F#m7", "Bbsus4"...).

Parameters
resultChord to name.
destDestination buffer.
sizeCapacity of dest (8+ recommended).
Returns
Number of characters written (excluding the terminator).

Definition at line 188 of file ChordDetector.h.

◆ getConfidenceThreshold()

template<FloatType T>
float dspark::ChordDetector< T >::getConfidenceThreshold ( ) const
inlinenoexcept
Returns
The current confidence-gating threshold.

Definition at line 140 of file ChordDetector.h.

◆ prepare()

template<FloatType T>
void dspark::ChordDetector< T >::prepare ( const AudioSpec spec,
int  windowSize = 4096 
)
inline

Prepares the analysis pipeline.

Parameters
specAudio environment specification.
windowSizeAnalysis window (default 4096: ~85 ms at 48 kHz).

Definition at line 84 of file ChordDetector.h.

◆ processBlock()

template<FloatType T>
void dspark::ChordDetector< T >::processBlock ( AudioBufferView< const T >  buffer)
inlinenoexcept

Feeds a block (channels averaged to mono).

Definition at line 148 of file ChordDetector.h.

◆ pushSamples()

template<FloatType T>
void dspark::ChordDetector< T >::pushSamples ( std::span< const T >  samples)
inlinenoexcept

Feeds mono samples directly.

Definition at line 166 of file ChordDetector.h.

◆ reset()

template<FloatType T>
void dspark::ChordDetector< T >::reset ( )
inlinenoexcept

Clears the analysis ring and forgets the held chord.

Allocation-free, but it rewrites the stream state: call it from the thread that owns the stream (or while processing is stopped), not concurrently with processBlock()/pushSamples().

Definition at line 118 of file ChordDetector.h.

◆ setConfidenceThreshold()

template<FloatType T>
void dspark::ChordDetector< T >::setConfidenceThreshold ( float  threshold)
inlinenoexcept

Confidence below which the previous chord is held (default 0.55).

Callable from any thread. Non-finite values are ignored (a NaN would make every comparison false and freeze the detector on the held chord forever).

Definition at line 133 of file ChordDetector.h.


The documentation for this class was generated from the following file: