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

◆ updateStability()

void fl::audio::detector::TempoAnalyzer::updateStability ( )
private

Definition at line 266 of file tempo_analyzer.cpp.hpp.

266 {
267 if (mBPMHistory.size() < 5) {
268 mStability = 0.0f;
269 mIsStable = false;
271 return;
272 }
273
274 // Calculate variance of recent BPM estimates
275 float sum = 0.0f;
276 for (size i = 0; i < mBPMHistory.size(); i++) {
277 sum += mBPMHistory[i];
278 }
279 float mean = sum / static_cast<float>(mBPMHistory.size());
280
281 float variance = 0.0f;
282 for (size i = 0; i < mBPMHistory.size(); i++) {
283 float diff = mBPMHistory[i] - mean;
284 variance += diff * diff;
285 }
286 variance /= static_cast<float>(mBPMHistory.size());
287
288 // Convert variance to stability score (low variance = high stability)
289 float stddev = fl::sqrt(variance);
290 mStability = fl::max(0.0f, 1.0f - (stddev / 10.0f));
291
292 // Check if stable
296 mIsStable = true;
297 }
298 } else {
300 mIsStable = false;
301 }
302}
static constexpr u32 STABLE_FRAMES_REQUIRED
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NOEXCEPT

References fl::max(), mBPMHistory, mIsStable, mStability, mStabilityThreshold, mStableFrameCount, fl::sqrt(), and STABLE_FRAMES_REQUIRED.

Referenced by update().

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