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

◆ calculatePatternConfidence()

float fl::audio::detector::Backbeat::calculatePatternConfidence ( const fft::Bins & fft)
private

Definition at line 394 of file backbeat.cpp.hpp.

394 {
395 // Calculate spectral correlation between current spectrum and learned profile
396 // Returns 0-1 indicating how well current spectrum matches typical backbeat
397
398 // If profile is not yet learned, return neutral confidence
399 bool profileLearned = false;
400 for (size i = 0; i < mBackbeatSpectralProfile.size(); i++) {
401 if (mBackbeatSpectralProfile[i] > 1e-6f) {
402 profileLearned = true;
403 break;
404 }
405 }
406
407 if (!profileLearned) {
408 return 0.5f; // Neutral confidence
409 }
410
411 // Calculate normalized correlation
412 size compareSize = fl::min(mBackbeatSpectralProfile.size(), fft.raw().size());
413
414 float dotProduct = 0.0f;
415 float profileMag = 0.0f;
416 float currentMag = 0.0f;
417
418 for (size i = 0; i < compareSize; i++) {
419 dotProduct += mBackbeatSpectralProfile[i] * fft.raw()[i];
421 currentMag += fft.raw()[i] * fft.raw()[i];
422 }
423
424 // Cosine similarity
425 const float epsilon = 1e-6f;
426 float denominator = fl::sqrt(profileMag * currentMag);
427
428 if (denominator < epsilon) {
429 return 0.5f; // Neutral if magnitudes too small
430 }
431
432 float correlation = dotProduct / denominator;
433
434 // Clamp to 0-1 range
435 return fl::clamp(correlation, 0.0f, 1.0f);
436}
AudioAnalyzeFFT1024 fft
vector< float > mBackbeatSpectralProfile
Definition backbeat.h:159
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT

References fl::clamp(), mBackbeatSpectralProfile, fl::min(), and fl::sqrt().

Referenced by detectBackbeat().

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