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

◆ updateTempo()

void fl::audio::detector::Beat::updateTempo ( u32 timestamp)
private

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

138 {
139 u32 interval = timestamp - mLastBeatTime;
140
141 // Only update tempo if interval is reasonable
142 if (interval >= MIN_BEAT_INTERVAL_MS && interval <= MAX_BEAT_INTERVAL_MS) {
143 // Smooth tempo changes
144 const float alpha = 0.2f;
145 mBeatInterval = static_cast<u32>(
146 alpha * static_cast<float>(interval) +
147 (1.0f - alpha) * static_cast<float>(mBeatInterval)
148 );
149
150 // Convert interval to BPM
151 float newBPM = 60000.0f / static_cast<float>(mBeatInterval);
152
153 // Check if tempo changed significantly
154 float bpmDiff = fl::abs(newBPM - mBPM);
155 mTempoChanged = (bpmDiff > 5.0f);
156
157 mBPM = newBPM;
158 }
159}
static constexpr u32 MAX_BEAT_INTERVAL_MS
Definition beat.h:58
static constexpr u32 MIN_BEAT_INTERVAL_MS
Definition beat.h:57
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT

References fl::abs(), MAX_BEAT_INTERVAL_MS, mBeatInterval, mBPM, MIN_BEAT_INTERVAL_MS, mLastBeatTime, and mTempoChanged.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: