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

Detailed Description

MusicalBeat distinguishes true musical beats from random onset detection.

This class improves upon basic spectral flux onset detection by:

  1. Tracking inter-beat intervals (IBI) to detect rhythmic patterns
  2. Estimating BPM and validating beat candidates against the detected tempo
  3. Applying confidence scoring based on tempo consistency
  4. Rejecting random onsets that don't fit the detected tempo

Key insight: Basic onset detection triggers on ANY spectral change, not just musical beats. This detector uses temporal pattern recognition to distinguish true beats from random noise bursts or non-rhythmic transients.

Usage:

config.minBPM = 60.0f;
config.maxBPM = 180.0f;
detector.configure(config);
// Each audio frame:
bool onsetDetected = ... // From SpectralFluxDetector
float onsetStrength = ... // Onset magnitude
detector.processSample(onsetDetected, onsetStrength);
if (detector.isBeat()) {
float bpm = detector.getBPM();
float confidence = detector.getBeatConfidence();
// Trigger beat-synchronized effect
}
void bpm()
float maxBPM
Maximum BPM to detect (default: 250 BPM)
float minBPM
Minimum BPM to detect (default: 50 BPM)
Configuration for musical beat detection.

Definition at line 70 of file musical_beat_detector.h.

#include <musical_beat_detector.h>

+ Collaboration diagram for fl::audio::detector::MusicalBeat:

Classes

struct  Stats
 Get statistics (for debugging/monitoring) More...
 

Public Member Functions

 MusicalBeat () FL_NO_EXCEPT
 
 MusicalBeat (const MusicalBeatDetectorConfig &config) FL_NO_EXCEPT
 
 ~MusicalBeat () FL_NO_EXCEPT
 
void configure (const MusicalBeatDetectorConfig &config) FL_NO_EXCEPT
 Configure the beat detector.
 
float getAverageIBI () const FL_NO_EXCEPT
 Get inter-beat interval (IBI) statistics.
 
float getBeatConfidence () const FL_NO_EXCEPT
 Get beat confidence for the last detected beat.
 
float getBPM () const FL_NO_EXCEPT
 Get current BPM estimate.
 
const Stats & getStats () const FL_NO_EXCEPT
 
bool isBeat () const FL_NO_EXCEPT
 Check if a musical beat was detected in the last frame.
 
void processSample (bool onsetDetected, float onsetStrength) FL_NO_EXCEPT
 Process one audio frame.
 
void reset () FL_NO_EXCEPT
 Reset internal state (clear history, reset BPM)
 

Private Member Functions

float calculateBeatConfidence (float currentIBI) FL_NO_EXCEPT
 Calculate beat confidence based on rhythmic consistency.
 
float calculateIBIStdDev () const FL_NO_EXCEPT
 Calculate standard deviation of IBI history.
 
bool isValidIBI (float ibi) const FL_NO_EXCEPT
 Check if IBI is within valid BPM range.
 
void updateBPMEstimate () FL_NO_EXCEPT
 Update BPM estimate from inter-beat intervals.
 
bool validateBeat (float onsetStrength) FL_NO_EXCEPT
 Validate if an onset is a true musical beat.
 

Private Attributes

float mAverageIBI = 0.0f
 Average inter-beat interval (in frames)
 
bool mBeatDetected = false
 Last beat was detected.
 
MusicalBeatDetectorConfig mConfig
 
float mCurrentBPM = 120.0f
 Current BPM estimate (smoothed)
 
u32 mCurrentFrame = 0
 Current frame counter.
 
deque< u32 > mIBIHistory
 Inter-beat interval history (in frames)
 
float mLastBeatConfidence = 0.0f
 Last beat confidence score.
 
u32 mLastBeatFrame = 0
 Last beat timestamp (in frames)
 
Stats mStats
 

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