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_candidate_detection_threshold = 0.2f;
47     struct DelaySelectionThresholds {
48       int initial;
49       int converged;
50     } delay_selection_thresholds = {5, 20};
51     bool use_external_delay_estimator = false;
52     bool log_warning_on_delay_changes = false;
53     struct AlignmentMixing {
54       bool downmix;
55       bool adaptive_selection;
56       float activity_power_threshold;
57       bool prefer_first_two_channels;
58     };
59     AlignmentMixing render_alignment_mixing = {false, true, 10000.f, true};
60     AlignmentMixing capture_alignment_mixing = {false, true, 10000.f, false};
61   } delay;
62 
63   struct Filter {
64     struct RefinedConfiguration {
65       size_t length_blocks;
66       float leakage_converged;
67       float leakage_diverged;
68       float error_floor;
69       float error_ceil;
70       float noise_gate;
71     };
72 
73     struct CoarseConfiguration {
74       size_t length_blocks;
75       float rate;
76       float noise_gate;
77     };
78 
79     RefinedConfiguration refined = {13,     0.00005f, 0.05f,
80                                     0.001f, 2.f,      20075344.f};
81     CoarseConfiguration coarse = {13, 0.7f, 20075344.f};
82 
83     RefinedConfiguration refined_initial = {12,     0.005f, 0.5f,
84                                             0.001f, 2.f,    20075344.f};
85     CoarseConfiguration coarse_initial = {12, 0.9f, 20075344.f};
86 
87     size_t config_change_duration_blocks = 250;
88     float initial_state_seconds = 2.5f;
89     bool conservative_initial_phase = false;
90     bool enable_coarse_filter_output_usage = true;
91     bool use_linear_filter = true;
92     bool export_linear_aec_output = false;
93   } filter;
94 
95   struct Erle {
96     float min = 1.f;
97     float max_l = 4.f;
98     float max_h = 1.5f;
99     bool onset_detection = true;
100     size_t num_sections = 1;
101     bool clamp_quality_estimate_to_zero = true;
102     bool clamp_quality_estimate_to_one = true;
103   } erle;
104 
105   struct EpStrength {
106     float default_gain = 1.f;
107     float default_len = 0.83f;
108     bool echo_can_saturate = true;
109     bool bounded_erl = false;
110   } ep_strength;
111 
112   struct EchoAudibility {
113     float low_render_limit = 4 * 64.f;
114     float normal_render_limit = 64.f;
115     float floor_power = 2 * 64.f;
116     float audibility_threshold_lf = 10;
117     float audibility_threshold_mf = 10;
118     float audibility_threshold_hf = 10;
119     bool use_stationarity_properties = false;
120     bool use_stationarity_properties_at_init = false;
121   } echo_audibility;
122 
123   struct RenderLevels {
124     float active_render_limit = 100.f;
125     float poor_excitation_render_limit = 150.f;
126     float poor_excitation_render_limit_ds8 = 20.f;
127     float render_power_gain_db = 0.f;
128   } render_levels;
129 
130   struct EchoRemovalControl {
131     bool has_clock_drift = false;
132     bool linear_and_stable_echo_path = false;
133   } echo_removal_control;
134 
135   struct EchoModel {
136     EchoModel();
137     EchoModel(const EchoModel& e);
138     EchoModel& operator=(const EchoModel& e);
139     size_t noise_floor_hold = 50;
140     float min_noise_floor_power = 1638400.f;
141     float stationary_gate_slope = 10.f;
142     float noise_gate_power = 27509.42f;
143     float noise_gate_slope = 0.3f;
144     size_t render_pre_window_size = 1;
145     size_t render_post_window_size = 1;
146     bool model_reverb_in_nonlinear_mode = true;
147   } echo_model;
148 
149   struct ComfortNoise {
150     float noise_floor_dbfs = -96.03406f;
151   } comfort_noise;
152 
153   struct Suppressor {
154     Suppressor();
155     Suppressor(const Suppressor& e);
156     Suppressor& operator=(const Suppressor& e);
157 
158     size_t nearend_average_blocks = 4;
159 
160     struct MaskingThresholds {
161       MaskingThresholds(float enr_transparent,
162                         float enr_suppress,
163                         float emr_transparent);
164       MaskingThresholds(const MaskingThresholds& e);
165       MaskingThresholds& operator=(const MaskingThresholds& e);
166       float enr_transparent;
167       float enr_suppress;
168       float emr_transparent;
169     };
170 
171     struct Tuning {
172       Tuning(MaskingThresholds mask_lf,
173              MaskingThresholds mask_hf,
174              float max_inc_factor,
175              float max_dec_factor_lf);
176       Tuning(const Tuning& e);
177       Tuning& operator=(const Tuning& e);
178       MaskingThresholds mask_lf;
179       MaskingThresholds mask_hf;
180       float max_inc_factor;
181       float max_dec_factor_lf;
182     };
183 
184     Tuning normal_tuning = Tuning(MaskingThresholds(.3f, .4f, .3f),
185                                   MaskingThresholds(.07f, .1f, .3f),
186                                   2.0f,
187                                   0.25f);
188     Tuning nearend_tuning = Tuning(MaskingThresholds(1.09f, 1.1f, .3f),
189                                    MaskingThresholds(.1f, .3f, .3f),
190                                    2.0f,
191                                    0.25f);
192 
193     struct DominantNearendDetection {
194       float enr_threshold = .25f;
195       float enr_exit_threshold = 10.f;
196       float snr_threshold = 30.f;
197       int hold_duration = 50;
198       int trigger_threshold = 12;
199       bool use_during_initial_phase = true;
200     } dominant_nearend_detection;
201 
202     struct SubbandNearendDetection {
203       size_t nearend_average_blocks = 1;
204       struct SubbandRegion {
205         size_t low;
206         size_t high;
207       };
208       SubbandRegion subband1 = {1, 1};
209       SubbandRegion subband2 = {1, 1};
210       float nearend_threshold = 1.f;
211       float snr_threshold = 1.f;
212     } subband_nearend_detection;
213 
214     bool use_subband_nearend_detection = false;
215 
216     struct HighBandsSuppression {
217       float enr_threshold = 1.f;
218       float max_gain_during_echo = 1.f;
219       float anti_howling_activation_threshold = 400.f;
220       float anti_howling_gain = 1.f;
221     } high_bands_suppression;
222 
223     float floor_first_increase = 0.00001f;
224     bool conservative_hf_suppression = false;
225   } suppressor;
226 };
227 }  // namespace webrtc
228 
229 #endif  // API_AUDIO_ECHO_CANCELLER3_CONFIG_H_
230