blob: 263599c53813c5be994e68d8524f1493e122eb6f [file] [log] [blame]
Sam Zackrissona4c85142018-10-10 10:44:43 +02001/*
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_json.h"
11
Yves Gerey3e707812018-11-28 16:47:49 +010012#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Mirko Bonadeie99f6872021-06-24 15:24:59 +020014#include <memory>
Sam Zackrissona4c85142018-10-10 10:44:43 +020015#include <string>
16#include <vector>
17
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "rtc_base/checks.h"
Sam Zackrissona4c85142018-10-10 10:44:43 +020019#include "rtc_base/logging.h"
20#include "rtc_base/strings/json.h"
21#include "rtc_base/strings/string_builder.h"
22
23namespace webrtc {
24namespace {
25void ReadParam(const Json::Value& root, std::string param_name, bool* param) {
26 RTC_DCHECK(param);
27 bool v;
28 if (rtc::GetBoolFromJsonObject(root, param_name, &v)) {
29 *param = v;
30 }
31}
32
33void ReadParam(const Json::Value& root, std::string param_name, size_t* param) {
34 RTC_DCHECK(param);
35 int v;
Sam Zackrisson528a0342019-10-22 11:36:17 +020036 if (rtc::GetIntFromJsonObject(root, param_name, &v) && v >= 0) {
Sam Zackrissona4c85142018-10-10 10:44:43 +020037 *param = v;
38 }
39}
40
41void ReadParam(const Json::Value& root, std::string param_name, int* param) {
42 RTC_DCHECK(param);
43 int v;
44 if (rtc::GetIntFromJsonObject(root, param_name, &v)) {
45 *param = v;
46 }
47}
48
49void ReadParam(const Json::Value& root, std::string param_name, float* param) {
50 RTC_DCHECK(param);
51 double v;
52 if (rtc::GetDoubleFromJsonObject(root, param_name, &v)) {
53 *param = static_cast<float>(v);
54 }
55}
56
57void ReadParam(const Json::Value& root,
58 std::string param_name,
Per Åhgrenff045112020-03-20 11:20:39 +010059 EchoCanceller3Config::Filter::RefinedConfiguration* param) {
Sam Zackrisson703259c2018-10-10 17:17:43 +020060 RTC_DCHECK(param);
Sam Zackrissona4c85142018-10-10 10:44:43 +020061 Json::Value json_array;
62 if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
63 std::vector<double> v;
64 rtc::JsonArrayToDoubleVector(json_array, &v);
65 if (v.size() != 6) {
66 RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
Sam Zackrisson703259c2018-10-10 17:17:43 +020067 return;
Sam Zackrissona4c85142018-10-10 10:44:43 +020068 }
69 param->length_blocks = static_cast<size_t>(v[0]);
70 param->leakage_converged = static_cast<float>(v[1]);
71 param->leakage_diverged = static_cast<float>(v[2]);
72 param->error_floor = static_cast<float>(v[3]);
73 param->error_ceil = static_cast<float>(v[4]);
74 param->noise_gate = static_cast<float>(v[5]);
75 }
76}
77
78void ReadParam(const Json::Value& root,
79 std::string param_name,
Per Åhgren9d661982020-03-20 11:26:48 +010080 EchoCanceller3Config::Filter::CoarseConfiguration* param) {
Sam Zackrisson703259c2018-10-10 17:17:43 +020081 RTC_DCHECK(param);
Sam Zackrissona4c85142018-10-10 10:44:43 +020082 Json::Value json_array;
83 if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
84 std::vector<double> v;
85 rtc::JsonArrayToDoubleVector(json_array, &v);
86 if (v.size() != 3) {
87 RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
Sam Zackrisson703259c2018-10-10 17:17:43 +020088 return;
Sam Zackrissona4c85142018-10-10 10:44:43 +020089 }
90 param->length_blocks = static_cast<size_t>(v[0]);
91 param->rate = static_cast<float>(v[1]);
92 param->noise_gate = static_cast<float>(v[2]);
93 }
94}
95
Per Åhgren6a05bb12019-12-03 11:24:59 +010096void ReadParam(const Json::Value& root,
97 std::string param_name,
98 EchoCanceller3Config::Delay::AlignmentMixing* param) {
99 RTC_DCHECK(param);
100
101 Json::Value subsection;
102 if (rtc::GetValueFromJsonObject(root, param_name, &subsection)) {
103 ReadParam(subsection, "downmix", &param->downmix);
104 ReadParam(subsection, "adaptive_selection", &param->adaptive_selection);
105 ReadParam(subsection, "activity_power_threshold",
106 &param->activity_power_threshold);
107 ReadParam(subsection, "prefer_first_two_channels",
108 &param->prefer_first_two_channels);
109 }
110}
111
Gustaf Ullbergf534a642019-11-25 16:13:58 +0100112void ReadParam(
113 const Json::Value& root,
114 std::string param_name,
115 EchoCanceller3Config::Suppressor::SubbandNearendDetection::SubbandRegion*
116 param) {
117 RTC_DCHECK(param);
118 Json::Value json_array;
119 if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
120 std::vector<int> v;
121 rtc::JsonArrayToIntVector(json_array, &v);
122 if (v.size() != 2) {
123 RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
124 return;
125 }
126 param->low = static_cast<size_t>(v[0]);
127 param->high = static_cast<size_t>(v[1]);
128 }
129}
130
Sam Zackrissona4c85142018-10-10 10:44:43 +0200131void ReadParam(const Json::Value& root,
132 std::string param_name,
133 EchoCanceller3Config::Suppressor::MaskingThresholds* param) {
Sam Zackrisson703259c2018-10-10 17:17:43 +0200134 RTC_DCHECK(param);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200135 Json::Value json_array;
136 if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
137 std::vector<double> v;
138 rtc::JsonArrayToDoubleVector(json_array, &v);
139 if (v.size() != 3) {
140 RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
Sam Zackrisson703259c2018-10-10 17:17:43 +0200141 return;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200142 }
143 param->enr_transparent = static_cast<float>(v[0]);
144 param->enr_suppress = static_cast<float>(v[1]);
145 param->emr_transparent = static_cast<float>(v[2]);
146 }
147}
148} // namespace
149
Per Åhgren370bae42018-10-25 11:32:39 +0200150void Aec3ConfigFromJsonString(absl::string_view json_string,
151 EchoCanceller3Config* config,
152 bool* parsing_successful) {
153 RTC_DCHECK(config);
154 RTC_DCHECK(parsing_successful);
155 EchoCanceller3Config& cfg = *config;
156 cfg = EchoCanceller3Config();
157 *parsing_successful = true;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200158
159 Json::Value root;
Mirko Bonadeie99f6872021-06-24 15:24:59 +0200160 Json::CharReaderBuilder builder;
161 std::string error_message;
162 std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
163 bool success =
164 reader->parse(json_string.data(), json_string.data() + json_string.size(),
165 &root, &error_message);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200166 if (!success) {
Mirko Bonadeie99f6872021-06-24 15:24:59 +0200167 RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << error_message;
Per Åhgren370bae42018-10-25 11:32:39 +0200168 *parsing_successful = false;
169 return;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200170 }
171
172 Json::Value aec3_root;
173 success = rtc::GetValueFromJsonObject(root, "aec3", &aec3_root);
174 if (!success) {
175 RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string;
Per Åhgren370bae42018-10-25 11:32:39 +0200176 *parsing_successful = false;
177 return;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200178 }
179
180 Json::Value section;
Per Åhgrenc1d20922019-04-22 23:36:58 +0200181 if (rtc::GetValueFromJsonObject(aec3_root, "buffering", &section)) {
Gustaf Ullberg11539f02018-10-15 13:40:29 +0200182 ReadParam(section, "excess_render_detection_interval_blocks",
183 &cfg.buffering.excess_render_detection_interval_blocks);
184 ReadParam(section, "max_allowed_excess_render_blocks",
185 &cfg.buffering.max_allowed_excess_render_blocks);
186 }
187
Sam Zackrissona4c85142018-10-10 10:44:43 +0200188 if (rtc::GetValueFromJsonObject(aec3_root, "delay", &section)) {
189 ReadParam(section, "default_delay", &cfg.delay.default_delay);
190 ReadParam(section, "down_sampling_factor", &cfg.delay.down_sampling_factor);
191 ReadParam(section, "num_filters", &cfg.delay.num_filters);
Gustaf Ullberg9249fbf2019-03-14 11:24:54 +0100192 ReadParam(section, "delay_headroom_samples",
193 &cfg.delay.delay_headroom_samples);
194 ReadParam(section, "hysteresis_limit_blocks",
195 &cfg.delay.hysteresis_limit_blocks);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200196 ReadParam(section, "fixed_capture_delay_samples",
197 &cfg.delay.fixed_capture_delay_samples);
198 ReadParam(section, "delay_estimate_smoothing",
199 &cfg.delay.delay_estimate_smoothing);
Gustaf Ullbergaeb8ce82021-05-19 14:26:31 +0200200 ReadParam(section, "delay_estimate_smoothing_delay_found",
201 &cfg.delay.delay_estimate_smoothing_delay_found);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200202 ReadParam(section, "delay_candidate_detection_threshold",
203 &cfg.delay.delay_candidate_detection_threshold);
204
205 Json::Value subsection;
206 if (rtc::GetValueFromJsonObject(section, "delay_selection_thresholds",
207 &subsection)) {
208 ReadParam(subsection, "initial",
209 &cfg.delay.delay_selection_thresholds.initial);
210 ReadParam(subsection, "converged",
211 &cfg.delay.delay_selection_thresholds.converged);
212 }
Gustaf Ullberg52caa0e2019-04-11 14:43:17 +0200213
214 ReadParam(section, "use_external_delay_estimator",
215 &cfg.delay.use_external_delay_estimator);
Sam Zackrissonffc84522019-10-15 13:43:02 +0200216 ReadParam(section, "log_warning_on_delay_changes",
217 &cfg.delay.log_warning_on_delay_changes);
Per Åhgren6a05bb12019-12-03 11:24:59 +0100218
219 ReadParam(section, "render_alignment_mixing",
220 &cfg.delay.render_alignment_mixing);
221 ReadParam(section, "capture_alignment_mixing",
222 &cfg.delay.capture_alignment_mixing);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200223 }
224
225 if (rtc::GetValueFromJsonObject(aec3_root, "filter", &section)) {
Per Åhgrenff045112020-03-20 11:20:39 +0100226 ReadParam(section, "refined", &cfg.filter.refined);
Per Åhgren9d661982020-03-20 11:26:48 +0100227 ReadParam(section, "coarse", &cfg.filter.coarse);
Per Åhgrenff045112020-03-20 11:20:39 +0100228 ReadParam(section, "refined_initial", &cfg.filter.refined_initial);
Per Åhgren9d661982020-03-20 11:26:48 +0100229 ReadParam(section, "coarse_initial", &cfg.filter.coarse_initial);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200230 ReadParam(section, "config_change_duration_blocks",
231 &cfg.filter.config_change_duration_blocks);
232 ReadParam(section, "initial_state_seconds",
233 &cfg.filter.initial_state_seconds);
Gustaf Ullberg992a96f2020-12-08 13:03:55 +0100234 ReadParam(section, "coarse_reset_hangover_blocks",
235 &cfg.filter.coarse_reset_hangover_blocks);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200236 ReadParam(section, "conservative_initial_phase",
237 &cfg.filter.conservative_initial_phase);
Per Åhgren9d661982020-03-20 11:26:48 +0100238 ReadParam(section, "enable_coarse_filter_output_usage",
239 &cfg.filter.enable_coarse_filter_output_usage);
Gustaf Ullberg52caa0e2019-04-11 14:43:17 +0200240 ReadParam(section, "use_linear_filter", &cfg.filter.use_linear_filter);
Gustaf Ullberg09226fc2021-02-19 13:03:14 +0100241 ReadParam(section, "high_pass_filter_echo_reference",
242 &cfg.filter.high_pass_filter_echo_reference);
Per Åhgrenc20a19c2019-11-13 11:12:29 +0100243 ReadParam(section, "export_linear_aec_output",
244 &cfg.filter.export_linear_aec_output);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200245 }
246
247 if (rtc::GetValueFromJsonObject(aec3_root, "erle", &section)) {
248 ReadParam(section, "min", &cfg.erle.min);
249 ReadParam(section, "max_l", &cfg.erle.max_l);
250 ReadParam(section, "max_h", &cfg.erle.max_h);
251 ReadParam(section, "onset_detection", &cfg.erle.onset_detection);
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +0100252 ReadParam(section, "num_sections", &cfg.erle.num_sections);
Per Åhgren8be669f2019-10-11 23:02:26 +0200253 ReadParam(section, "clamp_quality_estimate_to_zero",
254 &cfg.erle.clamp_quality_estimate_to_zero);
255 ReadParam(section, "clamp_quality_estimate_to_one",
256 &cfg.erle.clamp_quality_estimate_to_one);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200257 }
258
259 if (rtc::GetValueFromJsonObject(aec3_root, "ep_strength", &section)) {
Per Åhgrene8efbbd2019-03-14 11:29:39 +0100260 ReadParam(section, "default_gain", &cfg.ep_strength.default_gain);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200261 ReadParam(section, "default_len", &cfg.ep_strength.default_len);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200262 ReadParam(section, "echo_can_saturate", &cfg.ep_strength.echo_can_saturate);
263 ReadParam(section, "bounded_erl", &cfg.ep_strength.bounded_erl);
Gustaf Ullberg437d1292021-04-20 13:48:57 +0200264 ReadParam(section, "erle_onset_compensation_in_dominant_nearend",
265 &cfg.ep_strength.erle_onset_compensation_in_dominant_nearend);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200266 }
267
Sam Zackrissona4c85142018-10-10 10:44:43 +0200268 if (rtc::GetValueFromJsonObject(aec3_root, "echo_audibility", &section)) {
269 ReadParam(section, "low_render_limit",
270 &cfg.echo_audibility.low_render_limit);
271 ReadParam(section, "normal_render_limit",
272 &cfg.echo_audibility.normal_render_limit);
273
274 ReadParam(section, "floor_power", &cfg.echo_audibility.floor_power);
275 ReadParam(section, "audibility_threshold_lf",
276 &cfg.echo_audibility.audibility_threshold_lf);
277 ReadParam(section, "audibility_threshold_mf",
278 &cfg.echo_audibility.audibility_threshold_mf);
279 ReadParam(section, "audibility_threshold_hf",
280 &cfg.echo_audibility.audibility_threshold_hf);
Jesús de Vicente Peña70a59632019-04-16 12:32:15 +0200281 ReadParam(section, "use_stationarity_properties",
282 &cfg.echo_audibility.use_stationarity_properties);
Sam Zackrisson877dc892018-10-23 14:17:38 +0200283 ReadParam(section, "use_stationarity_properties_at_init",
Sam Zackrissona4c85142018-10-10 10:44:43 +0200284 &cfg.echo_audibility.use_stationarity_properties_at_init);
285 }
286
Per Åhgren01cf44d2018-10-20 00:17:13 +0200287 if (rtc::GetValueFromJsonObject(aec3_root, "render_levels", &section)) {
288 ReadParam(section, "active_render_limit",
289 &cfg.render_levels.active_render_limit);
290 ReadParam(section, "poor_excitation_render_limit",
291 &cfg.render_levels.poor_excitation_render_limit);
292 ReadParam(section, "poor_excitation_render_limit_ds8",
293 &cfg.render_levels.poor_excitation_render_limit_ds8);
Per Åhgrenae40e192019-10-29 22:54:05 +0100294 ReadParam(section, "render_power_gain_db",
295 &cfg.render_levels.render_power_gain_db);
Per Åhgren01cf44d2018-10-20 00:17:13 +0200296 }
297
Sam Zackrissona4c85142018-10-10 10:44:43 +0200298 if (rtc::GetValueFromJsonObject(aec3_root, "echo_removal_control",
299 &section)) {
Sam Zackrissona4c85142018-10-10 10:44:43 +0200300 ReadParam(section, "has_clock_drift",
301 &cfg.echo_removal_control.has_clock_drift);
302 ReadParam(section, "linear_and_stable_echo_path",
303 &cfg.echo_removal_control.linear_and_stable_echo_path);
304 }
305
306 if (rtc::GetValueFromJsonObject(aec3_root, "echo_model", &section)) {
307 Json::Value subsection;
308 ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold);
309 ReadParam(section, "min_noise_floor_power",
310 &cfg.echo_model.min_noise_floor_power);
311 ReadParam(section, "stationary_gate_slope",
312 &cfg.echo_model.stationary_gate_slope);
313 ReadParam(section, "noise_gate_power", &cfg.echo_model.noise_gate_power);
314 ReadParam(section, "noise_gate_slope", &cfg.echo_model.noise_gate_slope);
315 ReadParam(section, "render_pre_window_size",
316 &cfg.echo_model.render_pre_window_size);
317 ReadParam(section, "render_post_window_size",
318 &cfg.echo_model.render_post_window_size);
Sam Zackrisson389bf0f2020-10-02 21:13:13 +0200319 ReadParam(section, "model_reverb_in_nonlinear_mode",
320 &cfg.echo_model.model_reverb_in_nonlinear_mode);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200321 }
322
Per Åhgrena388b752020-03-25 07:31:47 +0100323 if (rtc::GetValueFromJsonObject(aec3_root, "comfort_noise", &section)) {
324 ReadParam(section, "noise_floor_dbfs", &cfg.comfort_noise.noise_floor_dbfs);
325 }
326
Sam Zackrissona4c85142018-10-10 10:44:43 +0200327 Json::Value subsection;
328 if (rtc::GetValueFromJsonObject(aec3_root, "suppressor", &section)) {
329 ReadParam(section, "nearend_average_blocks",
330 &cfg.suppressor.nearend_average_blocks);
331
332 if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) {
333 ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf);
334 ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf);
335 ReadParam(subsection, "max_inc_factor",
336 &cfg.suppressor.normal_tuning.max_inc_factor);
337 ReadParam(subsection, "max_dec_factor_lf",
338 &cfg.suppressor.normal_tuning.max_dec_factor_lf);
339 }
340
341 if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) {
342 ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf);
343 ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf);
344 ReadParam(subsection, "max_inc_factor",
345 &cfg.suppressor.nearend_tuning.max_inc_factor);
346 ReadParam(subsection, "max_dec_factor_lf",
347 &cfg.suppressor.nearend_tuning.max_dec_factor_lf);
348 }
349
Per Åhgrencbdbb8c2021-05-07 23:17:28 +0000350 ReadParam(section, "lf_smoothing_during_initial_phase",
351 &cfg.suppressor.lf_smoothing_during_initial_phase);
352 ReadParam(section, "last_permanent_lf_smoothing_band",
353 &cfg.suppressor.last_permanent_lf_smoothing_band);
354 ReadParam(section, "last_lf_smoothing_band",
355 &cfg.suppressor.last_lf_smoothing_band);
356 ReadParam(section, "last_lf_band", &cfg.suppressor.last_lf_band);
357 ReadParam(section, "first_hf_band", &cfg.suppressor.first_hf_band);
358
Sam Zackrissona4c85142018-10-10 10:44:43 +0200359 if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection",
360 &subsection)) {
361 ReadParam(subsection, "enr_threshold",
362 &cfg.suppressor.dominant_nearend_detection.enr_threshold);
Gustaf Ullbergc9f9b872018-10-22 15:15:36 +0200363 ReadParam(subsection, "enr_exit_threshold",
364 &cfg.suppressor.dominant_nearend_detection.enr_exit_threshold);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200365 ReadParam(subsection, "snr_threshold",
366 &cfg.suppressor.dominant_nearend_detection.snr_threshold);
367 ReadParam(subsection, "hold_duration",
368 &cfg.suppressor.dominant_nearend_detection.hold_duration);
369 ReadParam(subsection, "trigger_threshold",
370 &cfg.suppressor.dominant_nearend_detection.trigger_threshold);
Per Åhgrenfb5c1ec2018-10-24 13:02:11 +0200371 ReadParam(
372 subsection, "use_during_initial_phase",
373 &cfg.suppressor.dominant_nearend_detection.use_during_initial_phase);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200374 }
375
Gustaf Ullbergf534a642019-11-25 16:13:58 +0100376 if (rtc::GetValueFromJsonObject(section, "subband_nearend_detection",
377 &subsection)) {
378 ReadParam(
379 subsection, "nearend_average_blocks",
380 &cfg.suppressor.subband_nearend_detection.nearend_average_blocks);
381 ReadParam(subsection, "subband1",
382 &cfg.suppressor.subband_nearend_detection.subband1);
383 ReadParam(subsection, "subband2",
384 &cfg.suppressor.subband_nearend_detection.subband2);
385 ReadParam(subsection, "nearend_threshold",
386 &cfg.suppressor.subband_nearend_detection.nearend_threshold);
387 ReadParam(subsection, "snr_threshold",
388 &cfg.suppressor.subband_nearend_detection.snr_threshold);
389 }
390
391 ReadParam(section, "use_subband_nearend_detection",
392 &cfg.suppressor.use_subband_nearend_detection);
393
Sam Zackrissona4c85142018-10-10 10:44:43 +0200394 if (rtc::GetValueFromJsonObject(section, "high_bands_suppression",
395 &subsection)) {
396 ReadParam(subsection, "enr_threshold",
397 &cfg.suppressor.high_bands_suppression.enr_threshold);
398 ReadParam(subsection, "max_gain_during_echo",
399 &cfg.suppressor.high_bands_suppression.max_gain_during_echo);
Per Åhgren17e4c582019-11-27 08:13:24 +0100400 ReadParam(subsection, "anti_howling_activation_threshold",
401 &cfg.suppressor.high_bands_suppression
402 .anti_howling_activation_threshold);
403 ReadParam(subsection, "anti_howling_gain",
404 &cfg.suppressor.high_bands_suppression.anti_howling_gain);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200405 }
406
407 ReadParam(section, "floor_first_increase",
408 &cfg.suppressor.floor_first_increase);
Gustaf Ullberg7e4ad822020-10-22 14:36:37 +0200409 ReadParam(section, "conservative_hf_suppression",
410 &cfg.suppressor.conservative_hf_suppression);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200411 }
Per Åhgren370bae42018-10-25 11:32:39 +0200412}
413
414EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) {
415 EchoCanceller3Config cfg;
416 bool not_used;
417 Aec3ConfigFromJsonString(json_string, &cfg, &not_used);
Sam Zackrissona4c85142018-10-10 10:44:43 +0200418 return cfg;
419}
420
421std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) {
422 rtc::StringBuilder ost;
423 ost << "{";
424 ost << "\"aec3\": {";
Per Åhgrenc1d20922019-04-22 23:36:58 +0200425 ost << "\"buffering\": {";
426 ost << "\"excess_render_detection_interval_blocks\": "
427 << config.buffering.excess_render_detection_interval_blocks << ",";
428 ost << "\"max_allowed_excess_render_blocks\": "
429 << config.buffering.max_allowed_excess_render_blocks;
430 ost << "},";
431
Sam Zackrissona4c85142018-10-10 10:44:43 +0200432 ost << "\"delay\": {";
433 ost << "\"default_delay\": " << config.delay.default_delay << ",";
434 ost << "\"down_sampling_factor\": " << config.delay.down_sampling_factor
435 << ",";
436 ost << "\"num_filters\": " << config.delay.num_filters << ",";
Gustaf Ullberg9249fbf2019-03-14 11:24:54 +0100437 ost << "\"delay_headroom_samples\": " << config.delay.delay_headroom_samples
Sam Zackrissona4c85142018-10-10 10:44:43 +0200438 << ",";
Gustaf Ullberg9249fbf2019-03-14 11:24:54 +0100439 ost << "\"hysteresis_limit_blocks\": " << config.delay.hysteresis_limit_blocks
440 << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200441 ost << "\"fixed_capture_delay_samples\": "
442 << config.delay.fixed_capture_delay_samples << ",";
443 ost << "\"delay_estimate_smoothing\": "
444 << config.delay.delay_estimate_smoothing << ",";
Gustaf Ullbergaeb8ce82021-05-19 14:26:31 +0200445 ost << "\"delay_estimate_smoothing_delay_found\": "
446 << config.delay.delay_estimate_smoothing_delay_found << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200447 ost << "\"delay_candidate_detection_threshold\": "
448 << config.delay.delay_candidate_detection_threshold << ",";
449
450 ost << "\"delay_selection_thresholds\": {";
451 ost << "\"initial\": " << config.delay.delay_selection_thresholds.initial
452 << ",";
453 ost << "\"converged\": " << config.delay.delay_selection_thresholds.converged;
Gustaf Ullbergee84d392019-09-10 09:36:43 +0200454 ost << "},";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200455
Gustaf Ullbergee84d392019-09-10 09:36:43 +0200456 ost << "\"use_external_delay_estimator\": "
457 << (config.delay.use_external_delay_estimator ? "true" : "false") << ",";
Sam Zackrissonffc84522019-10-15 13:43:02 +0200458 ost << "\"log_warning_on_delay_changes\": "
Per Åhgren6a05bb12019-12-03 11:24:59 +0100459 << (config.delay.log_warning_on_delay_changes ? "true" : "false") << ",";
460
461 ost << "\"render_alignment_mixing\": {";
462 ost << "\"downmix\": "
463 << (config.delay.render_alignment_mixing.downmix ? "true" : "false")
464 << ",";
465 ost << "\"adaptive_selection\": "
466 << (config.delay.render_alignment_mixing.adaptive_selection ? "true"
467 : "false")
468 << ",";
469 ost << "\"activity_power_threshold\": "
470 << config.delay.render_alignment_mixing.activity_power_threshold << ",";
471 ost << "\"prefer_first_two_channels\": "
472 << (config.delay.render_alignment_mixing.prefer_first_two_channels
473 ? "true"
474 : "false");
475 ost << "},";
476
477 ost << "\"capture_alignment_mixing\": {";
478 ost << "\"downmix\": "
479 << (config.delay.capture_alignment_mixing.downmix ? "true" : "false")
480 << ",";
481 ost << "\"adaptive_selection\": "
482 << (config.delay.capture_alignment_mixing.adaptive_selection ? "true"
483 : "false")
484 << ",";
485 ost << "\"activity_power_threshold\": "
486 << config.delay.capture_alignment_mixing.activity_power_threshold << ",";
487 ost << "\"prefer_first_two_channels\": "
488 << (config.delay.capture_alignment_mixing.prefer_first_two_channels
489 ? "true"
490 : "false");
491 ost << "}";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200492 ost << "},";
493
494 ost << "\"filter\": {";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200495
Per Åhgrenff045112020-03-20 11:20:39 +0100496 ost << "\"refined\": [";
497 ost << config.filter.refined.length_blocks << ",";
498 ost << config.filter.refined.leakage_converged << ",";
499 ost << config.filter.refined.leakage_diverged << ",";
500 ost << config.filter.refined.error_floor << ",";
501 ost << config.filter.refined.error_ceil << ",";
502 ost << config.filter.refined.noise_gate;
503 ost << "],";
504
Per Åhgren9d661982020-03-20 11:26:48 +0100505 ost << "\"coarse\": [";
506 ost << config.filter.coarse.length_blocks << ",";
507 ost << config.filter.coarse.rate << ",";
508 ost << config.filter.coarse.noise_gate;
509 ost << "],";
510
Per Åhgrenff045112020-03-20 11:20:39 +0100511 ost << "\"refined_initial\": [";
512 ost << config.filter.refined_initial.length_blocks << ",";
513 ost << config.filter.refined_initial.leakage_converged << ",";
514 ost << config.filter.refined_initial.leakage_diverged << ",";
515 ost << config.filter.refined_initial.error_floor << ",";
516 ost << config.filter.refined_initial.error_ceil << ",";
517 ost << config.filter.refined_initial.noise_gate;
518 ost << "],";
519
Per Åhgren9d661982020-03-20 11:26:48 +0100520 ost << "\"coarse_initial\": [";
521 ost << config.filter.coarse_initial.length_blocks << ",";
522 ost << config.filter.coarse_initial.rate << ",";
523 ost << config.filter.coarse_initial.noise_gate;
524 ost << "],";
525
Sam Zackrissona4c85142018-10-10 10:44:43 +0200526 ost << "\"config_change_duration_blocks\": "
527 << config.filter.config_change_duration_blocks << ",";
528 ost << "\"initial_state_seconds\": " << config.filter.initial_state_seconds
529 << ",";
Gustaf Ullberg992a96f2020-12-08 13:03:55 +0100530 ost << "\"coarse_reset_hangover_blocks\": "
531 << config.filter.coarse_reset_hangover_blocks << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200532 ost << "\"conservative_initial_phase\": "
533 << (config.filter.conservative_initial_phase ? "true" : "false") << ",";
Per Åhgren9d661982020-03-20 11:26:48 +0100534 ost << "\"enable_coarse_filter_output_usage\": "
535 << (config.filter.enable_coarse_filter_output_usage ? "true" : "false")
536 << ",";
Per Åhgrenc20a19c2019-11-13 11:12:29 +0100537 ost << "\"use_linear_filter\": "
538 << (config.filter.use_linear_filter ? "true" : "false") << ",";
Gustaf Ullberg09226fc2021-02-19 13:03:14 +0100539 ost << "\"high_pass_filter_echo_reference\": "
540 << (config.filter.high_pass_filter_echo_reference ? "true" : "false")
541 << ",";
Per Åhgrenc20a19c2019-11-13 11:12:29 +0100542 ost << "\"export_linear_aec_output\": "
Per Åhgrene1562872020-04-09 13:12:08 +0200543 << (config.filter.export_linear_aec_output ? "true" : "false");
Sam Zackrissona4c85142018-10-10 10:44:43 +0200544
545 ost << "},";
546
547 ost << "\"erle\": {";
548 ost << "\"min\": " << config.erle.min << ",";
549 ost << "\"max_l\": " << config.erle.max_l << ",";
550 ost << "\"max_h\": " << config.erle.max_h << ",";
551 ost << "\"onset_detection\": "
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +0100552 << (config.erle.onset_detection ? "true" : "false") << ",";
Per Åhgren8be669f2019-10-11 23:02:26 +0200553 ost << "\"num_sections\": " << config.erle.num_sections << ",";
554 ost << "\"clamp_quality_estimate_to_zero\": "
555 << (config.erle.clamp_quality_estimate_to_zero ? "true" : "false") << ",";
556 ost << "\"clamp_quality_estimate_to_one\": "
557 << (config.erle.clamp_quality_estimate_to_one ? "true" : "false");
Sam Zackrissona4c85142018-10-10 10:44:43 +0200558 ost << "},";
559
560 ost << "\"ep_strength\": {";
Per Åhgrene8efbbd2019-03-14 11:29:39 +0100561 ost << "\"default_gain\": " << config.ep_strength.default_gain << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200562 ost << "\"default_len\": " << config.ep_strength.default_len << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200563 ost << "\"echo_can_saturate\": "
564 << (config.ep_strength.echo_can_saturate ? "true" : "false") << ",";
565 ost << "\"bounded_erl\": "
Gustaf Ullberg437d1292021-04-20 13:48:57 +0200566 << (config.ep_strength.bounded_erl ? "true" : "false") << ",";
567 ost << "\"erle_onset_compensation_in_dominant_nearend\": "
568 << (config.ep_strength.erle_onset_compensation_in_dominant_nearend
569 ? "true"
570 : "false");
Sam Zackrissona4c85142018-10-10 10:44:43 +0200571 ost << "},";
572
Sam Zackrissona4c85142018-10-10 10:44:43 +0200573 ost << "\"echo_audibility\": {";
574 ost << "\"low_render_limit\": " << config.echo_audibility.low_render_limit
575 << ",";
576 ost << "\"normal_render_limit\": "
577 << config.echo_audibility.normal_render_limit << ",";
578 ost << "\"floor_power\": " << config.echo_audibility.floor_power << ",";
579 ost << "\"audibility_threshold_lf\": "
580 << config.echo_audibility.audibility_threshold_lf << ",";
581 ost << "\"audibility_threshold_mf\": "
582 << config.echo_audibility.audibility_threshold_mf << ",";
583 ost << "\"audibility_threshold_hf\": "
584 << config.echo_audibility.audibility_threshold_hf << ",";
Jesús de Vicente Peña70a59632019-04-16 12:32:15 +0200585 ost << "\"use_stationarity_properties\": "
586 << (config.echo_audibility.use_stationarity_properties ? "true" : "false")
Sam Zackrissona4c85142018-10-10 10:44:43 +0200587 << ",";
588 ost << "\"use_stationarity_properties_at_init\": "
589 << (config.echo_audibility.use_stationarity_properties_at_init ? "true"
590 : "false");
591 ost << "},";
592
593 ost << "\"render_levels\": {";
594 ost << "\"active_render_limit\": " << config.render_levels.active_render_limit
595 << ",";
596 ost << "\"poor_excitation_render_limit\": "
597 << config.render_levels.poor_excitation_render_limit << ",";
598 ost << "\"poor_excitation_render_limit_ds8\": "
Per Åhgrenae40e192019-10-29 22:54:05 +0100599 << config.render_levels.poor_excitation_render_limit_ds8 << ",";
600 ost << "\"render_power_gain_db\": "
601 << config.render_levels.render_power_gain_db;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200602 ost << "},";
603
604 ost << "\"echo_removal_control\": {";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200605 ost << "\"has_clock_drift\": "
606 << (config.echo_removal_control.has_clock_drift ? "true" : "false")
607 << ",";
608 ost << "\"linear_and_stable_echo_path\": "
609 << (config.echo_removal_control.linear_and_stable_echo_path ? "true"
610 : "false");
611
612 ost << "},";
613
614 ost << "\"echo_model\": {";
615 ost << "\"noise_floor_hold\": " << config.echo_model.noise_floor_hold << ",";
616 ost << "\"min_noise_floor_power\": "
617 << config.echo_model.min_noise_floor_power << ",";
618 ost << "\"stationary_gate_slope\": "
619 << config.echo_model.stationary_gate_slope << ",";
620 ost << "\"noise_gate_power\": " << config.echo_model.noise_gate_power << ",";
621 ost << "\"noise_gate_slope\": " << config.echo_model.noise_gate_slope << ",";
622 ost << "\"render_pre_window_size\": "
623 << config.echo_model.render_pre_window_size << ",";
624 ost << "\"render_post_window_size\": "
Sam Zackrisson389bf0f2020-10-02 21:13:13 +0200625 << config.echo_model.render_post_window_size << ",";
626 ost << "\"model_reverb_in_nonlinear_mode\": "
627 << (config.echo_model.model_reverb_in_nonlinear_mode ? "true" : "false");
Sam Zackrissona4c85142018-10-10 10:44:43 +0200628 ost << "},";
629
Per Åhgrena388b752020-03-25 07:31:47 +0100630 ost << "\"comfort_noise\": {";
631 ost << "\"noise_floor_dbfs\": " << config.comfort_noise.noise_floor_dbfs;
632 ost << "},";
633
Sam Zackrissona4c85142018-10-10 10:44:43 +0200634 ost << "\"suppressor\": {";
635 ost << "\"nearend_average_blocks\": "
636 << config.suppressor.nearend_average_blocks << ",";
637 ost << "\"normal_tuning\": {";
638 ost << "\"mask_lf\": [";
639 ost << config.suppressor.normal_tuning.mask_lf.enr_transparent << ",";
640 ost << config.suppressor.normal_tuning.mask_lf.enr_suppress << ",";
641 ost << config.suppressor.normal_tuning.mask_lf.emr_transparent;
642 ost << "],";
643 ost << "\"mask_hf\": [";
644 ost << config.suppressor.normal_tuning.mask_hf.enr_transparent << ",";
645 ost << config.suppressor.normal_tuning.mask_hf.enr_suppress << ",";
646 ost << config.suppressor.normal_tuning.mask_hf.emr_transparent;
647 ost << "],";
648 ost << "\"max_inc_factor\": "
649 << config.suppressor.normal_tuning.max_inc_factor << ",";
650 ost << "\"max_dec_factor_lf\": "
651 << config.suppressor.normal_tuning.max_dec_factor_lf;
652 ost << "},";
653 ost << "\"nearend_tuning\": {";
654 ost << "\"mask_lf\": [";
655 ost << config.suppressor.nearend_tuning.mask_lf.enr_transparent << ",";
656 ost << config.suppressor.nearend_tuning.mask_lf.enr_suppress << ",";
657 ost << config.suppressor.nearend_tuning.mask_lf.emr_transparent;
658 ost << "],";
659 ost << "\"mask_hf\": [";
660 ost << config.suppressor.nearend_tuning.mask_hf.enr_transparent << ",";
661 ost << config.suppressor.nearend_tuning.mask_hf.enr_suppress << ",";
662 ost << config.suppressor.nearend_tuning.mask_hf.emr_transparent;
663 ost << "],";
664 ost << "\"max_inc_factor\": "
665 << config.suppressor.nearend_tuning.max_inc_factor << ",";
666 ost << "\"max_dec_factor_lf\": "
667 << config.suppressor.nearend_tuning.max_dec_factor_lf;
668 ost << "},";
Per Åhgrencbdbb8c2021-05-07 23:17:28 +0000669 ost << "\"lf_smoothing_during_initial_phase\": "
670 << (config.suppressor.lf_smoothing_during_initial_phase ? "true"
671 : "false")
672 << ",";
673 ost << "\"last_permanent_lf_smoothing_band\": "
674 << config.suppressor.last_permanent_lf_smoothing_band << ",";
675 ost << "\"last_lf_smoothing_band\": "
676 << config.suppressor.last_lf_smoothing_band << ",";
677 ost << "\"last_lf_band\": " << config.suppressor.last_lf_band << ",";
678 ost << "\"first_hf_band\": " << config.suppressor.first_hf_band << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200679 ost << "\"dominant_nearend_detection\": {";
680 ost << "\"enr_threshold\": "
681 << config.suppressor.dominant_nearend_detection.enr_threshold << ",";
Gustaf Ullbergc9f9b872018-10-22 15:15:36 +0200682 ost << "\"enr_exit_threshold\": "
683 << config.suppressor.dominant_nearend_detection.enr_exit_threshold << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200684 ost << "\"snr_threshold\": "
685 << config.suppressor.dominant_nearend_detection.snr_threshold << ",";
686 ost << "\"hold_duration\": "
687 << config.suppressor.dominant_nearend_detection.hold_duration << ",";
688 ost << "\"trigger_threshold\": "
Per Åhgrenfb5c1ec2018-10-24 13:02:11 +0200689 << config.suppressor.dominant_nearend_detection.trigger_threshold << ",";
690 ost << "\"use_during_initial_phase\": "
691 << config.suppressor.dominant_nearend_detection.use_during_initial_phase;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200692 ost << "},";
Gustaf Ullbergf534a642019-11-25 16:13:58 +0100693 ost << "\"subband_nearend_detection\": {";
694 ost << "\"nearend_average_blocks\": "
695 << config.suppressor.subband_nearend_detection.nearend_average_blocks
696 << ",";
697 ost << "\"subband1\": [";
698 ost << config.suppressor.subband_nearend_detection.subband1.low << ",";
699 ost << config.suppressor.subband_nearend_detection.subband1.high;
700 ost << "],";
701 ost << "\"subband2\": [";
702 ost << config.suppressor.subband_nearend_detection.subband2.low << ",";
703 ost << config.suppressor.subband_nearend_detection.subband2.high;
704 ost << "],";
705 ost << "\"nearend_threshold\": "
706 << config.suppressor.subband_nearend_detection.nearend_threshold << ",";
707 ost << "\"snr_threshold\": "
708 << config.suppressor.subband_nearend_detection.snr_threshold;
709 ost << "},";
710 ost << "\"use_subband_nearend_detection\": "
711 << config.suppressor.use_subband_nearend_detection << ",";
Sam Zackrissona4c85142018-10-10 10:44:43 +0200712 ost << "\"high_bands_suppression\": {";
713 ost << "\"enr_threshold\": "
714 << config.suppressor.high_bands_suppression.enr_threshold << ",";
715 ost << "\"max_gain_during_echo\": "
Per Åhgren17e4c582019-11-27 08:13:24 +0100716 << config.suppressor.high_bands_suppression.max_gain_during_echo << ",";
717 ost << "\"anti_howling_activation_threshold\": "
718 << config.suppressor.high_bands_suppression
719 .anti_howling_activation_threshold
720 << ",";
721 ost << "\"anti_howling_gain\": "
722 << config.suppressor.high_bands_suppression.anti_howling_gain;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200723 ost << "},";
Gustaf Ullberg7e4ad822020-10-22 14:36:37 +0200724 ost << "\"floor_first_increase\": " << config.suppressor.floor_first_increase
725 << ",";
726 ost << "\"conservative_hf_suppression\": "
727 << config.suppressor.conservative_hf_suppression;
Sam Zackrissona4c85142018-10-10 10:44:43 +0200728 ost << "}";
729 ost << "}";
730 ost << "}";
731
732 return ost.Release();
733}
734} // namespace webrtc