| Index: webrtc/modules/audio_processing/agc/agc_manager_direct.cc
|
| diff --git a/webrtc/modules/audio_processing/agc/agc_manager_direct.cc b/webrtc/modules/audio_processing/agc/agc_manager_direct.cc
|
| index f8fc310c57569aa28dab3a1d440bcc09292f72e7..70a0e1f2b2d1339db45ea4e8b51e2b04310f5374 100644
|
| --- a/webrtc/modules/audio_processing/agc/agc_manager_direct.cc
|
| +++ b/webrtc/modules/audio_processing/agc/agc_manager_direct.cc
|
| @@ -27,8 +27,6 @@ namespace webrtc {
|
|
|
| namespace {
|
|
|
| -// Lowest the microphone level can be lowered due to clipping.
|
| -const int kClippedLevelMin = 170;
|
| // Amount the microphone level is lowered with every clipping event.
|
| const int kClippedLevelStep = 15;
|
| // Proportion of clipped samples required to declare a clipping event.
|
| @@ -115,7 +113,8 @@ class DebugFile {
|
|
|
| AgcManagerDirect::AgcManagerDirect(GainControl* gctrl,
|
| VolumeCallbacks* volume_callbacks,
|
| - int startup_min_level)
|
| + int startup_min_level,
|
| + int clipped_level_min)
|
| : agc_(new Agc()),
|
| gctrl_(gctrl),
|
| volume_callbacks_(volume_callbacks),
|
| @@ -130,14 +129,15 @@ AgcManagerDirect::AgcManagerDirect(GainControl* gctrl,
|
| check_volume_on_next_process_(true), // Check at startup.
|
| startup_(true),
|
| startup_min_level_(ClampLevel(startup_min_level)),
|
| + clipped_level_min_(clipped_level_min),
|
| file_preproc_(new DebugFile("agc_preproc.pcm")),
|
| - file_postproc_(new DebugFile("agc_postproc.pcm")) {
|
| -}
|
| + file_postproc_(new DebugFile("agc_postproc.pcm")) {}
|
|
|
| AgcManagerDirect::AgcManagerDirect(Agc* agc,
|
| GainControl* gctrl,
|
| VolumeCallbacks* volume_callbacks,
|
| - int startup_min_level)
|
| + int startup_min_level,
|
| + int clipped_level_min)
|
| : agc_(agc),
|
| gctrl_(gctrl),
|
| volume_callbacks_(volume_callbacks),
|
| @@ -152,9 +152,9 @@ AgcManagerDirect::AgcManagerDirect(Agc* agc,
|
| check_volume_on_next_process_(true), // Check at startup.
|
| startup_(true),
|
| startup_min_level_(ClampLevel(startup_min_level)),
|
| + clipped_level_min_(clipped_level_min),
|
| file_preproc_(new DebugFile("agc_preproc.pcm")),
|
| - file_postproc_(new DebugFile("agc_postproc.pcm")) {
|
| -}
|
| + file_postproc_(new DebugFile("agc_postproc.pcm")) {}
|
|
|
| AgcManagerDirect::~AgcManagerDirect() {}
|
|
|
| @@ -218,14 +218,14 @@ void AgcManagerDirect::AnalyzePreProcess(int16_t* audio,
|
| << clipped_ratio;
|
| // Always decrease the maximum level, even if the current level is below
|
| // threshold.
|
| - SetMaxLevel(std::max(kClippedLevelMin, max_level_ - kClippedLevelStep));
|
| + SetMaxLevel(std::max(clipped_level_min_, max_level_ - kClippedLevelStep));
|
| RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.AgcClippingAdjustmentAllowed",
|
| - level_ - kClippedLevelStep >= kClippedLevelMin);
|
| - if (level_ > kClippedLevelMin) {
|
| + level_ - kClippedLevelStep >= clipped_level_min_);
|
| + if (level_ > clipped_level_min_) {
|
| // Don't try to adjust the level if we're already below the limit. As
|
| // a consequence, if the user has brought the level above the limit, we
|
| // will still not react until the postproc updates the level.
|
| - SetLevel(std::max(kClippedLevelMin, level_ - kClippedLevelStep));
|
| + SetLevel(std::max(clipped_level_min_, level_ - kClippedLevelStep));
|
| // Reset the AGC since the level has changed.
|
| agc_->Reset();
|
| }
|
| @@ -301,13 +301,15 @@ void AgcManagerDirect::SetLevel(int new_level) {
|
| }
|
|
|
| void AgcManagerDirect::SetMaxLevel(int level) {
|
| - RTC_DCHECK_GE(level, kClippedLevelMin);
|
| + RTC_DCHECK_GE(level, clipped_level_min_);
|
| max_level_ = level;
|
| // Scale the |kSurplusCompressionGain| linearly across the restricted
|
| // level range.
|
| - max_compression_gain_ = kMaxCompressionGain + std::floor(
|
| - (1.f * kMaxMicLevel - max_level_) / (kMaxMicLevel - kClippedLevelMin) *
|
| - kSurplusCompressionGain + 0.5f);
|
| + max_compression_gain_ =
|
| + kMaxCompressionGain + std::floor((1.f * kMaxMicLevel - max_level_) /
|
| + (kMaxMicLevel - clipped_level_min_) *
|
| + kSurplusCompressionGain +
|
| + 0.5f);
|
| LOG(LS_INFO) << "[agc] max_level_=" << max_level_
|
| << ", max_compression_gain_=" << max_compression_gain_;
|
| }
|
|
|