Skip to content

Commit

Permalink
Remove unused code in APM
Browse files Browse the repository at this point in the history
- The injection of the AGC2 level estimator into `AgcManagerDirect`
  is not used anymore
- `ExperimentalAgc::enabled_agc2_level_estimator` can also be removed
- 3 ctors of `ExperimentalAgc` are unused
- `AgcManagerDirectStandaloneTest::AgcMinMicLevelExperiment` can be
  split into separate unit tests (better code clarity)

Bug: webrtc:7494
Change-Id: I5843147c38cf7cb5ee484b0a72fe13dcf363efaf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/202025
Commit-Queue: Alessio Bazzica <[email protected]>
Reviewed-by: Per Åhgren <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33027}
  • Loading branch information
alebzk authored and Commit Bot committed Jan 18, 2021
1 parent 111a371 commit 42eef86
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 266 deletions.
1 change: 0 additions & 1 deletion modules/audio_processing/agc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ rtc_library("agc") {
"../../../rtc_base:safe_minmax",
"../../../system_wrappers:field_trial",
"../../../system_wrappers:metrics",
"../agc2:level_estimation_agc",
"../vad",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
Expand Down
15 changes: 3 additions & 12 deletions modules/audio_processing/agc/agc_manager_direct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "common_audio/include/audio_util.h"
#include "modules/audio_processing/agc/gain_control.h"
#include "modules/audio_processing/agc/gain_map_internal.h"
#include "modules/audio_processing/agc2/adaptive_mode_level_estimator_agc.h"
#include "rtc_base/atomic_ops.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
Expand Down Expand Up @@ -138,24 +137,18 @@ float ComputeClippedRatio(const float* const* audio,
MonoAgc::MonoAgc(ApmDataDumper* data_dumper,
int startup_min_level,
int clipped_level_min,
bool use_agc2_level_estimation,
bool disable_digital_adaptive,
int min_mic_level)
: min_mic_level_(min_mic_level),
disable_digital_adaptive_(disable_digital_adaptive),
agc_(std::make_unique<Agc>()),
max_level_(kMaxMicLevel),
max_compression_gain_(kMaxCompressionGain),
target_compression_(kDefaultCompressionGain),
compression_(target_compression_),
compression_accumulator_(compression_),
startup_min_level_(ClampLevel(startup_min_level, min_mic_level_)),
clipped_level_min_(clipped_level_min) {
if (use_agc2_level_estimation) {
agc_ = std::make_unique<AdaptiveModeLevelEstimatorAgc>(data_dumper);
} else {
agc_ = std::make_unique<Agc>();
}
}
clipped_level_min_(clipped_level_min) {}

MonoAgc::~MonoAgc() = default;

Expand Down Expand Up @@ -415,7 +408,6 @@ AgcManagerDirect::AgcManagerDirect(Agc* agc,
: AgcManagerDirect(/*num_capture_channels*/ 1,
startup_min_level,
clipped_level_min,
/*use_agc2_level_estimation*/ false,
/*disable_digital_adaptive*/ false,
sample_rate_hz) {
RTC_DCHECK(channel_agcs_[0]);
Expand All @@ -426,7 +418,6 @@ AgcManagerDirect::AgcManagerDirect(Agc* agc,
AgcManagerDirect::AgcManagerDirect(int num_capture_channels,
int startup_min_level,
int clipped_level_min,
bool use_agc2_level_estimation,
bool disable_digital_adaptive,
int sample_rate_hz)
: data_dumper_(
Expand All @@ -445,7 +436,7 @@ AgcManagerDirect::AgcManagerDirect(int num_capture_channels,

channel_agcs_[ch] = std::make_unique<MonoAgc>(
data_dumper_ch, startup_min_level, clipped_level_min,
use_agc2_level_estimation, disable_digital_adaptive_, min_mic_level);
disable_digital_adaptive_, min_mic_level);
}
RTC_DCHECK_LT(0, channel_agcs_.size());
channel_agcs_[0]->ActivateLogging();
Expand Down
12 changes: 10 additions & 2 deletions modules/audio_processing/agc/agc_manager_direct.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class AgcManagerDirect final {
AgcManagerDirect(int num_capture_channels,
int startup_min_level,
int clipped_level_min,
bool use_agc2_level_estimation,
bool disable_digital_adaptive,
int sample_rate_hz);

Expand Down Expand Up @@ -73,6 +72,16 @@ class AgcManagerDirect final {
DisableDigitalDisablesDigital);
FRIEND_TEST_ALL_PREFIXES(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperiment);
FRIEND_TEST_ALL_PREFIXES(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperimentDisabled);
FRIEND_TEST_ALL_PREFIXES(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperimentOutOfRangeAbove);
FRIEND_TEST_ALL_PREFIXES(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperimentOutOfRangeBelow);
FRIEND_TEST_ALL_PREFIXES(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperimentEnabled50);
FRIEND_TEST_ALL_PREFIXES(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperimentEnabledAboveStartupLevel);

// Dependency injection for testing. Don't delete |agc| as the memory is owned
// by the manager.
Expand Down Expand Up @@ -106,7 +115,6 @@ class MonoAgc {
MonoAgc(ApmDataDumper* data_dumper,
int startup_min_level,
int clipped_level_min,
bool use_agc2_level_estimation,
bool disable_digital_adaptive,
int min_mic_level);
~MonoAgc();
Expand Down
134 changes: 71 additions & 63 deletions modules/audio_processing/agc/agc_manager_direct_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class MockGainControl : public GainControl {
MOCK_METHOD(bool, stream_is_saturated, (), (const, override));
};

std::unique_ptr<AgcManagerDirect> CreateAgcManagerDirect(
int startup_min_level) {
return std::make_unique<AgcManagerDirect>(
/*num_capture_channels=*/1, startup_min_level, kClippedMin,
/*disable_digital_adaptive=*/true, kSampleRateHz);
}

} // namespace

class AgcManagerDirectTest : public ::testing::Test {
Expand Down Expand Up @@ -692,77 +699,78 @@ TEST_F(AgcManagerDirectTest, TakesNoActionOnZeroMicVolume) {
TEST(AgcManagerDirectStandaloneTest, DisableDigitalDisablesDigital) {
auto agc = std::unique_ptr<Agc>(new ::testing::NiceMock<MockAgc>());
MockGainControl gctrl;
AgcManagerDirect manager(/* num_capture_channels */ 1, kInitialVolume,
kClippedMin,
/* use agc2 level estimation */ false,
/* disable digital adaptive */ true, kSampleRateHz);

EXPECT_CALL(gctrl, set_mode(GainControl::kFixedDigital));
EXPECT_CALL(gctrl, set_target_level_dbfs(0));
EXPECT_CALL(gctrl, set_compression_gain_db(0));
EXPECT_CALL(gctrl, enable_limiter(false));

manager.Initialize();
manager.SetupDigitalGainControl(&gctrl);
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(kInitialVolume);
manager->Initialize();
manager->SetupDigitalGainControl(&gctrl);
}

TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperiment) {
auto agc_man = std::unique_ptr<AgcManagerDirect>(new AgcManagerDirect(
/* num_capture_channels */ 1, kInitialVolume, kClippedMin, true, true,
kSampleRateHz));
EXPECT_EQ(agc_man->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(agc_man->channel_agcs_[0]->startup_min_level(), kInitialVolume);
{
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Disabled/");
agc_man.reset(new AgcManagerDirect(
/* num_capture_channels */ 1, kInitialVolume, kClippedMin, true, true,
kSampleRateHz));
EXPECT_EQ(agc_man->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(agc_man->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}
{
// Valid range of field-trial parameter is [0,255].
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-256/");
agc_man.reset(new AgcManagerDirect(
/* num_capture_channels */ 1, kInitialVolume, kClippedMin, true, true,
kSampleRateHz));
EXPECT_EQ(agc_man->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(agc_man->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}
{
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled--1/");
agc_man.reset(new AgcManagerDirect(
/* num_capture_channels */ 1, kInitialVolume, kClippedMin, true, true,
kSampleRateHz));
EXPECT_EQ(agc_man->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(agc_man->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}
{
// Verify that a valid experiment changes the minimum microphone level.
// The start volume is larger than the min level and should therefore not
// be changed.
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
agc_man.reset(new AgcManagerDirect(
/* num_capture_channels */ 1, kInitialVolume, kClippedMin, true, true,
kSampleRateHz));
EXPECT_EQ(agc_man->channel_agcs_[0]->min_mic_level(), 50);
EXPECT_EQ(agc_man->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}
{
// Use experiment to reduce the default minimum microphone level, start at
// a lower level and ensure that the startup level is increased to the min
// level set by the experiment.
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
agc_man.reset(new AgcManagerDirect(/* num_capture_channels */ 1, 30,
kClippedMin, true, true, kSampleRateHz));
EXPECT_EQ(agc_man->channel_agcs_[0]->min_mic_level(), 50);
EXPECT_EQ(agc_man->channel_agcs_[0]->startup_min_level(), 50);
}
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(kInitialVolume);
EXPECT_EQ(manager->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(manager->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}

TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperimentDisabled) {
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Disabled/");
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(kInitialVolume);
EXPECT_EQ(manager->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(manager->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}

// Checks that a field-trial parameter outside of the valid range [0,255] is
// ignored.
TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperimentOutOfRangeAbove) {
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-256/");
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(kInitialVolume);
EXPECT_EQ(manager->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(manager->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}

// Checks that a field-trial parameter outside of the valid range [0,255] is
// ignored.
TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperimentOutOfRangeBelow) {
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled--1/");
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(kInitialVolume);
EXPECT_EQ(manager->channel_agcs_[0]->min_mic_level(), kMinMicLevel);
EXPECT_EQ(manager->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}

// Verifies that a valid experiment changes the minimum microphone level. The
// start volume is larger than the min level and should therefore not be
// changed.
TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperimentEnabled50) {
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(kInitialVolume);
EXPECT_EQ(manager->channel_agcs_[0]->min_mic_level(), 50);
EXPECT_EQ(manager->channel_agcs_[0]->startup_min_level(), kInitialVolume);
}

// Uses experiment to reduce the default minimum microphone level, start at a
// lower level and ensure that the startup level is increased to the min level
// set by the experiment.
TEST(AgcManagerDirectStandaloneTest,
AgcMinMicLevelExperimentEnabledAboveStartupLevel) {
test::ScopedFieldTrials field_trial(
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
std::unique_ptr<AgcManagerDirect> manager =
CreateAgcManagerDirect(/*startup_min_level=*/30);
EXPECT_EQ(manager->channel_agcs_[0]->min_mic_level(), 50);
EXPECT_EQ(manager->channel_agcs_[0]->startup_min_level(), 50);
}

} // namespace webrtc
25 changes: 0 additions & 25 deletions modules/audio_processing/agc2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,6 @@ group("agc2") {
]
}

rtc_library("level_estimation_agc") {
sources = [
"adaptive_mode_level_estimator_agc.cc",
"adaptive_mode_level_estimator_agc.h",
]
configs += [ "..:apm_debug_dump" ]
deps = [
":adaptive_digital",
":common",
":gain_applier",
":noise_level_estimator",
":rnn_vad_with_level",
"..:api",
"..:apm_logging",
"..:audio_frame_view",
"../../../api:array_view",
"../../../common_audio",
"../../../rtc_base:checks",
"../../../rtc_base:rtc_base_approved",
"../../../rtc_base:safe_minmax",
"../agc:level_estimation",
"../vad",
]
}

rtc_library("adaptive_digital") {
sources = [
"adaptive_agc.cc",
Expand Down
65 changes: 0 additions & 65 deletions modules/audio_processing/agc2/adaptive_mode_level_estimator_agc.cc

This file was deleted.

Loading

0 comments on commit 42eef86

Please sign in to comment.