FastLED 3.10.8
Loading...
Searching...
No Matches

◆ processSample()

void fl::audio::detector::MusicalBeat::processSample ( bool onsetDetected,
float onsetStrength )

Process one audio frame.

Parameters
onsetDetectedTrue if onset detector triggered
onsetStrengthOnset magnitude (spectral flux value)

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

25 {
26 mBeatDetected = false;
29
30 if (!onsetDetected) {
31 return;
32 }
33
34 mStats.totalOnsets++;
35
36 // Validate if this onset is a true musical beat
37 if (validateBeat(onsetStrength)) {
38 mBeatDetected = true;
39 mStats.validatedBeats++;
40
41 // Calculate inter-beat interval (IBI)
42 u32 ibiFrames = mCurrentFrame - mLastBeatFrame;
44
45 // Convert IBI from frames to seconds
46 float ibiSeconds = static_cast<float>(ibiFrames * mConfig.samplesPerFrame) /
47 static_cast<float>(mConfig.sampleRate);
48
49 // Validate IBI is within BPM range
50 if (isValidIBI(ibiSeconds)) {
51 // Add to history
52 if (mIBIHistory.size() >= mConfig.maxIBIHistory) {
53 // Remove oldest IBI
54 mIBIHistory.pop_front();
55 }
56 mIBIHistory.push_back(ibiFrames);
57
58 // Calculate beat confidence
60
61 // Update BPM estimate
63
64 // Update stats
65 mStats.currentBPM = mCurrentBPM;
66 mStats.averageIBI = getAverageIBI();
67 mStats.ibiCount = static_cast<u32>(mIBIHistory.size());
68 } else {
69 // IBI out of valid range - reject beat
70 mBeatDetected = false;
71 mStats.rejectedOnsets++;
72 }
73 } else {
74 mStats.rejectedOnsets++;
75 }
76}
deque< u32 > mIBIHistory
Inter-beat interval history (in frames)
bool validateBeat(float onsetStrength) FL_NO_EXCEPT
Validate if an onset is a true musical beat.
bool mBeatDetected
Last beat was detected.
float mCurrentBPM
Current BPM estimate (smoothed)
void updateBPMEstimate() FL_NO_EXCEPT
Update BPM estimate from inter-beat intervals.
float mLastBeatConfidence
Last beat confidence score.
u32 mCurrentFrame
Current frame counter.
u32 mLastBeatFrame
Last beat timestamp (in frames)
float getAverageIBI() const FL_NO_EXCEPT
Get inter-beat interval (IBI) statistics.
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.

References calculateBeatConfidence(), fl::FL_NO_EXCEPT, getAverageIBI(), isValidIBI(), mBeatDetected, mConfig, mCurrentBPM, mCurrentFrame, mIBIHistory, mLastBeatConfidence, mLastBeatFrame, mStats, updateBPMEstimate(), and validateBeat().

Referenced by ~MusicalBeat().

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