From 26cc5e650f15071ca200525e7a91285c48f81163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Tue, 26 Nov 2019 22:58:53 +0100 Subject: [PATCH] Corrected the aggregation of AGC choices and add fallback solution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL corrects the analog AGC code so that the levels are properly aggregated and not only the level of the first channel is chosen. It also adds a kill-switch to allow the aggrated level to be the maximum level rather than the minimum level. Bug: webrtc:10859 Change-Id: Ibf4fecb53cfaf0dc064c334112105bf26401f78d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160708 Reviewed-by: Sam Zackrisson Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#29931} --- .../agc/agc_manager_direct.cc | 27 +++++++++++++++---- .../audio_processing/agc/agc_manager_direct.h | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/modules/audio_processing/agc/agc_manager_direct.cc b/modules/audio_processing/agc/agc_manager_direct.cc index 6d0bb9a8b2..8af7c2d88b 100644 --- a/modules/audio_processing/agc/agc_manager_direct.cc +++ b/modules/audio_processing/agc/agc_manager_direct.cc @@ -56,6 +56,12 @@ const int kMaxResidualGainChange = 15; // restrictions from clipping events. const int kSurplusCompressionGain = 6; +// Returns whether a fall-back solution to choose the maximum level should be +// chosen. +bool UseMaxAnalogChannelLevel() { + return field_trial::IsEnabled("WebRTC-UseMaxAnalogAgcChannelLevel"); +} + // Returns kMinMicLevel if no field trial exists or if it has been disabled. // Returns a value between 0 and 255 depending on the field-trial string. // Example: 'WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-80' => returns 80. @@ -426,6 +432,7 @@ AgcManagerDirect::AgcManagerDirect(int num_capture_channels, int sample_rate_hz) : data_dumper_( new ApmDataDumper(rtc::AtomicOps::Increment(&instance_counter_))), + use_min_channel_level_(!UseMaxAnalogChannelLevel()), sample_rate_hz_(sample_rate_hz), num_capture_channels_(num_capture_channels), disable_digital_adaptive_(disable_digital_adaptive), @@ -579,11 +586,21 @@ void AgcManagerDirect::set_stream_analog_level(int level) { void AgcManagerDirect::AggregateChannelLevels() { stream_analog_level_ = channel_agcs_[0]->stream_analog_level(); channel_controlling_gain_ = 0; - for (size_t ch = 1; ch < channel_agcs_.size(); ++ch) { - int level = channel_agcs_[0]->stream_analog_level(); - if (level < stream_analog_level_) { - stream_analog_level_ = level; - channel_controlling_gain_ = static_cast(ch); + if (use_min_channel_level_) { + for (size_t ch = 1; ch < channel_agcs_.size(); ++ch) { + int level = channel_agcs_[ch]->stream_analog_level(); + if (level < stream_analog_level_) { + stream_analog_level_ = level; + channel_controlling_gain_ = static_cast(ch); + } + } + } else { + for (size_t ch = 1; ch < channel_agcs_.size(); ++ch) { + int level = channel_agcs_[ch]->stream_analog_level(); + if (level > stream_analog_level_) { + stream_analog_level_ = level; + channel_controlling_gain_ = static_cast(ch); + } } } } diff --git a/modules/audio_processing/agc/agc_manager_direct.h b/modules/audio_processing/agc/agc_manager_direct.h index 9502a7d82f..54eb867e3e 100644 --- a/modules/audio_processing/agc/agc_manager_direct.h +++ b/modules/audio_processing/agc/agc_manager_direct.h @@ -87,8 +87,8 @@ class AgcManagerDirect final { void AggregateChannelLevels(); std::unique_ptr data_dumper_; - static int instance_counter_; + const bool use_min_channel_level_; const int sample_rate_hz_; const int num_capture_channels_; const bool disable_digital_adaptive_;