Corrected the aggregation of AGC choices and add fallback solution

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 <saza@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29931}
This commit is contained in:
Per Åhgren
2019-11-26 22:58:53 +01:00
committed by Commit Bot
parent 17e4c58318
commit 26cc5e650f
2 changed files with 23 additions and 6 deletions

View File

@ -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<int>(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<int>(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<int>(ch);
}
}
}
}

View File

@ -87,8 +87,8 @@ class AgcManagerDirect final {
void AggregateChannelLevels();
std::unique_ptr<ApmDataDumper> 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_;