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

◆ applyLoudnessCompensation()

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

Definition at line 734 of file audio_reactive.cpp.

734 {
735 // Calculate current loudness level
736 float currentLoudness = data.volume;
737
738 // Calculate compensation factor based on difference from reference
739 float compensationFactor = 1.0f;
740 if (currentLoudness < referenceLevel) {
741 // Boost quiet signals
742 compensationFactor = 1.0f + (referenceLevel - currentLoudness) / referenceLevel * 0.3f;
743 } else if (currentLoudness > referenceLevel * 1.5f) {
744 // Slightly reduce very loud signals
745 compensationFactor = 1.0f - (currentLoudness - referenceLevel * 1.5f) / (referenceLevel * 2.0f) * 0.2f;
746 }
747
748 // Apply compensation to frequency bins
749 for (int i = 0; i < 16; ++i) {
750 data.frequencyBins[i] *= compensationFactor;
751 }
752
753#if SKETCH_HAS_LOTS_OF_MEMORY
754 // Store in history for future adaptive compensation (not implemented yet)
755 // This would be used for more sophisticated dynamic range compensation
756#endif
757}

References fl::AudioData::frequencyBins, and fl::AudioData::volume.