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

◆ calculateIBIStdDev()

float fl::audio::detector::MusicalBeat::calculateIBIStdDev ( ) const
private

Calculate standard deviation of IBI history.

Returns
Standard deviation in seconds (lower = more consistent tempo)

Definition at line 219 of file musical_beat_detector.cpp.hpp.

219 {
220 if (mIBIHistory.size() < 2) {
221 return 0.0f;
222 }
223
224 // Calculate mean IBI in frames
225 u32 sum = 0;
226 for (size i = 0; i < mIBIHistory.size(); ++i) {
227 sum += mIBIHistory[i];
228 }
229 float mean = static_cast<float>(sum) / static_cast<float>(mIBIHistory.size());
230
231 // Calculate variance
232 float variance = 0.0f;
233 for (size i = 0; i < mIBIHistory.size(); ++i) {
234 float diff = static_cast<float>(mIBIHistory[i]) - mean;
235 variance += diff * diff;
236 }
237 variance /= static_cast<float>(mIBIHistory.size());
238
239 // Convert std dev from frames to seconds
240 float stdDevFrames = fl::sqrt(variance);
241 return (stdDevFrames * static_cast<float>(mConfig.samplesPerFrame)) /
242 static_cast<float>(mConfig.sampleRate);
243}
deque< u32 > mIBIHistory
Inter-beat interval history (in frames)
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NOEXCEPT

References mConfig, mIBIHistory, and fl::sqrt().

Referenced by calculateBeatConfidence().

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