AEC3: Removing old suppressor logic

This CL removes some of the unused code in the suppressor. The CL has
been tested for bit exactness.

Bug: webrtc:8671
Change-Id: I960f9445dfd109cf1d5790debb8758872b5b8d0d
Reviewed-on: https://webrtc-review.googlesource.com/95682
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24417}
This commit is contained in:
Gustaf Ullberg
2018-08-23 15:11:38 +02:00
committed by Commit Bot
parent 5a72a5ef2b
commit ecb2d5670d
2 changed files with 19 additions and 95 deletions

View File

@ -32,11 +32,6 @@
namespace webrtc { namespace webrtc {
namespace { namespace {
bool EnableTransparencyImprovements() {
return !field_trial::IsEnabled(
"WebRTC-Aec3TransparencyImprovementsKillSwitch");
}
bool EnableNewSuppression() { bool EnableNewSuppression() {
return !field_trial::IsEnabled("WebRTC-Aec3NewSuppressionKillSwitch"); return !field_trial::IsEnabled("WebRTC-Aec3NewSuppressionKillSwitch");
} }
@ -161,7 +156,6 @@ void GainToNoAudibleEchoFallback(
bool low_noise_render, bool low_noise_render,
bool saturated_echo, bool saturated_echo,
bool linear_echo_estimate, bool linear_echo_estimate,
bool enable_transparency_improvements,
const std::array<float, kFftLengthBy2Plus1>& nearend, const std::array<float, kFftLengthBy2Plus1>& nearend,
const std::array<float, kFftLengthBy2Plus1>& weighted_echo, const std::array<float, kFftLengthBy2Plus1>& weighted_echo,
const std::array<float, kFftLengthBy2Plus1>& masker, const std::array<float, kFftLengthBy2Plus1>& masker,
@ -183,10 +177,7 @@ void GainToNoAudibleEchoFallback(
RTC_DCHECK_GT(1.f, nearend_masking_margin); RTC_DCHECK_GT(1.f, nearend_masking_margin);
const float masker_margin = const float masker_margin =
linear_echo_estimate linear_echo_estimate ? config.gain_mask.m0 : config.gain_mask.m8;
? (enable_transparency_improvements ? config.gain_mask.m0
: config.gain_mask.m1)
: config.gain_mask.m8;
for (size_t k = 0; k < gain->size(); ++k) { for (size_t k = 0; k < gain->size(); ++k) {
// TODO(devicentepena): Experiment by removing the reverberation estimation // TODO(devicentepena): Experiment by removing the reverberation estimation
@ -213,54 +204,6 @@ void GainToNoAudibleEchoFallback(
// TODO(peah): Make adaptive to take the actual filter error into account. // TODO(peah): Make adaptive to take the actual filter error into account.
constexpr size_t kUpperAccurateBandPlus1 = 29; constexpr size_t kUpperAccurateBandPlus1 = 29;
// Computes the signal output power that masks the echo signal.
void MaskingPower(const EchoCanceller3Config& config,
bool enable_transparency_improvements,
const std::array<float, kFftLengthBy2Plus1>& nearend,
const std::array<float, kFftLengthBy2Plus1>& comfort_noise,
const std::array<float, kFftLengthBy2Plus1>& last_masker,
const std::array<float, kFftLengthBy2Plus1>& gain,
std::array<float, kFftLengthBy2Plus1>* masker) {
if (enable_transparency_improvements) {
std::copy(comfort_noise.begin(), comfort_noise.end(), masker->begin());
return;
}
// Apply masking over time.
float masking_factor = config.gain_mask.temporal_masking_lf;
auto limit = config.gain_mask.temporal_masking_lf_bands;
std::transform(
comfort_noise.begin(), comfort_noise.begin() + limit, last_masker.begin(),
masker->begin(),
[masking_factor](float a, float b) { return a + masking_factor * b; });
masking_factor = config.gain_mask.temporal_masking_hf;
std::transform(
comfort_noise.begin() + limit, comfort_noise.end(),
last_masker.begin() + limit, masker->begin() + limit,
[masking_factor](float a, float b) { return a + masking_factor * b; });
// Apply masking only between lower frequency bands.
std::array<float, kFftLengthBy2Plus1> side_band_masker;
float max_nearend_after_gain = 0.f;
for (size_t k = 0; k < gain.size(); ++k) {
const float nearend_after_gain = nearend[k] * gain[k];
max_nearend_after_gain =
std::max(max_nearend_after_gain, nearend_after_gain);
side_band_masker[k] = nearend_after_gain + comfort_noise[k];
}
RTC_DCHECK_LT(kUpperAccurateBandPlus1, gain.size());
for (size_t k = 1; k < kUpperAccurateBandPlus1; ++k) {
(*masker)[k] += config.gain_mask.m5 *
(side_band_masker[k - 1] + side_band_masker[k + 1]);
}
// Add full-band masking as a minimum value for the masker.
const float min_masker = max_nearend_after_gain * config.gain_mask.m6;
std::for_each(masker->begin(), masker->end(),
[min_masker](float& a) { a = std::max(a, min_masker); });
}
// Limits the gain in the frequencies for which the adaptive filter has not // Limits the gain in the frequencies for which the adaptive filter has not
// converged. Currently, these frequencies are not hardcoded to the frequencies // converged. Currently, these frequencies are not hardcoded to the frequencies
// which are typically not excited by speech. // which are typically not excited by speech.
@ -331,7 +274,6 @@ void SuppressionGain::LowerBandGain(
min_gain[k] = denom > 0.f ? min_echo_power / denom : 1.f; min_gain[k] = denom > 0.f ? min_echo_power / denom : 1.f;
min_gain[k] = std::min(min_gain[k], 1.f); min_gain[k] = std::min(min_gain[k], 1.f);
} }
if (enable_transparency_improvements_) {
for (size_t k = 0; k < 6; ++k) { for (size_t k = 0; k < 6; ++k) {
// Make sure the gains of the low frequencies do not decrease too // Make sure the gains of the low frequencies do not decrease too
// quickly after strong nearend. // quickly after strong nearend.
@ -342,7 +284,6 @@ void SuppressionGain::LowerBandGain(
min_gain[k] = std::min(min_gain[k], 1.f); min_gain[k] = std::min(min_gain[k], 1.f);
} }
} }
}
} else { } else {
min_gain.fill(0.f); min_gain.fill(0.f);
} }
@ -350,21 +291,12 @@ void SuppressionGain::LowerBandGain(
// Compute the maximum gain by limiting the gain increase from the previous // Compute the maximum gain by limiting the gain increase from the previous
// gain. // gain.
std::array<float, kFftLengthBy2Plus1> max_gain; std::array<float, kFftLengthBy2Plus1> max_gain;
if (enable_transparency_improvements_) {
for (size_t k = 0; k < gain->size(); ++k) { for (size_t k = 0; k < gain->size(); ++k) {
max_gain[k] = max_gain[k] =
std::min(std::max(last_gain_[k] * config_.gain_updates.max_inc_factor, std::min(std::max(last_gain_[k] * config_.gain_updates.max_inc_factor,
config_.gain_updates.floor_first_increase), config_.gain_updates.floor_first_increase),
1.f); 1.f);
} }
} else {
for (size_t k = 0; k < gain->size(); ++k) {
max_gain[k] =
std::min(std::max(last_gain_[k] * gain_increase_[k],
config_.gain_updates.floor_first_increase),
1.f);
}
}
// Iteratively compute the gain required to attenuate the echo to a non // Iteratively compute the gain required to attenuate the echo to a non
// noticeable level. // noticeable level.
@ -376,12 +308,11 @@ void SuppressionGain::LowerBandGain(
} else { } else {
gain->fill(0.f); gain->fill(0.f);
for (int k = 0; k < 2; ++k) { for (int k = 0; k < 2; ++k) {
MaskingPower(config_, enable_transparency_improvements_, nearend, std::copy(comfort_noise.begin(), comfort_noise.end(), masker.begin());
comfort_noise, last_masker_, *gain, &masker); GainToNoAudibleEchoFallback(config_, low_noise_render, saturated_echo,
GainToNoAudibleEchoFallback( linear_echo_estimate, nearend, weighted_echo,
config_, low_noise_render, saturated_echo, linear_echo_estimate, masker, min_gain, max_gain,
enable_transparency_improvements_, nearend, weighted_echo, masker, one_by_weighted_echo, gain);
min_gain, max_gain, one_by_weighted_echo, gain);
AdjustForExternalFilters(gain); AdjustForExternalFilters(gain);
} }
} }
@ -397,15 +328,12 @@ void SuppressionGain::LowerBandGain(
std::copy(nearend.begin(), nearend.end(), last_nearend_.begin()); std::copy(nearend.begin(), nearend.end(), last_nearend_.begin());
std::copy(weighted_echo.begin(), weighted_echo.end(), last_echo_.begin()); std::copy(weighted_echo.begin(), weighted_echo.end(), last_echo_.begin());
std::copy(gain->begin(), gain->end(), last_gain_.begin()); std::copy(gain->begin(), gain->end(), last_gain_.begin());
MaskingPower(config_, enable_transparency_improvements_, nearend,
comfort_noise, last_masker_, *gain, &last_masker_);
aec3::VectorMath(optimization_).Sqrt(*gain); aec3::VectorMath(optimization_).Sqrt(*gain);
// Debug outputs for the purpose of development and analysis. // Debug outputs for the purpose of development and analysis.
data_dumper_->DumpRaw("aec3_suppressor_min_gain", min_gain); data_dumper_->DumpRaw("aec3_suppressor_min_gain", min_gain);
data_dumper_->DumpRaw("aec3_suppressor_max_gain", max_gain); data_dumper_->DumpRaw("aec3_suppressor_max_gain", max_gain);
data_dumper_->DumpRaw("aec3_suppressor_masker", masker); data_dumper_->DumpRaw("aec3_suppressor_masker", masker);
data_dumper_->DumpRaw("aec3_suppressor_last_masker", last_masker_);
} }
SuppressionGain::SuppressionGain(const EchoCanceller3Config& config, SuppressionGain::SuppressionGain(const EchoCanceller3Config& config,
@ -417,14 +345,12 @@ SuppressionGain::SuppressionGain(const EchoCanceller3Config& config,
config_(config), config_(config),
state_change_duration_blocks_( state_change_duration_blocks_(
static_cast<int>(config_.filter.config_change_duration_blocks)), static_cast<int>(config_.filter.config_change_duration_blocks)),
enable_transparency_improvements_(EnableTransparencyImprovements()),
enable_new_suppression_(EnableNewSuppression()), enable_new_suppression_(EnableNewSuppression()),
moving_average_(kFftLengthBy2Plus1, moving_average_(kFftLengthBy2Plus1,
config.suppressor.nearend_average_blocks) { config.suppressor.nearend_average_blocks) {
RTC_DCHECK_LT(0, state_change_duration_blocks_); RTC_DCHECK_LT(0, state_change_duration_blocks_);
one_by_state_change_duration_blocks_ = 1.f / state_change_duration_blocks_; one_by_state_change_duration_blocks_ = 1.f / state_change_duration_blocks_;
last_gain_.fill(1.f); last_gain_.fill(1.f);
last_masker_.fill(0.f);
gain_increase_.fill(1.f); gain_increase_.fill(1.f);
last_nearend_.fill(0.f); last_nearend_.fill(0.f);
last_echo_.fill(0.f); last_echo_.fill(0.f);

View File

@ -83,7 +83,6 @@ class SuppressionGain {
const int state_change_duration_blocks_; const int state_change_duration_blocks_;
float one_by_state_change_duration_blocks_; float one_by_state_change_duration_blocks_;
std::array<float, kFftLengthBy2Plus1> last_gain_; std::array<float, kFftLengthBy2Plus1> last_gain_;
std::array<float, kFftLengthBy2Plus1> last_masker_;
std::array<float, kFftLengthBy2Plus1> gain_increase_; std::array<float, kFftLengthBy2Plus1> gain_increase_;
std::array<float, kFftLengthBy2Plus1> last_nearend_; std::array<float, kFftLengthBy2Plus1> last_nearend_;
std::array<float, kFftLengthBy2Plus1> last_echo_; std::array<float, kFftLengthBy2Plus1> last_echo_;
@ -93,7 +92,6 @@ class SuppressionGain {
LowNoiseRenderDetector low_render_detector_; LowNoiseRenderDetector low_render_detector_;
bool initial_state_ = true; bool initial_state_ = true;
int initial_state_change_counter_ = 0; int initial_state_change_counter_ = 0;
const bool enable_transparency_improvements_;
const bool enable_new_suppression_; const bool enable_new_suppression_;
aec3::MovingAverage moving_average_; aec3::MovingAverage moving_average_;