Debian Codegraph @

Xpjproject/third_party/webrtc_aec3/src/api/audio/echo_canceller3_config.cc

raw symbols SCIP
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 #include "api/audio/echo_canceller3_config.h"
11
12 #include <algorithm>
13 #include <cmath>
14
15 #include "rtc_base/checks.h"
16 #include "rtc_base/numerics/safe_minmax.h"
17
18 namespace webrtc {
19 namespace {
20 bool Limit(float* value, float min, float max) {
21 float clamped = rtc::SafeClamp(*value, min, max);
22 clamped = std::isfinite(clamped) ? clamped : min;
23 bool res = *value == clamped;
24 *value = clamped;
25 return res;
26 }
27
28 bool Limit(size_t* value, size_t min, size_t max) {
29 size_t clamped = rtc::SafeClamp(*value, min, max);
30 bool res = *value == clamped;
31 *value = clamped;
32 return res;
33 }
34
35 bool Limit(int* value, int min, int max) {
36 int clamped = rtc::SafeClamp(*value, min, max);
37 bool res = *value == clamped;
38 *value = clamped;
39 return res;
40 }
41
42 bool FloorLimit(size_t* value, size_t min) {
43 size_t clamped = *value >= min ? *value : min;
44 bool res = *value == clamped;
45 *value = clamped;
46 return res;
47 }
48
49 } // namespace
50
51 EchoCanceller3Config::EchoCanceller3Config() = default;
52 EchoCanceller3Config::EchoCanceller3Config(const EchoCanceller3Config& e) =
53 default;
54 EchoCanceller3Config& EchoCanceller3Config::operator=(
55 const EchoCanceller3Config& e) = default;
56 EchoCanceller3Config::Delay::Delay() = default;
57 EchoCanceller3Config::Delay::Delay(const EchoCanceller3Config::Delay& e) =
58 default;
59 EchoCanceller3Config::Delay& EchoCanceller3Config::Delay::operator=(
60 const Delay& e) = default;
61
62 EchoCanceller3Config::EchoModel::EchoModel() = default;
63 EchoCanceller3Config::EchoModel::EchoModel(
64 const EchoCanceller3Config::EchoModel& e) = default;
65 EchoCanceller3Config::EchoModel& EchoCanceller3Config::EchoModel::operator=(
66 const EchoModel& e) = default;
67
68 EchoCanceller3Config::Suppressor::Suppressor() = default;
69 EchoCanceller3Config::Suppressor::Suppressor(
70 const EchoCanceller3Config::Suppressor& e) = default;
71 EchoCanceller3Config::Suppressor& EchoCanceller3Config::Suppressor::operator=(
72 const Suppressor& e) = default;
73
74 EchoCanceller3Config::Suppressor::MaskingThresholds::MaskingThresholds(
75 float enr_transparent,
76 float enr_suppress,
77 float emr_transparent)
78 : enr_transparent(enr_transparent),
79 enr_suppress(enr_suppress),
80 emr_transparent(emr_transparent) {}
81 EchoCanceller3Config::Suppressor::MaskingThresholds::MaskingThresholds(
82 const EchoCanceller3Config::Suppressor::MaskingThresholds& e) = default;
83 EchoCanceller3Config::Suppressor::MaskingThresholds&
84 EchoCanceller3Config::Suppressor::MaskingThresholds::operator=(
85 const MaskingThresholds& e) = default;
86
87 EchoCanceller3Config::Suppressor::Tuning::Tuning(MaskingThresholds mask_lf,
88 MaskingThresholds mask_hf,
89 float max_inc_factor,
90 float max_dec_factor_lf)
91 : mask_lf(mask_lf),
92 mask_hf(mask_hf),
93 max_inc_factor(max_inc_factor),
94 max_dec_factor_lf(max_dec_factor_lf) {}
95 EchoCanceller3Config::Suppressor::Tuning::Tuning(
96 const EchoCanceller3Config::Suppressor::Tuning& e) = default;
97 EchoCanceller3Config::Suppressor::Tuning&
98 EchoCanceller3Config::Suppressor::Tuning::operator=(const Tuning& e) = default;
99
100 bool EchoCanceller3Config::Validate(EchoCanceller3Config* config) {
101 RTC_DCHECK(config);
102 EchoCanceller3Config* c = config;
103 bool res = true;
104
105 if (c->delay.down_sampling_factor != 4 &&
106 c->delay.down_sampling_factor != 8) {
107 c->delay.down_sampling_factor = 4;
108 res = false;
109 }
110
111 res = res & Limit(&c->delay.default_delay, 0, 5000);
112 res = res & Limit(&c->delay.num_filters, 0, 5000);
113 res = res & Limit(&c->delay.delay_headroom_samples, 0, 5000);
114 res = res & Limit(&c->delay.hysteresis_limit_blocks, 0, 5000);
115 res = res & Limit(&c->delay.fixed_capture_delay_samples, 0, 5000);
116 res = res & Limit(&c->delay.delay_estimate_smoothing, 0.f, 1.f);
117 res = res & Limit(&c->delay.delay_candidate_detection_threshold, 0.f, 1.f);
118 res = res & Limit(&c->delay.delay_selection_thresholds.initial, 1, 250);
119 res = res & Limit(&c->delay.delay_selection_thresholds.converged, 1, 250);
120
121 res = res & FloorLimit(&c->filter.refined.length_blocks, 1);
122 res = res & Limit(&c->filter.refined.leakage_converged, 0.f, 1000.f);
123 res = res & Limit(&c->filter.refined.leakage_diverged, 0.f, 1000.f);
124 res = res & Limit(&c->filter.refined.error_floor, 0.f, 1000.f);
125 res = res & Limit(&c->filter.refined.error_ceil, 0.f, 100000000.f);
126 res = res & Limit(&c->filter.refined.noise_gate, 0.f, 100000000.f);
127
128 res = res & FloorLimit(&c->filter.refined_initial.length_blocks, 1);
129 res = res & Limit(&c->filter.refined_initial.leakage_converged, 0.f, 1000.f);
130 res = res & Limit(&c->filter.refined_initial.leakage_diverged, 0.f, 1000.f);
131 res = res & Limit(&c->filter.refined_initial.error_floor, 0.f, 1000.f);
132 res = res & Limit(&c->filter.refined_initial.error_ceil, 0.f, 100000000.f);
133 res = res & Limit(&c->filter.refined_initial.noise_gate, 0.f, 100000000.f);
134
135 if (c->filter.refined.length_blocks <
136 c->filter.refined_initial.length_blocks) {
137 c->filter.refined_initial.length_blocks = c->filter.refined.length_blocks;
138 res = false;
139 }
140
141 res = res & FloorLimit(&c->filter.coarse.length_blocks, 1);
142 res = res & Limit(&c->filter.coarse.rate, 0.f, 1.f);
143 res = res & Limit(&c->filter.coarse.noise_gate, 0.f, 100000000.f);
144
145 res = res & FloorLimit(&c->filter.coarse_initial.length_blocks, 1);
146 res = res & Limit(&c->filter.coarse_initial.rate, 0.f, 1.f);
147 res = res & Limit(&c->filter.coarse_initial.noise_gate, 0.f, 100000000.f);
148
149 if (c->filter.coarse.length_blocks < c->filter.coarse_initial.length_blocks) {
150 c->filter.coarse_initial.length_blocks = c->filter.coarse.length_blocks;
151 res = false;
152 }
153
154 res = res & Limit(&c->filter.config_change_duration_blocks, 0, 100000);
155 res = res & Limit(&c->filter.initial_state_seconds, 0.f, 100.f);
156 res = res & Limit(&c->filter.coarse_reset_hangover_blocks, 0, 2500);
157
158 res = res & Limit(&c->erle.min, 1.f, 100000.f);
159 res = res & Limit(&c->erle.max_l, 1.f, 100000.f);
160 res = res & Limit(&c->erle.max_h, 1.f, 100000.f);
161 if (c->erle.min > c->erle.max_l || c->erle.min > c->erle.max_h) {
162 c->erle.min = std::min(c->erle.max_l, c->erle.max_h);
163 res = false;
164 }
165 res = res & Limit(&c->erle.num_sections, 1, c->filter.refined.length_blocks);
166
167 res = res & Limit(&c->ep_strength.default_gain, 0.f, 1000000.f);
168 res = res & Limit(&c->ep_strength.default_len, -1.f, 1.f);
169
170 res =
171 res & Limit(&c->echo_audibility.low_render_limit, 0.f, 32768.f * 32768.f);
172 res = res &
173 Limit(&c->echo_audibility.normal_render_limit, 0.f, 32768.f * 32768.f);
174 res = res & Limit(&c->echo_audibility.floor_power, 0.f, 32768.f * 32768.f);
175 res = res & Limit(&c->echo_audibility.audibility_threshold_lf, 0.f,
176 32768.f * 32768.f);
177 res = res & Limit(&c->echo_audibility.audibility_threshold_mf, 0.f,
178 32768.f * 32768.f);
179 res = res & Limit(&c->echo_audibility.audibility_threshold_hf, 0.f,
180 32768.f * 32768.f);
181
182 res = res &
183 Limit(&c->render_levels.active_render_limit, 0.f, 32768.f * 32768.f);
184 res = res & Limit(&c->render_levels.poor_excitation_render_limit, 0.f,
185 32768.f * 32768.f);
186 res = res & Limit(&c->render_levels.poor_excitation_render_limit_ds8, 0.f,
187 32768.f * 32768.f);
188
189 res = res & Limit(&c->echo_model.noise_floor_hold, 0, 1000);
190 res = res & Limit(&c->echo_model.min_noise_floor_power, 0, 2000000.f);
191 res = res & Limit(&c->echo_model.stationary_gate_slope, 0, 1000000.f);
192 res = res & Limit(&c->echo_model.noise_gate_power, 0, 1000000.f);
193 res = res & Limit(&c->echo_model.noise_gate_slope, 0, 1000000.f);
194 res = res & Limit(&c->echo_model.render_pre_window_size, 0, 100);
195 res = res & Limit(&c->echo_model.render_post_window_size, 0, 100);
196
197 res = res & Limit(&c->comfort_noise.noise_floor_dbfs, -200.f, 0.f);
198
199 res = res & Limit(&c->suppressor.nearend_average_blocks, 1, 5000);
200
201 res = res &
202 Limit(&c->suppressor.normal_tuning.mask_lf.enr_transparent, 0.f, 100.f);
203 res = res &
204 Limit(&c->suppressor.normal_tuning.mask_lf.enr_suppress, 0.f, 100.f);
205 res = res &
206 Limit(&c->suppressor.normal_tuning.mask_lf.emr_transparent, 0.f, 100.f);
207 res = res &
208 Limit(&c->suppressor.normal_tuning.mask_hf.enr_transparent, 0.f, 100.f);
209 res = res &
210 Limit(&c->suppressor.normal_tuning.mask_hf.enr_suppress, 0.f, 100.f);
211 res = res &
212 Limit(&c->suppressor.normal_tuning.mask_hf.emr_transparent, 0.f, 100.f);
213 res = res & Limit(&c->suppressor.normal_tuning.max_inc_factor, 0.f, 100.f);
214 res = res & Limit(&c->suppressor.normal_tuning.max_dec_factor_lf, 0.f, 100.f);
215
216 res = res & Limit(&c->suppressor.nearend_tuning.mask_lf.enr_transparent, 0.f,
217 100.f);
218 res = res &
219 Limit(&c->suppressor.nearend_tuning.mask_lf.enr_suppress, 0.f, 100.f);
220 res = res & Limit(&c->suppressor.nearend_tuning.mask_lf.emr_transparent, 0.f,
221 100.f);
222 res = res & Limit(&c->suppressor.nearend_tuning.mask_hf.enr_transparent, 0.f,
223 100.f);
224 res = res &
225 Limit(&c->suppressor.nearend_tuning.mask_hf.enr_suppress, 0.f, 100.f);
226 res = res & Limit(&c->suppressor.nearend_tuning.mask_hf.emr_transparent, 0.f,
227 100.f);
228 res = res & Limit(&c->suppressor.nearend_tuning.max_inc_factor, 0.f, 100.f);
229 res =
230 res & Limit(&c->suppressor.nearend_tuning.max_dec_factor_lf, 0.f, 100.f);
231
232 res = res & Limit(&c->suppressor.dominant_nearend_detection.enr_threshold,
233 0.f, 1000000.f);
234 res = res & Limit(&c->suppressor.dominant_nearend_detection.snr_threshold,
235 0.f, 1000000.f);
236 res = res & Limit(&c->suppressor.dominant_nearend_detection.hold_duration, 0,
237 10000);
238 res = res & Limit(&c->suppressor.dominant_nearend_detection.trigger_threshold,
239 0, 10000);
240
241 res = res &
242 Limit(&c->suppressor.subband_nearend_detection.nearend_average_blocks,
243 1, 1024);
244 res =
245 res & Limit(&c->suppressor.subband_nearend_detection.subband1.low, 0, 65);
246 res = res & Limit(&c->suppressor.subband_nearend_detection.subband1.high,
247 c->suppressor.subband_nearend_detection.subband1.low, 65);
248 res =
249 res & Limit(&c->suppressor.subband_nearend_detection.subband2.low, 0, 65);
250 res = res & Limit(&c->suppressor.subband_nearend_detection.subband2.high,
251 c->suppressor.subband_nearend_detection.subband2.low, 65);
252 res = res & Limit(&c->suppressor.subband_nearend_detection.nearend_threshold,
253 0.f, 1.e24f);
254 res = res & Limit(&c->suppressor.subband_nearend_detection.snr_threshold, 0.f,
255 1.e24f);
256
257 res = res & Limit(&c->suppressor.high_bands_suppression.enr_threshold, 0.f,
258 1000000.f);
259 res = res & Limit(&c->suppressor.high_bands_suppression.max_gain_during_echo,
260 0.f, 1.f);
261 res = res & Limit(&c->suppressor.high_bands_suppression
262 .anti_howling_activation_threshold,
263 0.f, 32768.f * 32768.f);
264 res = res & Limit(&c->suppressor.high_bands_suppression.anti_howling_gain,
265 0.f, 1.f);
266
267 res = res & Limit(&c->suppressor.floor_first_increase, 0.f, 1000000.f);
268
269 return res;
270 }
271 } // namespace webrtc