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

◆ applyLoudnessCompensation()

void fl::audio::PerceptualWeighting::applyLoudnessCompensation ( Data & data,
float referenceLevel ) const

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

934 {
935 // Calculate current loudness level from raw (non-adaptive) volume.
936 // data.volume is adaptive (converges to ~1.0) and cannot distinguish
937 // quiet from loud signals. volumeRaw preserves actual amplitude.
938 float currentLoudness = data.volumeRaw;
939
940 // Calculate compensation factor based on difference from reference
941 float compensationFactor = 1.0f;
942 if (currentLoudness < referenceLevel) {
943 // Boost quiet signals
944 compensationFactor = 1.0f + (referenceLevel - currentLoudness) / referenceLevel * 0.3f;
945 } else if (currentLoudness > referenceLevel * 1.5f) {
946 // Slightly reduce very loud signals
947 compensationFactor = 1.0f - (currentLoudness - referenceLevel * 1.5f) / (referenceLevel * 2.0f) * 0.2f;
948 }
949
950 // Apply compensation to frequency bins
951 for (int i = 0; i < 16; ++i) {
952 data.frequencyBins[i] *= compensationFactor;
953 }
954
955#if SKETCH_HAS_LARGE_MEMORY
956 // Store in history for future adaptive compensation (not implemented yet)
957 // This would be used for more sophisticated dynamic range compensation
958#endif
959}

References fl::audio::Data::frequencyBins, and fl::audio::Data::volumeRaw.

Referenced by ~PerceptualWeighting().

+ Here is the caller graph for this function: