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

◆ smoothResults()

void fl::AudioReactive::smoothResults ( )
private

Definition at line 306 of file audio_reactive.cpp.

306 {
307 // Attack/decay smoothing - different rates for rising vs falling values
308 // Convert attack/decay times to smoothing factors
309 // Shorter times = less smoothing (faster response)
310 float attackFactor = 1.0f - (mConfig.attack / 255.0f * 0.9f); // Range: 0.1 to 1.0
311 float decayFactor = 1.0f - (mConfig.decay / 255.0f * 0.95f); // Range: 0.05 to 1.0
312
313 // Apply attack/decay smoothing to volume
314 if (mCurrentData.volume > mSmoothedData.volume) {
315 // Rising - use attack time (faster response)
316 mSmoothedData.volume = mSmoothedData.volume * (1.0f - attackFactor) +
317 mCurrentData.volume * attackFactor;
318 } else {
319 // Falling - use decay time (slower response)
320 mSmoothedData.volume = mSmoothedData.volume * (1.0f - decayFactor) +
321 mCurrentData.volume * decayFactor;
322 }
323
324 // Apply attack/decay smoothing to volumeRaw
325 if (mCurrentData.volumeRaw > mSmoothedData.volumeRaw) {
326 mSmoothedData.volumeRaw = mSmoothedData.volumeRaw * (1.0f - attackFactor) +
327 mCurrentData.volumeRaw * attackFactor;
328 } else {
329 mSmoothedData.volumeRaw = mSmoothedData.volumeRaw * (1.0f - decayFactor) +
330 mCurrentData.volumeRaw * decayFactor;
331 }
332
333 // Apply attack/decay smoothing to peak
334 if (mCurrentData.peak > mSmoothedData.peak) {
335 mSmoothedData.peak = mSmoothedData.peak * (1.0f - attackFactor) +
336 mCurrentData.peak * attackFactor;
337 } else {
338 mSmoothedData.peak = mSmoothedData.peak * (1.0f - decayFactor) +
339 mCurrentData.peak * decayFactor;
340 }
341
342 // Apply attack/decay smoothing to frequency bins
343 for (int i = 0; i < 16; ++i) {
344 if (mCurrentData.frequencyBins[i] > mSmoothedData.frequencyBins[i]) {
345 // Rising - use attack time
346 mSmoothedData.frequencyBins[i] = mSmoothedData.frequencyBins[i] * (1.0f - attackFactor) +
347 mCurrentData.frequencyBins[i] * attackFactor;
348 } else {
349 // Falling - use decay time
350 mSmoothedData.frequencyBins[i] = mSmoothedData.frequencyBins[i] * (1.0f - decayFactor) +
351 mCurrentData.frequencyBins[i] * decayFactor;
352 }
353 }
354
355 // Copy non-smoothed values
356 mSmoothedData.beatDetected = mCurrentData.beatDetected;
357 mSmoothedData.dominantFrequency = mCurrentData.dominantFrequency;
358 mSmoothedData.magnitude = mCurrentData.magnitude;
359 mSmoothedData.timestamp = mCurrentData.timestamp;
360}
AudioReactiveConfig mConfig

References mConfig, mCurrentData, and mSmoothedData.

Referenced by processSample(), and update().

+ Here is the caller graph for this function: