Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: webrtc/modules/audio_processing/aec3/suppression_gain.cc

Issue 3003733002: Utilizing the AEC3 config struct for constants. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/aec3/suppression_gain.cc
diff --git a/webrtc/modules/audio_processing/aec3/suppression_gain.cc b/webrtc/modules/audio_processing/aec3/suppression_gain.cc
index a25f748edcced09b3c19496a401e400ba71119d1..64d01b135253ab2f5a616c9c8c75eec2c223ddf6 100644
--- a/webrtc/modules/audio_processing/aec3/suppression_gain.cc
+++ b/webrtc/modules/audio_processing/aec3/suppression_gain.cc
@@ -107,15 +107,17 @@ float UpperBandsGain(
return std::min(gain_below_8_khz, anti_howling_gain);
}
+} // namespace
+
// Limits the gain increase.
-void UpdateMaxGainIncrease(
+void SuppressionGain::UpdateMaxGainIncrease(
hlundin-webrtc 2017/08/23 14:52:22 I think you should avoid littering the h-file with
peah-webrtc 2017/08/24 07:00:52 Good suggestion. That makes sense, I'll do that.
size_t no_saturation_counter,
bool low_noise_render,
const std::array<float, kFftLengthBy2Plus1>& last_echo,
const std::array<float, kFftLengthBy2Plus1>& echo,
const std::array<float, kFftLengthBy2Plus1>& last_gain,
const std::array<float, kFftLengthBy2Plus1>& new_gain,
- std::array<float, kFftLengthBy2Plus1>* gain_increase) {
+ std::array<float, kFftLengthBy2Plus1>* gain_increase) const {
float max_increasing;
float max_decreasing;
float rate_increasing;
@@ -123,27 +125,28 @@ void UpdateMaxGainIncrease(
float min_increasing;
float min_decreasing;
+ auto& param = config_.param.gain_updates;
if (low_noise_render) {
- max_increasing = 8.f;
- max_decreasing = 8.f;
- rate_increasing = 2.f;
- rate_decreasing = 2.f;
- min_increasing = 4.f;
- min_decreasing = 4.f;
+ max_increasing = param.low_noise.max_inc;
+ max_decreasing = param.low_noise.max_dec;
+ rate_increasing = param.low_noise.rate_inc;
+ rate_decreasing = param.low_noise.rate_dec;
+ min_increasing = param.low_noise.min_inc;
+ min_decreasing = param.low_noise.min_dec;
} else if (no_saturation_counter > 10) {
- max_increasing = 4.f;
- max_decreasing = 4.f;
- rate_increasing = 2.f;
- rate_decreasing = 2.f;
- min_increasing = 1.2f;
- min_decreasing = 2.f;
+ max_increasing = param.normal.max_inc;
+ max_decreasing = param.normal.max_dec;
+ rate_increasing = param.normal.rate_inc;
+ rate_decreasing = param.normal.rate_dec;
+ min_increasing = param.normal.min_inc;
+ min_decreasing = param.normal.min_dec;
} else {
- max_increasing = 1.2f;
- max_decreasing = 1.2f;
- rate_increasing = 1.5f;
- rate_decreasing = 1.5f;
- min_increasing = 1.f;
- min_decreasing = 1.f;
+ max_increasing = param.saturation.max_inc;
+ max_decreasing = param.saturation.max_dec;
+ rate_increasing = param.saturation.rate_inc;
+ rate_decreasing = param.saturation.rate_dec;
+ min_increasing = param.saturation.min_inc;
+ min_decreasing = param.saturation.min_dec;
}
for (size_t k = 0; k < new_gain.size(); ++k) {
@@ -162,7 +165,7 @@ void UpdateMaxGainIncrease(
}
// Computes the gain to reduce the echo to a non audible level.
-void GainToNoAudibleEcho(
+void SuppressionGain::GainToNoAudibleEcho(
bool low_noise_render,
bool saturated_echo,
const std::array<float, kFftLengthBy2Plus1>& nearend,
@@ -171,17 +174,18 @@ void GainToNoAudibleEcho(
const std::array<float, kFftLengthBy2Plus1>& min_gain,
const std::array<float, kFftLengthBy2Plus1>& max_gain,
const std::array<float, kFftLengthBy2Plus1>& one_by_echo,
- std::array<float, kFftLengthBy2Plus1>* gain) {
- constexpr float kEchoMaskingMargin = 1.f / 100.f;
+ std::array<float, kFftLengthBy2Plus1>* gain) const {
const float nearend_masking_margin =
- low_noise_render ? 0.1f : (saturated_echo ? 0.001f : 0.01f);
+ low_noise_render ? 0.1f
+ : (saturated_echo ? config_.param.gain_mask.m2
+ : config_.param.gain_mask.m3);
for (size_t k = 0; k < gain->size(); ++k) {
RTC_DCHECK_LE(0.f, nearend_masking_margin * nearend[k]);
if (echo[k] <= nearend_masking_margin * nearend[k]) {
(*gain)[k] = 1.f;
} else {
- (*gain)[k] = kEchoMaskingMargin * masker[k] * one_by_echo[k];
+ (*gain)[k] = config_.param.gain_mask.m1 * masker[k] * one_by_echo[k];
}
(*gain)[k] = std::min(std::max((*gain)[k], min_gain[k]), max_gain[k]);
@@ -189,22 +193,23 @@ void GainToNoAudibleEcho(
}
// Computes the signal output power that masks the echo signal.
-void MaskingPower(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) {
+void SuppressionGain::MaskingPower(
+ 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) const {
std::array<float, kFftLengthBy2Plus1> side_band_masker;
for (size_t k = 0; k < gain.size(); ++k) {
side_band_masker[k] = nearend[k] * gain[k] + comfort_noise[k];
- (*masker)[k] = comfort_noise[k] + 0.1f * last_masker[k];
+ (*masker)[k] =
+ comfort_noise[k] + config_.param.gain_mask.m4 * last_masker[k];
}
for (size_t k = 1; k < gain.size() - 1; ++k) {
(*masker)[k] += 0.1f * (side_band_masker[k - 1] + side_band_masker[k + 1]);
}
}
-} // namespace
// TODO(peah): Add further optimizations, in particular for the divisions.
void SuppressionGain::LowerBandGain(
@@ -227,7 +232,9 @@ void SuppressionGain::LowerBandGain(
// Compute the minimum gain as the attenuating gain to put the signal just
// above the zero sample values.
std::array<float, kFftLengthBy2Plus1> min_gain;
- const float min_echo_power = low_noise_render ? 192.f : 64.f;
+ const float min_echo_power = low_noise_render
+ ? config_.param.thresholds.min_echo1
+ : config_.param.thresholds.min_echo2;
if (no_saturation_counter_ > 10) {
for (size_t k = 0; k < nearend.size(); ++k) {
const float denom = std::min(nearend[k], echo[k]);
@@ -243,7 +250,9 @@ void SuppressionGain::LowerBandGain(
std::array<float, kFftLengthBy2Plus1> max_gain;
for (size_t k = 0; k < gain->size(); ++k) {
max_gain[k] =
- std::min(std::max(last_gain_[k] * gain_increase_[k], 0.001f), 1.f);
+ std::min(std::max(last_gain_[k] * gain_increase_[k],
+ config_.param.gain_updates.floor_first_increase),
+ 1.f);
}
// Iteratively compute the gain required to attenuate the echo to a non
@@ -271,8 +280,10 @@ void SuppressionGain::LowerBandGain(
aec3::VectorMath(optimization_).Sqrt(*gain);
}
-SuppressionGain::SuppressionGain(Aec3Optimization optimization)
- : optimization_(optimization) {
+SuppressionGain::SuppressionGain(
+ const AudioProcessing::Config::EchoCanceller3& config,
+ Aec3Optimization optimization)
+ : optimization_(optimization), config_(config) {
last_gain_.fill(1.f);
last_masker_.fill(0.f);
gain_increase_.fill(1.f);

Powered by Google App Engine
This is Rietveld 408576698