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

Detailed Description

Detects downbeats (first beat of each measure) in music.

The Downbeat analyzes beat patterns to identify the first beat of each musical measure. It detects metric groupings (time signatures) and tracks measure position.

Features:

  • Downbeat detection with confidence
  • Time signature detection (4/4, 3/4, 6/8, etc.)
  • Beat numbering within measures
  • Measure phase tracking (0-1 within measure)
  • Adaptive meter detection

Dependencies:

  • Requires Beat for rhythm analysis
  • Uses FFT for accent detection
  • Analyzes beat interval patterns

Definition at line 33 of file downbeat.h.

#include <downbeat.h>

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

Public Member Functions

 Downbeat () FL_NO_EXCEPT
 Construct with standalone Beat.
 
 Downbeat (shared_ptr< Beat > beatDetector) FL_NO_EXCEPT
 Construct with shared Beat (recommended)
 
 ~Downbeat () FL_NO_EXCEPT override
 
void fireCallbacks () FL_NO_EXCEPT override
 
u8 getBeatsPerMeasure () const FL_NO_EXCEPT
 Returns detected beats per measure (time signature numerator)
 
float getConfidence () const FL_NO_EXCEPT
 Returns downbeat detection confidence (0-1)
 
u8 getCurrentBeat () const FL_NO_EXCEPT
 Returns current beat number within measure (1-based, 1 = downbeat)
 
float getMeasurePhase () const FL_NO_EXCEPT
 Returns measure phase (0-1, 0 = downbeat)
 
const char * getName () const FL_NO_EXCEPT override
 
bool isDownbeat () const FL_NO_EXCEPT
 Returns true if downbeat 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 setAccentThreshold (float threshold) FL_NO_EXCEPT
 Set accent detection threshold (default: 1.2)
 
void setAutoMeterDetection (bool enable) FL_NO_EXCEPT
 Enable/disable automatic meter detection (default: true)
 
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 downbeat detection (default: 0.6)
 
void setTimeSignature (u8 beatsPerMeasure) FL_NO_EXCEPT
 Manually set time signature (disables auto-detection)
 
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()> onDownbeat
 Fires on detected downbeat (first beat of measure)
 
function_list< void(u8 beatNumber)> onMeasureBeat
 Fires on each beat with beat number (1-based, downbeat = 1)
 
function_list< void(float phase)> onMeasurePhase
 Fires with measure phase each frame (0-1 range)
 
function_list< void(u8 beatsPerMeasure)> onMeterChange
 Fires when time signature changes.
 

Private Member Functions

float calculateBeatAccent (const fft::Bins &fft, float bassEnergy) FL_NO_EXCEPT
 
bool detectDownbeat (u32 timestamp, float accent) FL_NO_EXCEPT
 
void detectMeter () FL_NO_EXCEPT
 
u8 findMostCommonMeter () const FL_NO_EXCEPT
 
void updateBeatDetector (shared_ptr< Context > context) FL_NO_EXCEPT
 
void updateMeasurePhase (u32 timestamp) FL_NO_EXCEPT
 

Private Attributes

float mAccentThreshold
 
bool mAutoMeterDetection
 
deque< float > mBeatAccents
 
shared_ptr< Beat > mBeatDetector
 
u8 mBeatsPerMeasure
 
u8 mBeatsSinceDownbeat
 
float mConfidence
 
float mConfidenceThreshold
 
u8 mCurrentBeat
 
bool mDownbeatDetected
 
bool mFireDownbeat = false
 
bool mFireMeasureBeat = false
 
bool mFireMeterChange = false
 
u32 mLastBeatTime
 
u32 mLastDownbeatTime
 
bool mManualMeter
 
float mMeasurePhase
 
deque< u8 > mMeterCandidates
 
bool mOwnsBeatDetector
 
u8 mPendingBeatNumber = 0
 
u8 mPendingMeter = 0
 
float mPreviousEnergy
 
shared_ptr< const fft::Bins > mRetainedFFT
 

Static Private Attributes

static constexpr size MAX_BEAT_HISTORY = 32
 
static constexpr size METER_HISTORY_SIZE = 8
 

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