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

◆ updateSpectralFlux()

void fl::audio::Reactive::updateSpectralFlux ( )
private

Definition at line 621 of file audio_reactive.cpp.hpp.

621 {
622 // Compute spectral flux from Reactive's own previous magnitudes.
623 //
624 // IMPORTANT ordering contract (called from processSample):
625 // Step 7: updateSpectralFlux() — uses & updates Reactive::mPreviousMagnitudes
626 // Step 9: detectEnhancedBeats() — calls SpectralFluxDetector::detectOnset()
627 // which uses & updates SpectralFluxDetector::mPreviousMagnitudes
628 //
629 // Both arrays converge to the same values (both set to mCurrentData.frequencyBins
630 // each frame), but they are separate to avoid a state-ordering bug: calling
631 // mSpectralFluxDetector->calculateSpectralFlux() here would update the
632 // detector's internal state and cause detectOnset() to see zero flux.
633 float flux = 0.0f;
634 for (int i = 0; i < 16; ++i) {
635 float diff = mCurrentData.frequencyBins[i] - mPreviousMagnitudes[i];
636 if (diff > 0.0f) {
637 flux += diff;
638 }
639 }
640 mCurrentData.spectralFlux = flux;
641
642 // Update previous magnitudes for next frame
643 for (int i = 0; i < 16; ++i) {
644 mPreviousMagnitudes[i] = mCurrentData.frequencyBins[i];
645 }
646}
fl::array< float, 16 > mPreviousMagnitudes

References mCurrentData, and mPreviousMagnitudes.

Referenced by processSample().

+ Here is the caller graph for this function: