diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2013-09-25 18:43:55 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2013-09-26 12:55:10 -0700 |
commit | cd0c4683947231a7d3dc7811bedb75c5a965103c (patch) | |
tree | 3554110faa75566c437e0d4f5bf26cf7b2759f97 /media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp | |
parent | fed6292af65a0b97b583ecbd3c232b3811a3f37b (diff) | |
download | frameworks_av-cd0c4683947231a7d3dc7811bedb75c5a965103c.zip frameworks_av-cd0c4683947231a7d3dc7811bedb75c5a965103c.tar.gz frameworks_av-cd0c4683947231a7d3dc7811bedb75c5a965103c.tar.bz2 |
LoudnessEnhancer compatible with stereo imaging
Use a single compressor for both channels.
Envelope of signal is determined by looking at both channels.
Bug 8413913
Change-Id: Ia9b6f34923d2977c60a3352500b858dfa1fab33c
Diffstat (limited to 'media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp')
-rw-r--r-- | media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp b/media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp index 2bbd043..7bd068e 100644 --- a/media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp +++ b/media/libeffects/loudness/dsp/core/dynamic_range_compression.cpp @@ -102,5 +102,40 @@ float AdaptiveDynamicRangeCompression::Compress(float x) { return x; } +void AdaptiveDynamicRangeCompression::Compress(float *x1, float *x2) { + // Taking the maximum amplitude of both channels + const float max_abs_x = std::max(std::fabs(*x1), + std::max(std::fabs(*x2), kMinLogAbsValue)); + const float max_abs_x_dB = math::fast_log(max_abs_x); + // Subtract Threshold from log-encoded input to get the amount of overshoot + const float overshoot = max_abs_x_dB - knee_threshold_; + // Hard half-wave rectifier + const float rect = std::max(overshoot, 0.0f); + // Multiply rectified overshoot with slope + const float cv = rect * slope_; + const float prev_state = state_; + if (cv <= state_) { + state_ = alpha_attack_ * state_ + (1.0f - alpha_attack_) * cv; + } else { + state_ = alpha_release_ * state_ + (1.0f - alpha_release_) * cv; + } + compressor_gain_ *= + math::ExpApproximationViaTaylorExpansionOrder5(state_ - prev_state); + *x1 *= compressor_gain_; + if (*x1 > kFixedPointLimit) { + *x1 = kFixedPointLimit; + } + if (*x1 < -kFixedPointLimit) { + *x1 = -kFixedPointLimit; + } + *x2 *= compressor_gain_; + if (*x2 > kFixedPointLimit) { + *x2 = kFixedPointLimit; + } + if (*x2 < -kFixedPointLimit) { + *x2 = -kFixedPointLimit; + } +} + } // namespace le_fx |