xref: /aosp_15_r20/external/webrtc/api/audio/echo_canceller3_config.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef API_AUDIO_ECHO_CANCELLER3_CONFIG_H_
12 #define API_AUDIO_ECHO_CANCELLER3_CONFIG_H_
13 
14 #include <stddef.h>  // size_t
15 
16 #include "rtc_base/system/rtc_export.h"
17 
18 namespace webrtc {
19 
20 // Configuration struct for EchoCanceller3
21 struct RTC_EXPORT EchoCanceller3Config {
22   // Checks and updates the config parameters to lie within (mostly) reasonable
23   // ranges. Returns true if and only of the config did not need to be changed.
24   static bool Validate(EchoCanceller3Config* config);
25 
26   EchoCanceller3Config();
27   EchoCanceller3Config(const EchoCanceller3Config& e);
28   EchoCanceller3Config& operator=(const EchoCanceller3Config& other);
29 
30   struct Buffering {
31     size_t excess_render_detection_interval_blocks = 250;
32     size_t max_allowed_excess_render_blocks = 8;
33   } buffering;
34 
35   struct Delay {
36     Delay();
37     Delay(const Delay& e);
38     Delay& operator=(const Delay& e);
39     size_t default_delay = 5;
40     size_t down_sampling_factor = 4;
41     size_t num_filters = 5;
42     size_t delay_headroom_samples = 32;
43     size_t hysteresis_limit_blocks = 1;
44     size_t fixed_capture_delay_samples = 0;
45     float delay_estimate_smoothing = 0.7f;
46     float delay_estimate_smoothing_delay_found = 0.7f;
47     float delay_candidate_detection_threshold = 0.2f;
48     struct DelaySelectionThresholds {
49       int initial;
50       int converged;
51     } delay_selection_thresholds = {5, 20};
52     bool use_external_delay_estimator = false;
53     bool log_warning_on_delay_changes = false;
54     struct AlignmentMixing {
55       bool downmix;
56       bool adaptive_selection;
57       float activity_power_threshold;
58       bool prefer_first_two_channels;
59     };
60     AlignmentMixing render_alignment_mixing = {false, true, 10000.f, true};
61     AlignmentMixing capture_alignment_mixing = {false, true, 10000.f, false};
62     bool detect_pre_echo = true;
63   } delay;
64 
65   struct Filter {
66     struct RefinedConfiguration {
67       size_t length_blocks;
68       float leakage_converged;
69       float leakage_diverged;
70       float error_floor;
71       float error_ceil;
72       float noise_gate;
73     };
74 
75     struct CoarseConfiguration {
76       size_t length_blocks;
77       float rate;
78       float noise_gate;
79     };
80 
81     RefinedConfiguration refined = {13,     0.00005f, 0.05f,
82                                     0.001f, 2.f,      20075344.f};
83     CoarseConfiguration coarse = {13, 0.7f, 20075344.f};
84 
85     RefinedConfiguration refined_initial = {12,     0.005f, 0.5f,
86                                             0.001f, 2.f,    20075344.f};
87     CoarseConfiguration coarse_initial = {12, 0.9f, 20075344.f};
88 
89     size_t config_change_duration_blocks = 250;
90     float initial_state_seconds = 2.5f;
91     int coarse_reset_hangover_blocks = 25;
92     bool conservative_initial_phase = false;
93     bool enable_coarse_filter_output_usage = true;
94     bool use_linear_filter = true;
95     bool high_pass_filter_echo_reference = false;
96     bool export_linear_aec_output = false;
97   } filter;
98 
99   struct Erle {
100     float min = 1.f;
101     float max_l = 4.f;
102     float max_h = 1.5f;
103     bool onset_detection = true;
104     size_t num_sections = 1;
105     bool clamp_quality_estimate_to_zero = true;
106     bool clamp_quality_estimate_to_one = true;
107   } erle;
108 
109   struct EpStrength {
110     float default_gain = 1.f;
111     float default_len = 0.83f;
112     float nearend_len = 0.83f;
113     bool echo_can_saturate = true;
114     bool bounded_erl = false;
115     bool erle_onset_compensation_in_dominant_nearend = false;
116     bool use_conservative_tail_frequency_response = true;
117   } ep_strength;
118 
119   struct EchoAudibility {
120     float low_render_limit = 4 * 64.f;
121     float normal_render_limit = 64.f;
122     float floor_power = 2 * 64.f;
123     float audibility_threshold_lf = 10;
124     float audibility_threshold_mf = 10;
125     float audibility_threshold_hf = 10;
126     bool use_stationarity_properties = false;
127     bool use_stationarity_properties_at_init = false;
128   } echo_audibility;
129 
130   struct RenderLevels {
131     float active_render_limit = 100.f;
132     float poor_excitation_render_limit = 150.f;
133     float poor_excitation_render_limit_ds8 = 20.f;
134     float render_power_gain_db = 0.f;
135   } render_levels;
136 
137   struct EchoRemovalControl {
138     bool has_clock_drift = false;
139     bool linear_and_stable_echo_path = false;
140   } echo_removal_control;
141 
142   struct EchoModel {
143     EchoModel();
144     EchoModel(const EchoModel& e);
145     EchoModel& operator=(const EchoModel& e);
146     size_t noise_floor_hold = 50;
147     float min_noise_floor_power = 1638400.f;
148     float stationary_gate_slope = 10.f;
149     float noise_gate_power = 27509.42f;
150     float noise_gate_slope = 0.3f;
151     size_t render_pre_window_size = 1;
152     size_t render_post_window_size = 1;
153     bool model_reverb_in_nonlinear_mode = true;
154   } echo_model;
155 
156   struct ComfortNoise {
157     float noise_floor_dbfs = -96.03406f;
158   } comfort_noise;
159 
160   struct Suppressor {
161     Suppressor();
162     Suppressor(const Suppressor& e);
163     Suppressor& operator=(const Suppressor& e);
164 
165     size_t nearend_average_blocks = 4;
166 
167     struct MaskingThresholds {
168       MaskingThresholds(float enr_transparent,
169                         float enr_suppress,
170                         float emr_transparent);
171       MaskingThresholds(const MaskingThresholds& e);
172       MaskingThresholds& operator=(const MaskingThresholds& e);
173       float enr_transparent;
174       float enr_suppress;
175       float emr_transparent;
176     };
177 
178     struct Tuning {
179       Tuning(MaskingThresholds mask_lf,
180              MaskingThresholds mask_hf,
181              float max_inc_factor,
182              float max_dec_factor_lf);
183       Tuning(const Tuning& e);
184       Tuning& operator=(const Tuning& e);
185       MaskingThresholds mask_lf;
186       MaskingThresholds mask_hf;
187       float max_inc_factor;
188       float max_dec_factor_lf;
189     };
190 
191     Tuning normal_tuning = Tuning(MaskingThresholds(.3f, .4f, .3f),
192                                   MaskingThresholds(.07f, .1f, .3f),
193                                   2.0f,
194                                   0.25f);
195     Tuning nearend_tuning = Tuning(MaskingThresholds(1.09f, 1.1f, .3f),
196                                    MaskingThresholds(.1f, .3f, .3f),
197                                    2.0f,
198                                    0.25f);
199 
200     bool lf_smoothing_during_initial_phase = true;
201     int last_permanent_lf_smoothing_band = 0;
202     int last_lf_smoothing_band = 5;
203     int last_lf_band = 5;
204     int first_hf_band = 8;
205 
206     struct DominantNearendDetection {
207       float enr_threshold = .25f;
208       float enr_exit_threshold = 10.f;
209       float snr_threshold = 30.f;
210       int hold_duration = 50;
211       int trigger_threshold = 12;
212       bool use_during_initial_phase = true;
213       bool use_unbounded_echo_spectrum = true;
214     } dominant_nearend_detection;
215 
216     struct SubbandNearendDetection {
217       size_t nearend_average_blocks = 1;
218       struct SubbandRegion {
219         size_t low;
220         size_t high;
221       };
222       SubbandRegion subband1 = {1, 1};
223       SubbandRegion subband2 = {1, 1};
224       float nearend_threshold = 1.f;
225       float snr_threshold = 1.f;
226     } subband_nearend_detection;
227 
228     bool use_subband_nearend_detection = false;
229 
230     struct HighBandsSuppression {
231       float enr_threshold = 1.f;
232       float max_gain_during_echo = 1.f;
233       float anti_howling_activation_threshold = 400.f;
234       float anti_howling_gain = 1.f;
235     } high_bands_suppression;
236 
237     float floor_first_increase = 0.00001f;
238     bool conservative_hf_suppression = false;
239   } suppressor;
240 
241   struct MultiChannel {
242     bool detect_stereo_content = true;
243     float stereo_detection_threshold = 0.0f;
244     int stereo_detection_timeout_threshold_seconds = 300;
245     float stereo_detection_hysteresis_seconds = 2.0f;
246   } multi_channel;
247 };
248 }  // namespace webrtc
249 
250 #endif  // API_AUDIO_ECHO_CANCELLER3_CONFIG_H_
251