diff --git a/api/audio/echo_canceller3_config.h b/api/audio/echo_canceller3_config.h index 5eb2fd2ed9..8ff5aca90a 100644 --- a/api/audio/echo_canceller3_config.h +++ b/api/audio/echo_canceller3_config.h @@ -186,6 +186,7 @@ struct RTC_EXPORT EchoCanceller3Config { float snr_threshold = 30.f; int hold_duration = 50; int trigger_threshold = 12; + bool use_during_initial_phase = true; } dominant_nearend_detection; struct HighBandsSuppression { diff --git a/modules/audio_processing/aec3/suppression_gain.cc b/modules/audio_processing/aec3/suppression_gain.cc index f3ea57ab8a..88cfc0a01e 100644 --- a/modules/audio_processing/aec3/suppression_gain.cc +++ b/modules/audio_processing/aec3/suppression_gain.cc @@ -338,7 +338,7 @@ void SuppressionGain::GetGain( // Update the state selection. dominant_nearend_detector_.Update(nearend_spectrum, residual_echo_spectrum, - comfort_noise_spectrum); + comfort_noise_spectrum, initial_state_); // Compute gain for the lower band. bool low_noise_render = low_render_detector_.Detect(render); @@ -400,12 +400,14 @@ SuppressionGain::DominantNearendDetector::DominantNearendDetector( enr_exit_threshold_(config.enr_exit_threshold), snr_threshold_(config.snr_threshold), hold_duration_(config.hold_duration), - trigger_threshold_(config.trigger_threshold) {} + trigger_threshold_(config.trigger_threshold), + use_during_initial_phase_(config.use_during_initial_phase) {} void SuppressionGain::DominantNearendDetector::Update( rtc::ArrayView nearend_spectrum, rtc::ArrayView residual_echo_spectrum, - rtc::ArrayView comfort_noise_spectrum) { + rtc::ArrayView comfort_noise_spectrum, + bool initial_state) { auto low_frequency_energy = [](rtc::ArrayView spectrum) { RTC_DCHECK_LE(16, spectrum.size()); return std::accumulate(spectrum.begin() + 1, spectrum.begin() + 16, 0.f); @@ -416,7 +418,8 @@ void SuppressionGain::DominantNearendDetector::Update( // Detect strong active nearend if the nearend is sufficiently stronger than // the echo and the nearend noise. - if (ne_sum > enr_threshold_ * echo_sum && + if ((!initial_state || use_during_initial_phase_) && + ne_sum > enr_threshold_ * echo_sum && ne_sum > snr_threshold_ * noise_sum) { if (++trigger_counter_ >= trigger_threshold_) { // After a period of strong active nearend activity, flag nearend mode. diff --git a/modules/audio_processing/aec3/suppression_gain.h b/modules/audio_processing/aec3/suppression_gain.h index 1d55647693..e74cd9632b 100644 --- a/modules/audio_processing/aec3/suppression_gain.h +++ b/modules/audio_processing/aec3/suppression_gain.h @@ -107,7 +107,8 @@ class SuppressionGain { // Updates the state selection based on latest spectral estimates. void Update(rtc::ArrayView nearend_spectrum, rtc::ArrayView residual_echo_spectrum, - rtc::ArrayView comfort_noise_spectrum); + rtc::ArrayView comfort_noise_spectrum, + bool initial_state); private: const float enr_threshold_; @@ -115,6 +116,7 @@ class SuppressionGain { const float snr_threshold_; const int hold_duration_; const int trigger_threshold_; + const bool use_during_initial_phase_; bool nearend_state_ = false; int trigger_counter_ = 0;