AEC3: Add an AEC3 config specific to `NeuralResidualEchoEstimator`.

This change introduces a method in the `NeuralResidualEchoEstimator`
interface that allows the neural echo estimator to provide a specific
`EchoCanceller3Config`. The implementation in
`NeuralResidualEchoEstimatorImpl` returns a configuration with adjusted
suppressor and filter settings designed for use with the neural residual
echo estimator.

No-Iwyu: IWYU bot is confused by a pragma in TFLite c_api_types.h.
Change-Id: Ib4f46eff6653fc9e8bd1486c8ee84773d416c0f9
Bug: webrtc:442444736
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/413601
Reviewed-by: Jesus de Vicente Pena <devicentepena@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Simon Sondén (xWF) <sonden@google.com>
Cr-Commit-Position: refs/heads/main@{#45818}
diff --git a/api/audio/BUILD.gn b/api/audio/BUILD.gn
index 2537979..0a188a7 100644
--- a/api/audio/BUILD.gn
+++ b/api/audio/BUILD.gn
@@ -175,7 +175,10 @@
 rtc_source_set("neural_residual_echo_estimator_api") {
   visibility = [ "*" ]
   sources = [ "neural_residual_echo_estimator.h" ]
-  deps = [ "..:array_view" ]
+  deps = [
+    ":aec3_config",
+    "..:array_view",
+  ]
 }
 
 rtc_library("echo_detector_creator") {
diff --git a/api/audio/neural_residual_echo_estimator.h b/api/audio/neural_residual_echo_estimator.h
index 0f9f2b4..152bb12 100644
--- a/api/audio/neural_residual_echo_estimator.h
+++ b/api/audio/neural_residual_echo_estimator.h
@@ -14,6 +14,7 @@
 #include <array>
 
 #include "api/array_view.h"
+#include "api/audio/echo_canceller3_config.h"
 
 namespace webrtc {
 
@@ -24,6 +25,7 @@
 class NeuralResidualEchoEstimator {
  public:
   virtual ~NeuralResidualEchoEstimator() {}
+
   // Estimates residual echo power spectrum in the signal after linear AEC
   // subtraction. Returns two estimates:
   //   * R2: A conservative estimate.
@@ -46,6 +48,9 @@
                         ArrayView<const std::array<float, 65>> E2,
                         ArrayView<std::array<float, 65>> R2,
                         ArrayView<std::array<float, 65>> R2_unbounded) = 0;
+
+  // Returns a recommended AEC3 configuration for this estimator.
+  virtual EchoCanceller3Config GetConfiguration(bool multi_channel) const = 0;
 };
 }  // namespace webrtc
 
diff --git a/modules/audio_processing/aec3/BUILD.gn b/modules/audio_processing/aec3/BUILD.gn
index 93ff0fe..80c5175 100644
--- a/modules/audio_processing/aec3/BUILD.gn
+++ b/modules/audio_processing/aec3/BUILD.gn
@@ -314,6 +314,7 @@
       ":neural_residual_echo_estimator_proto",
       "..:apm_logging",
       "../../../api:array_view",
+      "../../../api/audio:aec3_config",
       "../../../api/audio:neural_residual_echo_estimator_api",
       "../../../common_audio",
       "../../../rtc_base:checks",
@@ -438,6 +439,7 @@
       deps += [
         ":neural_residual_echo_estimator_impl",
         ":neural_residual_echo_estimator_proto",
+        "../../../test:test_support",
       ]
     }
 
diff --git a/modules/audio_processing/aec3/echo_canceller3_unittest.cc b/modules/audio_processing/aec3/echo_canceller3_unittest.cc
index 4f1cbe4..92b75f2 100644
--- a/modules/audio_processing/aec3/echo_canceller3_unittest.cc
+++ b/modules/audio_processing/aec3/echo_canceller3_unittest.cc
@@ -11,6 +11,7 @@
 #include "modules/audio_processing/aec3/echo_canceller3.h"
 
 #include <algorithm>
+#include <array>
 #include <cstddef>
 #include <deque>
 #include <memory>
@@ -22,6 +23,7 @@
 #include "api/array_view.h"
 #include "api/audio/echo_canceller3_config.h"
 #include "api/audio/echo_control.h"
+#include "api/audio/neural_residual_echo_estimator.h"
 #include "api/environment/environment.h"
 #include "api/environment/environment_factory.h"
 #include "api/field_trials.h"
@@ -1188,6 +1190,10 @@
       return residual_echo_estimate_requested_;
     }
 
+    EchoCanceller3Config GetConfiguration(bool multi_channel) const override {
+      return EchoCanceller3Config();
+    }
+
    private:
     bool residual_echo_estimate_requested_ = false;
   };
diff --git a/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.cc b/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.cc
index 621f7d6..7501b2d 100644
--- a/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.cc
+++ b/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.cc
@@ -24,6 +24,7 @@
 
 #include "absl/strings/string_view.h"
 #include "api/array_view.h"
+#include "api/audio/echo_canceller3_config.h"
 #include "modules/audio_processing/aec3/aec3_common.h"
 #include "modules/audio_processing/aec3/neural_feature_extractor.h"
 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
@@ -369,6 +370,27 @@
   }
 }
 
+EchoCanceller3Config NeuralResidualEchoEstimatorImpl::GetConfiguration(
+    bool multi_channel) const {
+  EchoCanceller3Config config;
+  EchoCanceller3Config::Suppressor::MaskingThresholds tuning_masking_thresholds(
+      /*enr_transparent=*/0.0f, /*enr_suppress=*/1.0f,
+      /*emr_transparent=*/0.3f);
+  EchoCanceller3Config::Suppressor::Tuning tuning(
+      /*mask_lf=*/tuning_masking_thresholds,
+      /*mask_hf=*/tuning_masking_thresholds, /*max_inc_factor=*/100.0f,
+      /*max_dec_factor_lf=*/0.0f);
+  config.filter.enable_coarse_filter_output_usage = false;
+  config.suppressor.nearend_average_blocks = 1;
+  config.suppressor.normal_tuning = tuning;
+  config.suppressor.nearend_tuning = tuning;
+  config.suppressor.dominant_nearend_detection.enr_threshold = 0.5f;
+  config.suppressor.dominant_nearend_detection.trigger_threshold = 2;
+  config.suppressor.high_frequency_suppression.limiting_gain_band = 24;
+  config.suppressor.high_frequency_suppression.bands_in_limiting_gain = 3;
+  return config;
+}
+
 void NeuralResidualEchoEstimatorImpl::DumpInputs() {
   data_dumper_->DumpWav("ml_ree_mic_input", input_mic_buffer_, 16000, 1);
   data_dumper_->DumpWav("ml_ree_linear_aec_output",
diff --git a/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.h b/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.h
index 448102f..0514dc4 100644
--- a/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.h
+++ b/modules/audio_processing/aec3/neural_residual_echo_estimator_impl.h
@@ -17,6 +17,7 @@
 
 #include "absl/strings/string_view.h"
 #include "api/array_view.h"
+#include "api/audio/echo_canceller3_config.h"
 #include "api/audio/neural_residual_echo_estimator.h"
 #include "modules/audio_processing/aec3/aec3_common.h"
 #include "modules/audio_processing/aec3/neural_feature_extractor.h"
@@ -80,6 +81,8 @@
       webrtc::ArrayView<std::array<float, kFftLengthBy2Plus1>> R2_unbounded)
       override;
 
+  EchoCanceller3Config GetConfiguration(bool multi_channel) const override;
+
  private:
   void DumpInputs();