FastLED 3.9.15
Loading...
Searching...
No Matches
multiband_beat_detector.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/int.h"
4#include "fl/stl/span.h"
5#include "fl/stl/noexcept.h"
6
7namespace fl {
8namespace audio {
9namespace detector {
10
15 float bassThreshold = 0.15f;
16
19 float midThreshold = 0.12f;
20
23 float trebleThreshold = 0.08f;
24
28
32
35 float correlationBoost = 0.05f;
36};
37
75public:
77 explicit MultiBandBeat(const MultiBandBeatDetectorConfig& config);
79
81 void configure(const MultiBandBeatDetectorConfig& config);
82
85 void detectBeats(span<const float> frequencyBins);
86
89 bool isBassBeat() const;
90
93 bool isMidBeat() const;
94
97 bool isTrebleBeat() const;
98
100 float getBassEnergy() const;
101
103 float getMidEnergy() const;
104
106 float getTrebleEnergy() const;
107
110 bool isMultiBandBeat() const;
111
113 void reset();
114
116 struct Stats {
117 u32 bassBeats = 0; // Total bass beats detected (lifetime)
118 u32 midBeats = 0; // Total mid beats detected (lifetime)
119 u32 trebleBeats = 0; // Total treble beats detected (lifetime)
120 u32 multiBandBeats = 0; // Beats with multiple bands (lifetime)
121 float bassEnergy = 0.0f; // Current bass energy
122 float midEnergy = 0.0f; // Current mid energy
123 float trebleEnergy = 0.0f; // Current treble energy
124 };
125
126 const Stats& getStats() const { return mStats; }
127
128private:
135 bool detectBandBeat(float currentEnergy, float previousEnergy,
136 float threshold, u32& cooldownCounter);
137
141 float calculateBassEnergy(span<const float> frequencyBins) const;
142
146 float calculateMidEnergy(span<const float> frequencyBins) const;
147
151 float calculateTrebleEnergy(span<const float> frequencyBins) const;
152
155
157 bool mBassBeat = false;
158 bool mMidBeat = false;
159 bool mTrebleBeat = false;
160
162 float mBassEnergy = 0.0f;
163 float mMidEnergy = 0.0f;
164 float mTrebleEnergy = 0.0f;
165
168 float mPreviousMidEnergy = 0.0f;
170
175
178
180 static constexpr size BASS_BIN_START = 0;
181 static constexpr size BASS_BIN_END = 2; // Bins 0-1
182 static constexpr size MID_BIN_START = 6;
183 static constexpr size MID_BIN_END = 8; // Bins 6-7
184 static constexpr size TREBLE_BIN_START = 14;
185 static constexpr size TREBLE_BIN_END = 16; // Bins 14-15
186};
187
188} // namespace detector
189} // namespace audio
190} // namespace fl
bool detectBandBeat(float currentEnergy, float previousEnergy, float threshold, u32 &cooldownCounter)
Detect beat in a specific frequency band.
void reset()
Reset internal state (clear history, reset cooldowns)
float getMidEnergy() const
Get current mid energy (0.0-1.0)
bool isBassBeat() const
Check if a bass beat was detected in the last frame.
float calculateMidEnergy(span< const float > frequencyBins) const
Calculate energy for mid band (bins 6-7)
float getTrebleEnergy() const
Get current treble energy (0.0-1.0)
bool isMultiBandBeat() const
Check if multiple bands triggered simultaneously (strong beat)
bool mBassBeat
Beat detection flags for current frame.
bool isMidBeat() const
Check if a mid beat was detected in the last frame.
float getBassEnergy() const
Get current bass energy (0.0-1.0)
u32 mBassCooldown
Beat cooldown counters (prevent double-triggering)
float calculateBassEnergy(span< const float > frequencyBins) const
Calculate energy for bass band (bins 0-1)
float mPreviousBassEnergy
Previous band energies (for energy increase calculation)
bool isTrebleBeat() const
Check if a treble beat was detected in the last frame.
void configure(const MultiBandBeatDetectorConfig &config)
Configure the multi-band beat detector.
static constexpr size BASS_BIN_START
Frequency bin indices for each band.
float calculateTrebleEnergy(span< const float > frequencyBins) const
Calculate energy for treble band (bins 14-15)
void detectBeats(span< const float > frequencyBins)
Detect beats in all frequency bands.
Get statistics (for debugging/monitoring)
float correlationBoost
Cross-band correlation boost (0.0-1.0) Added to threshold when multiple bands trigger together.
u32 beatCooldownFrames
Minimum cooldown between beats in same band (frames) Prevents double-triggering on same beat.
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.
bool enableCrossBandCorrelation
Enable cross-band correlation Boosts confidence when multiple bands trigger simultaneously.
float bassThreshold
Bass beat threshold (0.0-1.0) Energy increase required to trigger bass beat.
Configuration for multi-band beat detection.
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT