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

◆ calculateSpectralFlux()

float fl::audio::detector::Beat::calculateSpectralFlux ( const fft::Bins & fft)
private

Definition at line 80 of file beat.cpp.hpp.

80 {
81 float flux = 0.0f;
82 size numBins = fl::min(fft.raw().size(), mPreviousMagnitudes.size());
83
84 // Use the bass half of fft::FFT bins for beat detection.
85 // Musical beats (kick drums) have energy at 60-200 Hz.
86 // With 16 CQ log-spaced bins from 30-4698 Hz:
87 // bins 0-3 cover ~30-82 Hz (sub-bass)
88 // bins 4-7 cover ~82-226 Hz (bass/low-mid, kick fundamentals)
89 // Using numBins/2 = 8 bins covers the full kick drum range (~30-226 Hz).
90 // Treble transients (hi-hats, cymbals) in bins 8-15 are excluded.
91 size bassBins = numBins / 2;
92 if (bassBins < 1) bassBins = 1;
93
94 for (size i = 0; i < bassBins; i++) {
95 float diff = fft.raw()[i] - mPreviousMagnitudes[i];
96 if (diff > 0.0f) {
97 flux += diff;
98 }
99 }
100
101 return flux / static_cast<float>(bassBins);
102}
AudioAnalyzeFFT1024 fft
vector< float > mPreviousMagnitudes
Definition beat.h:51
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71

References fl::min(), and mPreviousMagnitudes.

Referenced by update().

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