FastLED 3.9.15
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 isValidIBI(float ibi) const
Check if IBI is within valid BPM range.
float calculateBeatConfidence(float currentIBI)
Calculate beat confidence based on rhythmic consistency.
bool mBeatDetected
Last beat was detected.
float mCurrentBPM
Current BPM estimate (smoothed)
float mLastBeatConfidence
Last beat confidence score.
u32 mCurrentFrame
Current frame counter.
float getAverageIBI() const
Get inter-beat interval (IBI) statistics.
u32 mLastBeatFrame
Last beat timestamp (in frames)
bool validateBeat(float onsetStrength)
Validate if an onset is a true musical beat.
void updateBPMEstimate()
Update BPM estimate from inter-beat intervals.

References calculateBeatConfidence(), 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: