46 float ibiSeconds =
static_cast<float>(ibiFrames *
mConfig.samplesPerFrame) /
47 static_cast<float>(
mConfig.sampleRate);
100 float avgFrames =
static_cast<float>(sum) /
static_cast<float>(
mIBIHistory.size());
101 return (avgFrames *
static_cast<float>(
mConfig.samplesPerFrame)) /
102 static_cast<float>(
mConfig.sampleRate);
115 mStats.validatedBeats = 0;
116 mStats.rejectedOnsets = 0;
130 float expectedFrames = (expectedIBI *
static_cast<float>(
mConfig.sampleRate)) /
131 static_cast<float>(
mConfig.samplesPerFrame);
137 float tolerance = 0.25f;
138 float minExpected = expectedFrames * (1.0f - tolerance);
139 float maxExpected = expectedFrames * (1.0f + tolerance);
143 float actualIBI = (actualFrames *
static_cast<float>(
mConfig.samplesPerFrame)) /
144 static_cast<float>(
mConfig.sampleRate);
149 return (actualFrames >= minExpected) && (actualFrames <= maxExpected);
166 float cv = (avgIBI > 0.0f) ? (stdDev / avgIBI) : 1.0f;
172 float confidence =
fl::max(0.0f, 1.0f - (cv * 2.0f));
175 float ibiDiff =
fl::abs(currentIBI - avgIBI);
176 float ibiError = (avgIBI > 0.0f) ? (ibiDiff / avgIBI) : 1.0f;
177 float ibiBonus =
fl::max(0.0f, 1.0f - (ibiError * 4.0f));
180 return (confidence * 0.7f) + (ibiBonus * 0.3f);
190 if (avgIBI <= 0.0f) {
194 float instantaneousBPM = 60.0f / avgIBI;
200 float alpha =
mConfig.bpmSmoothingAlpha;
213 float bpm = 60.0f / ibi;
229 float mean =
static_cast<float>(sum) /
static_cast<float>(
mIBIHistory.size());
232 float variance = 0.0f;
234 float diff =
static_cast<float>(
mIBIHistory[i]) - mean;
235 variance += diff * diff;
237 variance /=
static_cast<float>(
mIBIHistory.size());
240 float stdDevFrames =
fl::sqrt(variance);
241 return (stdDevFrames *
static_cast<float>(
mConfig.samplesPerFrame)) /
242 static_cast<float>(
mConfig.sampleRate);
deque< u32 > mIBIHistory
Inter-beat interval history (in frames)
float mAverageIBI
Average inter-beat interval (in frames)
bool validateBeat(float onsetStrength) FL_NO_EXCEPT
Validate if an onset is a true musical beat.
void configure(const MusicalBeatDetectorConfig &config) FL_NO_EXCEPT
Configure the beat detector.
float getBeatConfidence() const FL_NO_EXCEPT
Get beat confidence for the last detected beat.
bool mBeatDetected
Last beat was detected.
float mCurrentBPM
Current BPM estimate (smoothed)
void processSample(bool onsetDetected, float onsetStrength) FL_NO_EXCEPT
Process one audio frame.
void reset() FL_NO_EXCEPT
Reset internal state (clear history, reset BPM)
void updateBPMEstimate() FL_NO_EXCEPT
Update BPM estimate from inter-beat intervals.
float getBPM() const FL_NO_EXCEPT
Get current BPM estimate.
float mLastBeatConfidence
Last beat confidence score.
float calculateIBIStdDev() const FL_NO_EXCEPT
Calculate standard deviation of IBI history.
u32 mCurrentFrame
Current frame counter.
~MusicalBeat() FL_NO_EXCEPT
bool isBeat() const FL_NO_EXCEPT
Check if a musical beat was detected in the last frame.
u32 mLastBeatFrame
Last beat timestamp (in frames)
float getAverageIBI() const FL_NO_EXCEPT
Get inter-beat interval (IBI) statistics.
MusicalBeat() FL_NO_EXCEPT
bool isValidIBI(float ibi) const FL_NO_EXCEPT
Check if IBI is within valid BPM range.
float calculateBeatConfidence(float currentIBI) FL_NO_EXCEPT
Calculate beat confidence based on rhythmic consistency.
MusicalBeatDetectorConfig mConfig
Configuration for musical beat detection.
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NO_EXCEPT
Base definition for an LED controller.