FastLED 3.10.8
Loading...
Searching...
No Matches
fl::audio::detector::Backbeat Class Reference

Detailed Description

Detects backbeats (beats 2 and 4 in 4/4 time) in music.

The Backbeat identifies backbeat patterns using multi-band frequency analysis with emphasis on mid-range frequencies where snare drums are prominent. It complements the Downbeat and is crucial for rock, pop, funk, and many other genres where the snare drum emphasizes the backbeat.

Features:

  • Multi-band accent detection (bass, mid, high)
  • Adaptive threshold learning
  • Spectral profile matching
  • Works standalone or with Downbeat
  • Confidence scoring
  • Pattern consistency checking

Dependencies:

  • Requires Beat for rhythm analysis
  • Optional Downbeat for accurate measure position
  • Uses FFT for frequency analysis

Definition at line 45 of file backbeat.h.

#include <backbeat.h>

+ Inheritance diagram for fl::audio::detector::Backbeat:
+ Collaboration diagram for fl::audio::detector::Backbeat:

Public Member Functions

 Backbeat () FL_NO_EXCEPT
 Construct with standalone Beat.
 
 Backbeat (shared_ptr< Beat > beatDetector) FL_NO_EXCEPT
 Construct with shared Beat.
 
 Backbeat (shared_ptr< Beat > beatDetector, shared_ptr< Downbeat > downbeatDetector) FL_NO_EXCEPT
 Construct with shared Beat and Downbeat.
 
 ~Backbeat () FL_NO_EXCEPT override
 
void fireCallbacks () FL_NO_EXCEPT override
 
float getBackbeatRatio () const FL_NO_EXCEPT
 Returns ratio of backbeat to downbeat energy (0-2+)
 
float getConfidence () const FL_NO_EXCEPT
 Returns backbeat detection confidence (0-1)
 
u8 getLastBackbeatNumber () const FL_NO_EXCEPT
 Returns the beat number of the last detected backbeat (1-based)
 
const char * getName () const FL_NO_EXCEPT override
 
float getStrength () const FL_NO_EXCEPT
 Returns current backbeat accent strength (0-1+)
 
bool isBackbeat () const FL_NO_EXCEPT
 Returns true if backbeat was detected this frame.
 
bool needsFFT () const FL_NO_EXCEPT override
 
bool needsFFTHistory () const FL_NO_EXCEPT override
 
void reset () FL_NO_EXCEPT override
 
void setAdaptive (bool enable) FL_NO_EXCEPT
 Enable/disable adaptive threshold learning (default: true)
 
void setBackbeatExpectedBeats (u8 beatMask) FL_NO_EXCEPT
 Set which beats are backbeats using bitmask (bit 0=beat 1, bit 1=beat 2, etc.)
 
void setBassThreshold (float threshold) FL_NO_EXCEPT
 Set bass accent threshold (default: 1.2)
 
void setBeatDetector (shared_ptr< Beat > beatDetector) FL_NO_EXCEPT
 Share an external Beat instance.
 
void setConfidenceThreshold (float threshold) FL_NO_EXCEPT
 Set minimum confidence for backbeat detection (default: 0.6)
 
void setDownbeatDetector (shared_ptr< Downbeat > downbeatDetector) FL_NO_EXCEPT
 Share an external Downbeat instance.
 
void setHighThreshold (float threshold) FL_NO_EXCEPT
 Set high accent threshold (default: 1.1)
 
void setMidThreshold (float threshold) FL_NO_EXCEPT
 Set mid accent threshold (default: 1.3) - critical for snare.
 
void update (shared_ptr< Context > context) FL_NO_EXCEPT override
 
- Public Member Functions inherited from fl::audio::Detector
virtual ~Detector () FL_NO_EXCEPT=default
 
virtual void setSampleRate (int) FL_NO_EXCEPT
 

Public Attributes

function_list< void(u8 beatNumber, float confidence, float strength)> onBackbeat
 Fires on detected backbeat (beats 2, 4) with beat number, confidence, and strength.
 

Private Member Functions

MultibandAccent calculateMultibandAccent (const fft::Bins &fft) FL_NO_EXCEPT
 
float calculatePatternConfidence (const fft::Bins &fft) FL_NO_EXCEPT
 
bool detectBackbeat (float accentStrength, const fft::Bins &fft) FL_NO_EXCEPT
 
float detectBackbeatAccent (const MultibandAccent &accent) FL_NO_EXCEPT
 
bool isBackbeatPosition () const FL_NO_EXCEPT
 
void updateAdaptiveThresholds () FL_NO_EXCEPT
 
void updateBackbeatProfile (const fft::Bins &fft) FL_NO_EXCEPT
 
void updateBeatDetector (shared_ptr< Context > context) FL_NO_EXCEPT
 
void updateBeatPosition () FL_NO_EXCEPT
 

Private Attributes

bool mAdaptive
 
float mAdaptiveThreshold
 
deque< float > mBackbeatAccents
 
bool mBackbeatDetected
 
u8 mBackbeatMask
 
float mBackbeatMean
 
float mBackbeatRatio
 
vector< float > mBackbeatSpectralProfile
 
float mBassThreshold
 
shared_ptr< Beat > mBeatDetector
 
u8 mBeatsPerMeasure
 
float mConfidence
 
float mConfidenceThreshold
 
u8 mCurrentBeat
 
float mCurrentStrength
 
shared_ptr< Downbeat > mDownbeatDetector
 
float mHighThreshold
 
u8 mLastBackbeatNumber
 
float mMidThreshold
 
deque< float > mNonBackbeatAccents
 
float mNonBackbeatMean
 
bool mOwnsBeatDetector
 
bool mOwnsDownbeatDetector
 
MultibandAccent mPreviousAccent
 
bool mPreviousWasBeat
 
float mProfileAlpha
 
shared_ptr< const fft::Bins > mRetainedFFT
 

Static Private Attributes

static constexpr size MAX_ACCENT_HISTORY = 16
 
static constexpr size SPECTRAL_PROFILE_SIZE = 16
 

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