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

◆ calculateBeatConfidence()

float fl::audio::detector::MusicalBeat::calculateBeatConfidence ( float currentIBI)
private

Calculate beat confidence based on rhythmic consistency.

Parameters
currentIBICurrent inter-beat interval
Returns
Confidence score (0.0-1.0)

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

152 {
153 // Confidence based on temporal consistency
154 if (mIBIHistory.size() < 2) {
155 // Not enough history - return moderate confidence
156 return 0.6f;
157 }
158
159 // Calculate IBI standard deviation
160 float stdDev = calculateIBIStdDev();
161
162 // Average IBI in seconds
163 float avgIBI = getAverageIBI();
164
165 // Coefficient of variation (normalized std dev)
166 float cv = (avgIBI > 0.0f) ? (stdDev / avgIBI) : 1.0f;
167
168 // Confidence inversely proportional to variability
169 // cv = 0.0 (perfect consistency) → confidence = 1.0
170 // cv = 0.2 (20% variation) → confidence ≈ 0.5
171 // cv ≥ 0.5 (50%+ variation) → confidence → 0.0
172 float confidence = fl::max(0.0f, 1.0f - (cv * 2.0f));
173
174 // Boost confidence if current IBI matches average closely
175 float ibiDiff = fl::abs(currentIBI - avgIBI);
176 float ibiError = (avgIBI > 0.0f) ? (ibiDiff / avgIBI) : 1.0f;
177 float ibiBonus = fl::max(0.0f, 1.0f - (ibiError * 4.0f));
178
179 // Combined confidence (weighted average)
180 return (confidence * 0.7f) + (ibiBonus * 0.3f);
181}
deque< u32 > mIBIHistory
Inter-beat interval history (in frames)
float getAverageIBI() const
Get inter-beat interval (IBI) statistics.
float calculateIBIStdDev() const
Calculate standard deviation of IBI history.
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 abs(T x) FL_NOEXCEPT

References fl::abs(), calculateIBIStdDev(), getAverageIBI(), fl::max(), and mIBIHistory.

Referenced by processSample().

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