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

◆ validateBeat()

bool fl::audio::detector::MusicalBeat::validateBeat ( float onsetStrength)
private

Validate if an onset is a true musical beat.

Parameters
onsetStrengthOnset magnitude
Returns
True if onset matches expected beat timing

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

122 {
123 // First beat always validates (no history to compare)
124 if (mLastBeatFrame == 0) {
125 return true;
126 }
127
128 // Calculate expected IBI based on current BPM
129 float expectedIBI = 60.0f / mCurrentBPM; // seconds per beat
130 float expectedFrames = (expectedIBI * static_cast<float>(mConfig.sampleRate)) /
131 static_cast<float>(mConfig.samplesPerFrame);
132
133 // Calculate actual IBI since last beat
134 float actualFrames = static_cast<float>(mCurrentFrame - mLastBeatFrame);
135
136 // Allow ±25% deviation from expected tempo
137 float tolerance = 0.25f;
138 float minExpected = expectedFrames * (1.0f - tolerance);
139 float maxExpected = expectedFrames * (1.0f + tolerance);
140
141 // If we have no IBI history yet, accept any beat within valid BPM range
142 if (mIBIHistory.empty()) {
143 float actualIBI = (actualFrames * static_cast<float>(mConfig.samplesPerFrame)) /
144 static_cast<float>(mConfig.sampleRate);
145 return isValidIBI(actualIBI);
146 }
147
148 // Validate timing matches expected tempo
149 return (actualFrames >= minExpected) && (actualFrames <= maxExpected);
150}
deque< u32 > mIBIHistory
Inter-beat interval history (in frames)
bool isValidIBI(float ibi) const
Check if IBI is within valid BPM range.
float mCurrentBPM
Current BPM estimate (smoothed)
u32 mCurrentFrame
Current frame counter.
u32 mLastBeatFrame
Last beat timestamp (in frames)

References isValidIBI(), mConfig, mCurrentBPM, mCurrentFrame, mIBIHistory, and mLastBeatFrame.

Referenced by processSample().

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