FastLED 3.9.15
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_NOEXCEPT
 
 MusicalBeat (const MusicalBeatDetectorConfig &config)
 
 ~MusicalBeat () FL_NOEXCEPT
 
void configure (const MusicalBeatDetectorConfig &config)
 Configure the beat detector.
 
float getAverageIBI () const
 Get inter-beat interval (IBI) statistics.
 
float getBeatConfidence () const
 Get beat confidence for the last detected beat.
 
float getBPM () const
 Get current BPM estimate.
 
const StatsgetStats () const
 
bool isBeat () const
 Check if a musical beat was detected in the last frame.
 
void processSample (bool onsetDetected, float onsetStrength)
 Process one audio frame.
 
void reset ()
 Reset internal state (clear history, reset BPM)
 

Private Member Functions

float calculateBeatConfidence (float currentIBI)
 Calculate beat confidence based on rhythmic consistency.
 
float calculateIBIStdDev () const
 Calculate standard deviation of IBI history.
 
bool isValidIBI (float ibi) const
 Check if IBI is within valid BPM range.
 
void updateBPMEstimate ()
 Update BPM estimate from inter-beat intervals.
 
bool validateBeat (float onsetStrength)
 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: