FastLED 3.9.15
Loading...
Searching...
No Matches

◆ detectBeat()

bool fl::audio::detector::Beat::detectBeat ( u32 timestamp)
private

Definition at line 110 of file beat.cpp.hpp.

110 {
111 // Use adaptive threshold with an absolute floor. The floor handles
112 // the silence-to-signal transition when adaptive threshold is near zero,
113 // and prevents CQ spectral leakage from triggering false beats.
114 static constexpr float MIN_FLUX_THRESHOLD = 50.0f;
115 float effectiveThreshold = fl::max(mAdaptiveThreshold, MIN_FLUX_THRESHOLD);
116
117 // Check if flux exceeds effective threshold
118 if (mSpectralFlux <= effectiveThreshold) {
119 return false;
120 }
121
122 // Check cooldown period
123 u32 timeSinceLastBeat = timestamp - mLastBeatTime;
124 if (timeSinceLastBeat < MIN_BEAT_INTERVAL_MS) {
125 return false;
126 }
127
128 // Calculate confidence based on how much we exceeded threshold
129 if (mAdaptiveThreshold > 0.0f) {
131 } else {
132 mConfidence = 1.0f;
133 }
134
135 return true;
136}
static constexpr u32 MIN_BEAT_INTERVAL_MS
Definition beat.h:57
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75

References mAdaptiveThreshold, fl::max(), mConfidence, fl::min(), MIN_BEAT_INTERVAL_MS, mLastBeatTime, and mSpectralFlux.

+ Here is the call graph for this function: