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

◆ detectBeat()

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

Definition at line 184 of file audio_reactive.cpp.

184 {
185 // Need minimum time since last beat
186 if (currentTimeMs - mLastBeatTime < BEAT_COOLDOWN) {
187 mCurrentData.beatDetected = false;
188 return;
189 }
190
191 // Simple beat detection based on volume increase
192 float currentVolume = mCurrentData.volume;
193
194 // Beat detected if volume significantly increased
195 if (currentVolume > mPreviousVolume + mVolumeThreshold &&
196 currentVolume > 5.0f) { // Minimum volume threshold
197 mCurrentData.beatDetected = true;
198 mLastBeatTime = currentTimeMs;
199 } else {
200 mCurrentData.beatDetected = false;
201 }
202
203 // Update previous volume for next comparison using attack/decay
204 float beatAttackRate = mConfig.attack / 255.0f * 0.5f + 0.1f; // 0.1 to 0.6
205 float beatDecayRate = mConfig.decay / 255.0f * 0.3f + 0.05f; // 0.05 to 0.35
206
207 if (currentVolume > mPreviousVolume) {
208 // Rising volume - use attack rate (faster tracking)
209 mPreviousVolume = mPreviousVolume * (1.0f - beatAttackRate) + currentVolume * beatAttackRate;
210 } else {
211 // Falling volume - use decay rate (slower tracking)
212 mPreviousVolume = mPreviousVolume * (1.0f - beatDecayRate) + currentVolume * beatDecayRate;
213 }
214}
static constexpr fl::u32 BEAT_COOLDOWN
AudioConfig mConfig

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

Referenced by processSample().

+ Here is the caller graph for this function: