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

◆ detectBeat()

void fl::AudioReactive::detectBeat ( fl::u32 currentTimeMs)
private

Definition at line 214 of file audio_reactive.cpp.

214 {
215 // Need minimum time since last beat
216 if (currentTimeMs - mLastBeatTime < BEAT_COOLDOWN) {
217 mCurrentData.beatDetected = false;
218 return;
219 }
220
221 // Simple beat detection based on volume increase
222 float currentVolume = mCurrentData.volume;
223
224 // Beat detected if volume significantly increased
225 if (currentVolume > mPreviousVolume + mVolumeThreshold &&
226 currentVolume > 5.0f) { // Minimum volume threshold
227 mCurrentData.beatDetected = true;
228 mLastBeatTime = currentTimeMs;
229 } else {
230 mCurrentData.beatDetected = false;
231 }
232
233 // Update previous volume for next comparison using attack/decay
234 float beatAttackRate = mConfig.attack / 255.0f * 0.5f + 0.1f; // 0.1 to 0.6
235 float beatDecayRate = mConfig.decay / 255.0f * 0.3f + 0.05f; // 0.05 to 0.35
236
237 if (currentVolume > mPreviousVolume) {
238 // Rising volume - use attack rate (faster tracking)
239 mPreviousVolume = mPreviousVolume * (1.0f - beatAttackRate) + currentVolume * beatAttackRate;
240 } else {
241 // Falling volume - use decay rate (slower tracking)
242 mPreviousVolume = mPreviousVolume * (1.0f - beatDecayRate) + currentVolume * beatDecayRate;
243 }
244}
AudioReactiveConfig mConfig
static constexpr fl::u32 BEAT_COOLDOWN

References BEAT_COOLDOWN, mConfig, mCurrentData, mLastBeatTime, mPreviousVolume, and mVolumeThreshold.

Referenced by processSample().

+ Here is the caller graph for this function: