Further AGC refactoring in preparation for adding multichannel support
Bug: webrtc:10859 Change-Id: If7d58a615a365a0b0f7b49e0cc2392b9bd5e2a0c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159028 Commit-Queue: Per Åhgren <peah@webrtc.org> Reviewed-by: Sam Zackrisson <saza@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29736}
This commit is contained in:
@ -163,46 +163,28 @@ float ComputeClippedRatio(const float* const* audio,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
AgcManagerDirect::AgcManagerDirect(GainControl* gctrl,
|
|
||||||
VolumeCallbacks* volume_callbacks,
|
|
||||||
int startup_min_level,
|
|
||||||
int clipped_level_min,
|
|
||||||
bool use_agc2_level_estimation,
|
|
||||||
bool disable_digital_adaptive)
|
|
||||||
: AgcManagerDirect(use_agc2_level_estimation ? nullptr : new Agc(),
|
|
||||||
gctrl,
|
|
||||||
volume_callbacks,
|
|
||||||
startup_min_level,
|
|
||||||
clipped_level_min,
|
|
||||||
use_agc2_level_estimation,
|
|
||||||
disable_digital_adaptive) {
|
|
||||||
RTC_DCHECK(agc_);
|
|
||||||
}
|
|
||||||
|
|
||||||
AgcManagerDirect::AgcManagerDirect(Agc* agc,
|
AgcManagerDirect::AgcManagerDirect(Agc* agc,
|
||||||
GainControl* gctrl,
|
GainControl* gctrl,
|
||||||
VolumeCallbacks* volume_callbacks,
|
VolumeCallbacks* volume_callbacks,
|
||||||
int startup_min_level,
|
int startup_min_level,
|
||||||
int clipped_level_min)
|
int clipped_level_min)
|
||||||
: AgcManagerDirect(agc,
|
: AgcManagerDirect(gctrl,
|
||||||
gctrl,
|
|
||||||
volume_callbacks,
|
volume_callbacks,
|
||||||
startup_min_level,
|
startup_min_level,
|
||||||
clipped_level_min,
|
clipped_level_min,
|
||||||
false,
|
false,
|
||||||
false) {
|
false) {
|
||||||
RTC_DCHECK(agc_);
|
RTC_DCHECK(agc_);
|
||||||
|
agc_.reset(agc);
|
||||||
}
|
}
|
||||||
|
|
||||||
AgcManagerDirect::AgcManagerDirect(Agc* agc,
|
AgcManagerDirect::AgcManagerDirect(GainControl* gctrl,
|
||||||
GainControl* gctrl,
|
|
||||||
VolumeCallbacks* volume_callbacks,
|
VolumeCallbacks* volume_callbacks,
|
||||||
int startup_min_level,
|
int startup_min_level,
|
||||||
int clipped_level_min,
|
int clipped_level_min,
|
||||||
bool use_agc2_level_estimation,
|
bool use_agc2_level_estimation,
|
||||||
bool disable_digital_adaptive)
|
bool disable_digital_adaptive)
|
||||||
: data_dumper_(new ApmDataDumper(instance_counter_)),
|
: data_dumper_(new ApmDataDumper(instance_counter_)),
|
||||||
agc_(agc),
|
|
||||||
gctrl_(gctrl),
|
gctrl_(gctrl),
|
||||||
volume_callbacks_(volume_callbacks),
|
volume_callbacks_(volume_callbacks),
|
||||||
frames_since_clipped_(kClippedWaitFrames),
|
frames_since_clipped_(kClippedWaitFrames),
|
||||||
@ -216,16 +198,14 @@ AgcManagerDirect::AgcManagerDirect(Agc* agc,
|
|||||||
check_volume_on_next_process_(true), // Check at startup.
|
check_volume_on_next_process_(true), // Check at startup.
|
||||||
startup_(true),
|
startup_(true),
|
||||||
min_mic_level_(GetMinMicLevel()),
|
min_mic_level_(GetMinMicLevel()),
|
||||||
use_agc2_level_estimation_(use_agc2_level_estimation),
|
|
||||||
disable_digital_adaptive_(disable_digital_adaptive),
|
disable_digital_adaptive_(disable_digital_adaptive),
|
||||||
startup_min_level_(ClampLevel(startup_min_level, min_mic_level_)),
|
startup_min_level_(ClampLevel(startup_min_level, min_mic_level_)),
|
||||||
clipped_level_min_(clipped_level_min) {
|
clipped_level_min_(clipped_level_min) {
|
||||||
instance_counter_++;
|
instance_counter_++;
|
||||||
if (use_agc2_level_estimation_) {
|
if (use_agc2_level_estimation) {
|
||||||
RTC_DCHECK(!agc);
|
agc_ = std::make_unique<AdaptiveModeLevelEstimatorAgc>(data_dumper_.get());
|
||||||
agc_.reset(new AdaptiveModeLevelEstimatorAgc(data_dumper_.get()));
|
|
||||||
} else {
|
} else {
|
||||||
RTC_DCHECK(agc);
|
agc_ = std::make_unique<Agc>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,15 +84,6 @@ class AgcManagerDirect final {
|
|||||||
int startup_min_level,
|
int startup_min_level,
|
||||||
int clipped_level_min);
|
int clipped_level_min);
|
||||||
|
|
||||||
// Most general c-tor.
|
|
||||||
AgcManagerDirect(Agc* agc,
|
|
||||||
GainControl* gctrl,
|
|
||||||
VolumeCallbacks* volume_callbacks,
|
|
||||||
int startup_min_level,
|
|
||||||
int clipped_level_min,
|
|
||||||
bool use_agc2_level_estimation,
|
|
||||||
bool disable_digital_adaptive);
|
|
||||||
|
|
||||||
int min_mic_level() const { return min_mic_level_; }
|
int min_mic_level() const { return min_mic_level_; }
|
||||||
int startup_min_level() const { return startup_min_level_; }
|
int startup_min_level() const { return startup_min_level_; }
|
||||||
|
|
||||||
@ -127,7 +118,6 @@ class AgcManagerDirect final {
|
|||||||
bool check_volume_on_next_process_;
|
bool check_volume_on_next_process_;
|
||||||
bool startup_;
|
bool startup_;
|
||||||
const int min_mic_level_;
|
const int min_mic_level_;
|
||||||
const bool use_agc2_level_estimation_;
|
|
||||||
const bool disable_digital_adaptive_;
|
const bool disable_digital_adaptive_;
|
||||||
int startup_min_level_;
|
int startup_min_level_;
|
||||||
const int clipped_level_min_;
|
const int clipped_level_min_;
|
||||||
|
@ -695,8 +695,7 @@ TEST(AgcManagerDirectStandaloneTest, DisableDigitalDisablesDigital) {
|
|||||||
MockGainControl gctrl;
|
MockGainControl gctrl;
|
||||||
TestVolumeCallbacks volume;
|
TestVolumeCallbacks volume;
|
||||||
|
|
||||||
AgcManagerDirect manager(agc.release(), &gctrl, &volume, kInitialVolume,
|
AgcManagerDirect manager(&gctrl, &volume, kInitialVolume, kClippedMin,
|
||||||
kClippedMin,
|
|
||||||
/* use agc2 level estimation */ false,
|
/* use agc2 level estimation */ false,
|
||||||
/* disable digital adaptive */ true);
|
/* disable digital adaptive */ true);
|
||||||
|
|
||||||
@ -710,14 +709,14 @@ TEST(AgcManagerDirectStandaloneTest, DisableDigitalDisablesDigital) {
|
|||||||
|
|
||||||
TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperiment) {
|
TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperiment) {
|
||||||
auto agc_man = std::unique_ptr<AgcManagerDirect>(new AgcManagerDirect(
|
auto agc_man = std::unique_ptr<AgcManagerDirect>(new AgcManagerDirect(
|
||||||
nullptr, nullptr, nullptr, kInitialVolume, kClippedMin, true, true));
|
nullptr, nullptr, kInitialVolume, kClippedMin, true, true));
|
||||||
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
||||||
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
||||||
{
|
{
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
"WebRTC-Audio-AgcMinMicLevelExperiment/Disabled/");
|
"WebRTC-Audio-AgcMinMicLevelExperiment/Disabled/");
|
||||||
agc_man.reset(new AgcManagerDirect(
|
agc_man.reset(new AgcManagerDirect(nullptr, nullptr, kInitialVolume,
|
||||||
nullptr, nullptr, nullptr, kInitialVolume, kClippedMin, true, true));
|
kClippedMin, true, true));
|
||||||
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
||||||
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
||||||
}
|
}
|
||||||
@ -725,16 +724,16 @@ TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperiment) {
|
|||||||
// Valid range of field-trial parameter is [0,255].
|
// Valid range of field-trial parameter is [0,255].
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-256/");
|
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-256/");
|
||||||
agc_man.reset(new AgcManagerDirect(
|
agc_man.reset(new AgcManagerDirect(nullptr, nullptr, kInitialVolume,
|
||||||
nullptr, nullptr, nullptr, kInitialVolume, kClippedMin, true, true));
|
kClippedMin, true, true));
|
||||||
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
||||||
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled--1/");
|
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled--1/");
|
||||||
agc_man.reset(new AgcManagerDirect(
|
agc_man.reset(new AgcManagerDirect(nullptr, nullptr, kInitialVolume,
|
||||||
nullptr, nullptr, nullptr, kInitialVolume, kClippedMin, true, true));
|
kClippedMin, true, true));
|
||||||
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
EXPECT_EQ(agc_man->min_mic_level(), kMinMicLevel);
|
||||||
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
||||||
}
|
}
|
||||||
@ -744,8 +743,8 @@ TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperiment) {
|
|||||||
// be changed.
|
// be changed.
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
|
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
|
||||||
agc_man.reset(new AgcManagerDirect(
|
agc_man.reset(new AgcManagerDirect(nullptr, nullptr, kInitialVolume,
|
||||||
nullptr, nullptr, nullptr, kInitialVolume, kClippedMin, true, true));
|
kClippedMin, true, true));
|
||||||
EXPECT_EQ(agc_man->min_mic_level(), 50);
|
EXPECT_EQ(agc_man->min_mic_level(), 50);
|
||||||
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
EXPECT_EQ(agc_man->startup_min_level(), kInitialVolume);
|
||||||
}
|
}
|
||||||
@ -755,8 +754,8 @@ TEST(AgcManagerDirectStandaloneTest, AgcMinMicLevelExperiment) {
|
|||||||
// level set by the experiment.
|
// level set by the experiment.
|
||||||
test::ScopedFieldTrials field_trial(
|
test::ScopedFieldTrials field_trial(
|
||||||
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
|
"WebRTC-Audio-AgcMinMicLevelExperiment/Enabled-50/");
|
||||||
agc_man.reset(new AgcManagerDirect(nullptr, nullptr, nullptr, 30,
|
agc_man.reset(
|
||||||
kClippedMin, true, true));
|
new AgcManagerDirect(nullptr, nullptr, 30, kClippedMin, true, true));
|
||||||
EXPECT_EQ(agc_man->min_mic_level(), 50);
|
EXPECT_EQ(agc_man->min_mic_level(), 50);
|
||||||
EXPECT_EQ(agc_man->startup_min_level(), 50);
|
EXPECT_EQ(agc_man->startup_min_level(), 50);
|
||||||
}
|
}
|
||||||
|
@ -330,12 +330,10 @@ AudioProcessingImpl::AudioProcessingImpl(
|
|||||||
/* enabled= */ false,
|
/* enabled= */ false,
|
||||||
/* enabled_agc2_level_estimator= */ false,
|
/* enabled_agc2_level_estimator= */ false,
|
||||||
/* digital_adaptive_disabled= */ false,
|
/* digital_adaptive_disabled= */ false,
|
||||||
/* analyze_before_aec= */ false,
|
|
||||||
#else
|
#else
|
||||||
config.Get<ExperimentalAgc>().enabled,
|
config.Get<ExperimentalAgc>().enabled,
|
||||||
config.Get<ExperimentalAgc>().enabled_agc2_level_estimator,
|
config.Get<ExperimentalAgc>().enabled_agc2_level_estimator,
|
||||||
config.Get<ExperimentalAgc>().digital_adaptive_disabled,
|
config.Get<ExperimentalAgc>().digital_adaptive_disabled,
|
||||||
config.Get<ExperimentalAgc>().analyze_before_aec,
|
|
||||||
#endif
|
#endif
|
||||||
!field_trial::IsEnabled(
|
!field_trial::IsEnabled(
|
||||||
"WebRTC-ApmExperimentalMultiChannelRenderKillSwitch"),
|
"WebRTC-ApmExperimentalMultiChannelRenderKillSwitch"),
|
||||||
@ -1288,13 +1286,6 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
|
|||||||
submodules_.agc_manager->AnalyzePreProcess(
|
submodules_.agc_manager->AnalyzePreProcess(
|
||||||
capture_buffer->channels_const(), capture_buffer->num_channels(),
|
capture_buffer->channels_const(), capture_buffer->num_channels(),
|
||||||
capture_nonlocked_.capture_processing_format.num_frames());
|
capture_nonlocked_.capture_processing_format.num_frames());
|
||||||
|
|
||||||
if (constants_.use_experimental_agc_process_before_aec) {
|
|
||||||
submodules_.agc_manager->Process(
|
|
||||||
capture_buffer->channels_const()[0],
|
|
||||||
capture_nonlocked_.capture_processing_format.num_frames(),
|
|
||||||
capture_nonlocked_.capture_processing_format.sample_rate_hz());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (submodule_states_.CaptureMultiBandSubModulesActive() &&
|
if (submodule_states_.CaptureMultiBandSubModulesActive() &&
|
||||||
@ -1379,8 +1370,7 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (constants_.use_experimental_agc &&
|
if (constants_.use_experimental_agc &&
|
||||||
submodules_.gain_control->is_enabled() &&
|
submodules_.gain_control->is_enabled()) {
|
||||||
!constants_.use_experimental_agc_process_before_aec) {
|
|
||||||
submodules_.agc_manager->Process(
|
submodules_.agc_manager->Process(
|
||||||
capture_buffer->split_bands_const_f(0)[kBand0To8kHz],
|
capture_buffer->split_bands_const_f(0)[kBand0To8kHz],
|
||||||
capture_buffer->num_frames_per_band(), capture_nonlocked_.split_rate);
|
capture_buffer->num_frames_per_band(), capture_nonlocked_.split_rate);
|
||||||
|
@ -380,7 +380,6 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
bool use_experimental_agc,
|
bool use_experimental_agc,
|
||||||
bool use_experimental_agc_agc2_level_estimation,
|
bool use_experimental_agc_agc2_level_estimation,
|
||||||
bool use_experimental_agc_agc2_digital_adaptive,
|
bool use_experimental_agc_agc2_digital_adaptive,
|
||||||
bool use_experimental_agc_process_before_aec,
|
|
||||||
bool experimental_multi_channel_render_support,
|
bool experimental_multi_channel_render_support,
|
||||||
bool experimental_multi_channel_capture_support)
|
bool experimental_multi_channel_capture_support)
|
||||||
: agc_startup_min_volume(agc_startup_min_volume),
|
: agc_startup_min_volume(agc_startup_min_volume),
|
||||||
@ -390,8 +389,6 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
use_experimental_agc_agc2_level_estimation),
|
use_experimental_agc_agc2_level_estimation),
|
||||||
use_experimental_agc_agc2_digital_adaptive(
|
use_experimental_agc_agc2_digital_adaptive(
|
||||||
use_experimental_agc_agc2_digital_adaptive),
|
use_experimental_agc_agc2_digital_adaptive),
|
||||||
use_experimental_agc_process_before_aec(
|
|
||||||
use_experimental_agc_process_before_aec),
|
|
||||||
experimental_multi_channel_render_support(
|
experimental_multi_channel_render_support(
|
||||||
experimental_multi_channel_render_support),
|
experimental_multi_channel_render_support),
|
||||||
experimental_multi_channel_capture_support(
|
experimental_multi_channel_capture_support(
|
||||||
@ -401,7 +398,6 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
bool use_experimental_agc;
|
bool use_experimental_agc;
|
||||||
bool use_experimental_agc_agc2_level_estimation;
|
bool use_experimental_agc_agc2_level_estimation;
|
||||||
bool use_experimental_agc_agc2_digital_adaptive;
|
bool use_experimental_agc_agc2_digital_adaptive;
|
||||||
bool use_experimental_agc_process_before_aec;
|
|
||||||
bool experimental_multi_channel_render_support;
|
bool experimental_multi_channel_render_support;
|
||||||
bool experimental_multi_channel_capture_support;
|
bool experimental_multi_channel_capture_support;
|
||||||
} constants_;
|
} constants_;
|
||||||
|
@ -112,15 +112,20 @@ static constexpr int kClippedLevelMin = 70;
|
|||||||
struct ExperimentalAgc {
|
struct ExperimentalAgc {
|
||||||
ExperimentalAgc() = default;
|
ExperimentalAgc() = default;
|
||||||
explicit ExperimentalAgc(bool enabled) : enabled(enabled) {}
|
explicit ExperimentalAgc(bool enabled) : enabled(enabled) {}
|
||||||
|
ExperimentalAgc(bool enabled,
|
||||||
|
bool enabled_agc2_level_estimator,
|
||||||
|
bool digital_adaptive_disabled)
|
||||||
|
: enabled(enabled),
|
||||||
|
enabled_agc2_level_estimator(enabled_agc2_level_estimator),
|
||||||
|
digital_adaptive_disabled(digital_adaptive_disabled) {}
|
||||||
|
// Deprecated constructor: will be removed.
|
||||||
ExperimentalAgc(bool enabled,
|
ExperimentalAgc(bool enabled,
|
||||||
bool enabled_agc2_level_estimator,
|
bool enabled_agc2_level_estimator,
|
||||||
bool digital_adaptive_disabled,
|
bool digital_adaptive_disabled,
|
||||||
bool analyze_before_aec)
|
bool analyze_before_aec)
|
||||||
: enabled(enabled),
|
: enabled(enabled),
|
||||||
enabled_agc2_level_estimator(enabled_agc2_level_estimator),
|
enabled_agc2_level_estimator(enabled_agc2_level_estimator),
|
||||||
digital_adaptive_disabled(digital_adaptive_disabled),
|
digital_adaptive_disabled(digital_adaptive_disabled) {}
|
||||||
analyze_before_aec(analyze_before_aec) {}
|
|
||||||
|
|
||||||
ExperimentalAgc(bool enabled, int startup_min_volume)
|
ExperimentalAgc(bool enabled, int startup_min_volume)
|
||||||
: enabled(enabled), startup_min_volume(startup_min_volume) {}
|
: enabled(enabled), startup_min_volume(startup_min_volume) {}
|
||||||
ExperimentalAgc(bool enabled, int startup_min_volume, int clipped_level_min)
|
ExperimentalAgc(bool enabled, int startup_min_volume, int clipped_level_min)
|
||||||
@ -134,9 +139,6 @@ struct ExperimentalAgc {
|
|||||||
int clipped_level_min = kClippedLevelMin;
|
int clipped_level_min = kClippedLevelMin;
|
||||||
bool enabled_agc2_level_estimator = false;
|
bool enabled_agc2_level_estimator = false;
|
||||||
bool digital_adaptive_disabled = false;
|
bool digital_adaptive_disabled = false;
|
||||||
// 'analyze_before_aec' is an experimental flag. It is intended to be removed
|
|
||||||
// at some point.
|
|
||||||
bool analyze_before_aec = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Use to enable experimental noise suppression. It can be set in the
|
// Use to enable experimental noise suppression. It can be set in the
|
||||||
|
Reference in New Issue
Block a user