MCPcopy Create free account
hub / github.com/FastLED/FastLED / updateStability

Method updateStability

src/fl/audio/detector/tempo_analyzer.cpp.hpp:266–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264}
265
266void TempoAnalyzer::updateStability() {
267 if (mBPMHistory.size() < 5) {
268 mStability = 0.0f;
269 mIsStable = false;
270 mStableFrameCount = 0;
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
293 if (mStability >= mStabilityThreshold) {
294 mStableFrameCount++;
295 if (mStableFrameCount >= STABLE_FRAMES_REQUIRED) {
296 mIsStable = true;
297 }
298 } else {
299 mStableFrameCount = 0;
300 mIsStable = false;
301 }
302}
303
304float TempoAnalyzer::calculateIntervalScore(u32 interval) {
305 float bpm = 60000.0f / static_cast<float>(interval);

Callers

nothing calls this directly

Calls 3

sqrtFunction · 0.85
maxFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected