FastLED 3.9.15
Loading...
Searching...
No Matches
fl::audio::detector::MultiBandBeat Class Reference

Detailed Description

MultiBandBeat performs frequency-specific beat detection.

This class separates beat detection into three frequency bands:

  • Bass (bins 0-1): 20-80 Hz - kick drums, bass guitar
  • Mid (bins 6-7): 320-640 Hz - snares, vocals, guitars
  • Treble (bins 14-15): 5120-16000 Hz - hi-hats, cymbals

Features:

  1. Per-band energy tracking and threshold adaptation
  2. Independent beat detection for each frequency range
  3. Cross-band beat correlation (e.g., kick+snare = strong beat)
  4. Per-band cooldown to prevent double-triggering

Usage:

config.bassThreshold = 0.15f;
config.midThreshold = 0.12f;
config.trebleThreshold = 0.08f;
detector.configure(config);
// Each audio frame:
float frequencyBins[16] = {...}; // From FrequencyBinMapper
detector.detectBeats(frequencyBins);
if (detector.isBassBeat()) {
// Trigger bass-synchronized effect (e.g., strobe on kick)
}
if (detector.isMidBeat()) {
// Trigger mid-synchronized effect (e.g., pulse on snare)
}
if (detector.isTrebleBeat()) {
// Trigger treble-synchronized effect (e.g., sparkle on hi-hat)
}
bool isTrebleBeat() const
Check if a treble beat was detected in the last frame.
float midThreshold
Mid beat threshold (0.0-1.0) Energy increase required to trigger mid beat.
float trebleThreshold
Treble beat threshold (0.0-1.0) Energy increase required to trigger treble beat.
float bassThreshold
Bass beat threshold (0.0-1.0) Energy increase required to trigger bass beat.
Configuration for multi-band beat detection.

Definition at line 74 of file multiband_beat_detector.h.

#include <multiband_beat_detector.h>

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

Classes

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

Public Member Functions

 MultiBandBeat () FL_NOEXCEPT
 
 MultiBandBeat (const MultiBandBeatDetectorConfig &config)
 
 ~MultiBandBeat () FL_NOEXCEPT
 
void configure (const MultiBandBeatDetectorConfig &config)
 Configure the multi-band beat detector.
 
void detectBeats (span< const float > frequencyBins)
 Detect beats in all frequency bands.
 
float getBassEnergy () const
 Get current bass energy (0.0-1.0)
 
float getMidEnergy () const
 Get current mid energy (0.0-1.0)
 
const StatsgetStats () const
 
float getTrebleEnergy () const
 Get current treble energy (0.0-1.0)
 
bool isBassBeat () const
 Check if a bass beat was detected in the last frame.
 
bool isMidBeat () const
 Check if a mid beat was detected in the last frame.
 
bool isMultiBandBeat () const
 Check if multiple bands triggered simultaneously (strong beat)
 
bool isTrebleBeat () const
 Check if a treble beat was detected in the last frame.
 
void reset ()
 Reset internal state (clear history, reset cooldowns)
 

Private Member Functions

float calculateBassEnergy (span< const float > frequencyBins) const
 Calculate energy for bass band (bins 0-1)
 
float calculateMidEnergy (span< const float > frequencyBins) const
 Calculate energy for mid band (bins 6-7)
 
float calculateTrebleEnergy (span< const float > frequencyBins) const
 Calculate energy for treble band (bins 14-15)
 
bool detectBandBeat (float currentEnergy, float previousEnergy, float threshold, u32 &cooldownCounter)
 Detect beat in a specific frequency band.
 

Private Attributes

bool mBassBeat = false
 Beat detection flags for current frame.
 
u32 mBassCooldown = 0
 Beat cooldown counters (prevent double-triggering)
 
float mBassEnergy = 0.0f
 Current band energies.
 
MultiBandBeatDetectorConfig mConfig
 
u32 mCurrentFrame = 0
 Current frame counter.
 
bool mMidBeat = false
 
u32 mMidCooldown = 0
 
float mMidEnergy = 0.0f
 
float mPreviousBassEnergy = 0.0f
 Previous band energies (for energy increase calculation)
 
float mPreviousMidEnergy = 0.0f
 
float mPreviousTrebleEnergy = 0.0f
 
Stats mStats
 
bool mTrebleBeat = false
 
u32 mTrebleCooldown = 0
 
float mTrebleEnergy = 0.0f
 

Static Private Attributes

static constexpr size BASS_BIN_END = 2
 
static constexpr size BASS_BIN_START = 0
 Frequency bin indices for each band.
 
static constexpr size MID_BIN_END = 8
 
static constexpr size MID_BIN_START = 6
 
static constexpr size TREBLE_BIN_END = 16
 
static constexpr size TREBLE_BIN_START = 14
 

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