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

◆ smoothResults()

void fl::audio::Reactive::smoothResults ( )
private

Definition at line 456 of file audio_reactive.cpp.hpp.

456 {
457 // Attack/decay smoothing - different rates for rising vs falling values
458 // Convert attack/decay times to smoothing factors
459 // Shorter times = less smoothing (faster response)
460 float attackFactor = 1.0f - (mConfig.attack / 255.0f * 0.9f); // Range: 0.1 to 1.0
461 float decayFactor = 1.0f - (mConfig.decay / 255.0f * 0.95f); // Range: 0.05 to 1.0
462
463 // volume is already adaptively smoothed by EnergyAnalyzer — copy directly
464 // to avoid double-smoothing which would make it sluggish.
465 mSmoothedData.volume = mCurrentData.volume;
466
467 // Apply attack/decay smoothing to volumeRaw
468 if (mCurrentData.volumeRaw > mSmoothedData.volumeRaw) {
469 mSmoothedData.volumeRaw = mSmoothedData.volumeRaw * (1.0f - attackFactor) +
470 mCurrentData.volumeRaw * attackFactor;
471 } else {
472 mSmoothedData.volumeRaw = mSmoothedData.volumeRaw * (1.0f - decayFactor) +
473 mCurrentData.volumeRaw * decayFactor;
474 }
475
476 // Apply attack/decay smoothing to peak
477 if (mCurrentData.peak > mSmoothedData.peak) {
478 mSmoothedData.peak = mSmoothedData.peak * (1.0f - attackFactor) +
479 mCurrentData.peak * attackFactor;
480 } else {
481 mSmoothedData.peak = mSmoothedData.peak * (1.0f - decayFactor) +
482 mCurrentData.peak * decayFactor;
483 }
484
485 // Apply attack/decay smoothing to frequency bins
486 for (int i = 0; i < 16; ++i) {
487 if (mCurrentData.frequencyBins[i] > mSmoothedData.frequencyBins[i]) {
488 // Rising - use attack time
489 mSmoothedData.frequencyBins[i] = mSmoothedData.frequencyBins[i] * (1.0f - attackFactor) +
490 mCurrentData.frequencyBins[i] * attackFactor;
491 } else {
492 // Falling - use decay time
493 mSmoothedData.frequencyBins[i] = mSmoothedData.frequencyBins[i] * (1.0f - decayFactor) +
494 mCurrentData.frequencyBins[i] * decayFactor;
495 }
496 }
497
498 // Copy non-smoothed values
499 mSmoothedData.beatDetected = mCurrentData.beatDetected;
500 mSmoothedData.dominantFrequency = mCurrentData.dominantFrequency;
501 mSmoothedData.magnitude = mCurrentData.magnitude;
502 mSmoothedData.timestamp = mCurrentData.timestamp;
503
504 // Copy enhanced beat detection fields
505 mSmoothedData.bassBeatDetected = mCurrentData.bassBeatDetected;
506 mSmoothedData.midBeatDetected = mCurrentData.midBeatDetected;
507 mSmoothedData.trebleBeatDetected = mCurrentData.trebleBeatDetected;
508 mSmoothedData.spectralFlux = mCurrentData.spectralFlux;
509 mSmoothedData.bassEnergy = mCurrentData.bassEnergy;
510 mSmoothedData.midEnergy = mCurrentData.midEnergy;
511 mSmoothedData.trebleEnergy = mCurrentData.trebleEnergy;
512}
ReactiveConfig mConfig

References mConfig, mCurrentData, and mSmoothedData.

Referenced by processSample(), and update().

+ Here is the caller graph for this function: