FastLED 3.9.15
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_NOEXCEPT
 Construct with standalone Beat.
 
 Downbeat (shared_ptr< Beat > beatDetector)
 Construct with shared Beat (recommended)
 
 ~Downbeat () FL_NOEXCEPT override
 
void fireCallbacks () override
 
u8 getBeatsPerMeasure () const
 Returns detected beats per measure (time signature numerator)
 
float getConfidence () const
 Returns downbeat detection confidence (0-1)
 
u8 getCurrentBeat () const
 Returns current beat number within measure (1-based, 1 = downbeat)
 
float getMeasurePhase () const
 Returns measure phase (0-1, 0 = downbeat)
 
const char * getName () const override
 
bool isDownbeat () const
 Returns true if downbeat was detected this frame.
 
bool needsFFT () const override
 
bool needsFFTHistory () const override
 
void reset () override
 
void setAccentThreshold (float threshold)
 Set accent detection threshold (default: 1.2)
 
void setAutoMeterDetection (bool enable)
 Enable/disable automatic meter detection (default: true)
 
void setBeatDetector (shared_ptr< Beat > beatDetector)
 Share an external Beat instance.
 
void setConfidenceThreshold (float threshold)
 Set minimum confidence for downbeat detection (default: 0.6)
 
void setTimeSignature (u8 beatsPerMeasure)
 Manually set time signature (disables auto-detection)
 
void update (shared_ptr< Context > context) override
 
- Public Member Functions inherited from fl::audio::Detector
virtual ~Detector () FL_NOEXCEPT=default
 
virtual void setSampleRate (int) FL_NOEXCEPT
 

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)
 
bool detectDownbeat (u32 timestamp, float accent)
 
void detectMeter ()
 
u8 findMostCommonMeter () const
 
void updateBeatDetector (shared_ptr< Context > context)
 
void updateMeasurePhase (u32 timestamp)
 

Private Attributes

float mAccentThreshold
 
bool mAutoMeterDetection
 
deque< float > mBeatAccents
 
shared_ptr< BeatmBeatDetector
 
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< u8mMeterCandidates
 
bool mOwnsBeatDetector
 
u8 mPendingBeatNumber = 0
 
u8 mPendingMeter = 0
 
float mPreviousEnergy
 
shared_ptr< const fft::BinsmRetainedFFT
 

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: