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

◆ update()

void fl::audio::detector::Beat::update ( shared_ptr< Context > context)
overridevirtual

Implements fl::audio::Detector.

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

28 {
29 // Use 30 Hz min frequency so bass bins actually cover sub-bass (20-60 Hz).
30 // Default fmin (90 Hz) covers most bass but misses the deepest sub-bass.
31 // CQ_NAIVE provides bass/treble discrimination via CQ kernels
32 // (which include built-in Hamming windowing), while being faster
33 // than CQ_OCTAVE. The 16-bin / 30-14080Hz range has N_window=1,
34 // which is borderline for CQ_NAIVE but acceptable for beat detection.
35 mRetainedFFT = context->getFFT(16, 30.0f,
38 const fft::Bins& fft = *mRetainedFFT;
39 u32 timestamp = context->getTimestamp();
40
41 // Calculate spectral flux
43
44 // Detect beat BEFORE updating adaptive threshold.
45 // If we update the threshold first, the current frame's (potentially
46 // high) spectral flux inflates the running average, raising the
47 // threshold at the exact moment we need it lowest (onset detection).
48 mBeatDetected = detectBeat(timestamp);
49
50 // Update adaptive threshold AFTER beat detection
52
53 if (mBeatDetected) {
54 updateTempo(timestamp);
55 mLastBeatTime = timestamp;
56 }
57
58 // Update phase regardless of beat detection
59 updatePhase(timestamp);
60
61 // Update previous magnitudes for next frame
62 for (size i = 0; i < fft.raw().size() && i < mPreviousMagnitudes.size(); i++) {
63 mPreviousMagnitudes[i] = fft.raw()[i];
64 }
65}
AudioAnalyzeFFT1024 fft
bool detectBeat(u32 timestamp)
Definition beat.cpp.hpp:110
float calculateSpectralFlux(const fft::Bins &fft)
Definition beat.cpp.hpp:80
vector< float > mPreviousMagnitudes
Definition beat.h:51
shared_ptr< const fft::Bins > mRetainedFFT
Definition beat.h:65
void updateTempo(u32 timestamp)
Definition beat.cpp.hpp:138
void updatePhase(u32 timestamp)
Definition beat.cpp.hpp:161
static float DefaultMaxFrequency() FL_NOEXCEPT
Definition fft.h:128

References Beat(), calculateSpectralFlux(), fl::audio::fft::CQ_NAIVE, fl::audio::fft::Args::DefaultMaxFrequency(), detectBeat(), mBeatDetected, mLastBeatTime, mPreviousMagnitudes, mRetainedFFT, mSpectralFlux, update(), updateAdaptiveThreshold(), updatePhase(), and updateTempo().

Referenced by ~Beat(), and update().

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