Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 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_json.h" |
| 11 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 13 | |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "rtc_base/checks.h" |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 18 | #include "rtc_base/logging.h" |
| 19 | #include "rtc_base/strings/json.h" |
| 20 | #include "rtc_base/strings/string_builder.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | namespace { |
| 24 | void ReadParam(const Json::Value& root, std::string param_name, bool* param) { |
| 25 | RTC_DCHECK(param); |
| 26 | bool v; |
| 27 | if (rtc::GetBoolFromJsonObject(root, param_name, &v)) { |
| 28 | *param = v; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | void ReadParam(const Json::Value& root, std::string param_name, size_t* param) { |
| 33 | RTC_DCHECK(param); |
| 34 | int v; |
Sam Zackrisson | 528a034 | 2019-10-22 11:36:17 +0200 | [diff] [blame] | 35 | if (rtc::GetIntFromJsonObject(root, param_name, &v) && v >= 0) { |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 36 | *param = v; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void ReadParam(const Json::Value& root, std::string param_name, int* param) { |
| 41 | RTC_DCHECK(param); |
| 42 | int v; |
| 43 | if (rtc::GetIntFromJsonObject(root, param_name, &v)) { |
| 44 | *param = v; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void ReadParam(const Json::Value& root, std::string param_name, float* param) { |
| 49 | RTC_DCHECK(param); |
| 50 | double v; |
| 51 | if (rtc::GetDoubleFromJsonObject(root, param_name, &v)) { |
| 52 | *param = static_cast<float>(v); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void ReadParam(const Json::Value& root, |
| 57 | std::string param_name, |
| 58 | EchoCanceller3Config::Filter::MainConfiguration* param) { |
Sam Zackrisson | 703259c | 2018-10-10 17:17:43 +0200 | [diff] [blame] | 59 | RTC_DCHECK(param); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 60 | Json::Value json_array; |
| 61 | if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { |
| 62 | std::vector<double> v; |
| 63 | rtc::JsonArrayToDoubleVector(json_array, &v); |
| 64 | if (v.size() != 6) { |
| 65 | RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; |
Sam Zackrisson | 703259c | 2018-10-10 17:17:43 +0200 | [diff] [blame] | 66 | return; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 67 | } |
| 68 | param->length_blocks = static_cast<size_t>(v[0]); |
| 69 | param->leakage_converged = static_cast<float>(v[1]); |
| 70 | param->leakage_diverged = static_cast<float>(v[2]); |
| 71 | param->error_floor = static_cast<float>(v[3]); |
| 72 | param->error_ceil = static_cast<float>(v[4]); |
| 73 | param->noise_gate = static_cast<float>(v[5]); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void ReadParam(const Json::Value& root, |
| 78 | std::string param_name, |
| 79 | EchoCanceller3Config::Filter::ShadowConfiguration* param) { |
Sam Zackrisson | 703259c | 2018-10-10 17:17:43 +0200 | [diff] [blame] | 80 | RTC_DCHECK(param); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 81 | Json::Value json_array; |
| 82 | if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { |
| 83 | std::vector<double> v; |
| 84 | rtc::JsonArrayToDoubleVector(json_array, &v); |
| 85 | if (v.size() != 3) { |
| 86 | RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; |
Sam Zackrisson | 703259c | 2018-10-10 17:17:43 +0200 | [diff] [blame] | 87 | return; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 88 | } |
| 89 | param->length_blocks = static_cast<size_t>(v[0]); |
| 90 | param->rate = static_cast<float>(v[1]); |
| 91 | param->noise_gate = static_cast<float>(v[2]); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void ReadParam(const Json::Value& root, |
| 96 | std::string param_name, |
| 97 | EchoCanceller3Config::Suppressor::MaskingThresholds* param) { |
Sam Zackrisson | 703259c | 2018-10-10 17:17:43 +0200 | [diff] [blame] | 98 | RTC_DCHECK(param); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 99 | Json::Value json_array; |
| 100 | if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { |
| 101 | std::vector<double> v; |
| 102 | rtc::JsonArrayToDoubleVector(json_array, &v); |
| 103 | if (v.size() != 3) { |
| 104 | RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; |
Sam Zackrisson | 703259c | 2018-10-10 17:17:43 +0200 | [diff] [blame] | 105 | return; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 106 | } |
| 107 | param->enr_transparent = static_cast<float>(v[0]); |
| 108 | param->enr_suppress = static_cast<float>(v[1]); |
| 109 | param->emr_transparent = static_cast<float>(v[2]); |
| 110 | } |
| 111 | } |
| 112 | } // namespace |
| 113 | |
Per Åhgren | 370bae4 | 2018-10-25 11:32:39 +0200 | [diff] [blame] | 114 | void Aec3ConfigFromJsonString(absl::string_view json_string, |
| 115 | EchoCanceller3Config* config, |
| 116 | bool* parsing_successful) { |
| 117 | RTC_DCHECK(config); |
| 118 | RTC_DCHECK(parsing_successful); |
| 119 | EchoCanceller3Config& cfg = *config; |
| 120 | cfg = EchoCanceller3Config(); |
| 121 | *parsing_successful = true; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 122 | |
| 123 | Json::Value root; |
| 124 | bool success = Json::Reader().parse(std::string(json_string), root); |
| 125 | if (!success) { |
| 126 | RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << json_string; |
Per Åhgren | 370bae4 | 2018-10-25 11:32:39 +0200 | [diff] [blame] | 127 | *parsing_successful = false; |
| 128 | return; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | Json::Value aec3_root; |
| 132 | success = rtc::GetValueFromJsonObject(root, "aec3", &aec3_root); |
| 133 | if (!success) { |
| 134 | RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string; |
Per Åhgren | 370bae4 | 2018-10-25 11:32:39 +0200 | [diff] [blame] | 135 | *parsing_successful = false; |
| 136 | return; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | Json::Value section; |
Per Åhgren | c1d2092 | 2019-04-22 23:36:58 +0200 | [diff] [blame] | 140 | if (rtc::GetValueFromJsonObject(aec3_root, "buffering", §ion)) { |
Gustaf Ullberg | 11539f0 | 2018-10-15 13:40:29 +0200 | [diff] [blame] | 141 | ReadParam(section, "excess_render_detection_interval_blocks", |
| 142 | &cfg.buffering.excess_render_detection_interval_blocks); |
| 143 | ReadParam(section, "max_allowed_excess_render_blocks", |
| 144 | &cfg.buffering.max_allowed_excess_render_blocks); |
| 145 | } |
| 146 | |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 147 | if (rtc::GetValueFromJsonObject(aec3_root, "delay", §ion)) { |
| 148 | ReadParam(section, "default_delay", &cfg.delay.default_delay); |
| 149 | ReadParam(section, "down_sampling_factor", &cfg.delay.down_sampling_factor); |
| 150 | ReadParam(section, "num_filters", &cfg.delay.num_filters); |
Gustaf Ullberg | 9249fbf | 2019-03-14 11:24:54 +0100 | [diff] [blame] | 151 | ReadParam(section, "delay_headroom_samples", |
| 152 | &cfg.delay.delay_headroom_samples); |
| 153 | ReadParam(section, "hysteresis_limit_blocks", |
| 154 | &cfg.delay.hysteresis_limit_blocks); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 155 | ReadParam(section, "fixed_capture_delay_samples", |
| 156 | &cfg.delay.fixed_capture_delay_samples); |
| 157 | ReadParam(section, "delay_estimate_smoothing", |
| 158 | &cfg.delay.delay_estimate_smoothing); |
| 159 | ReadParam(section, "delay_candidate_detection_threshold", |
| 160 | &cfg.delay.delay_candidate_detection_threshold); |
| 161 | |
| 162 | Json::Value subsection; |
| 163 | if (rtc::GetValueFromJsonObject(section, "delay_selection_thresholds", |
| 164 | &subsection)) { |
| 165 | ReadParam(subsection, "initial", |
| 166 | &cfg.delay.delay_selection_thresholds.initial); |
| 167 | ReadParam(subsection, "converged", |
| 168 | &cfg.delay.delay_selection_thresholds.converged); |
| 169 | } |
Gustaf Ullberg | 52caa0e | 2019-04-11 14:43:17 +0200 | [diff] [blame] | 170 | |
| 171 | ReadParam(section, "use_external_delay_estimator", |
| 172 | &cfg.delay.use_external_delay_estimator); |
Gustaf Ullberg | ee84d39 | 2019-09-10 09:36:43 +0200 | [diff] [blame] | 173 | ReadParam(section, "downmix_before_delay_estimation", |
| 174 | &cfg.delay.downmix_before_delay_estimation); |
Sam Zackrisson | ffc8452 | 2019-10-15 13:43:02 +0200 | [diff] [blame] | 175 | ReadParam(section, "log_warning_on_delay_changes", |
| 176 | &cfg.delay.log_warning_on_delay_changes); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | if (rtc::GetValueFromJsonObject(aec3_root, "filter", §ion)) { |
| 180 | ReadParam(section, "main", &cfg.filter.main); |
| 181 | ReadParam(section, "shadow", &cfg.filter.shadow); |
| 182 | ReadParam(section, "main_initial", &cfg.filter.main_initial); |
| 183 | ReadParam(section, "shadow_initial", &cfg.filter.shadow_initial); |
| 184 | ReadParam(section, "config_change_duration_blocks", |
| 185 | &cfg.filter.config_change_duration_blocks); |
| 186 | ReadParam(section, "initial_state_seconds", |
| 187 | &cfg.filter.initial_state_seconds); |
| 188 | ReadParam(section, "conservative_initial_phase", |
| 189 | &cfg.filter.conservative_initial_phase); |
| 190 | ReadParam(section, "enable_shadow_filter_output_usage", |
| 191 | &cfg.filter.enable_shadow_filter_output_usage); |
Gustaf Ullberg | 52caa0e | 2019-04-11 14:43:17 +0200 | [diff] [blame] | 192 | ReadParam(section, "use_linear_filter", &cfg.filter.use_linear_filter); |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 193 | ReadParam(section, "export_linear_aec_output", |
| 194 | &cfg.filter.export_linear_aec_output); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | if (rtc::GetValueFromJsonObject(aec3_root, "erle", §ion)) { |
| 198 | ReadParam(section, "min", &cfg.erle.min); |
| 199 | ReadParam(section, "max_l", &cfg.erle.max_l); |
| 200 | ReadParam(section, "max_h", &cfg.erle.max_h); |
| 201 | ReadParam(section, "onset_detection", &cfg.erle.onset_detection); |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 202 | ReadParam(section, "num_sections", &cfg.erle.num_sections); |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 203 | ReadParam(section, "clamp_quality_estimate_to_zero", |
| 204 | &cfg.erle.clamp_quality_estimate_to_zero); |
| 205 | ReadParam(section, "clamp_quality_estimate_to_one", |
| 206 | &cfg.erle.clamp_quality_estimate_to_one); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | if (rtc::GetValueFromJsonObject(aec3_root, "ep_strength", §ion)) { |
Per Åhgren | e8efbbd | 2019-03-14 11:29:39 +0100 | [diff] [blame] | 210 | ReadParam(section, "default_gain", &cfg.ep_strength.default_gain); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 211 | ReadParam(section, "default_len", &cfg.ep_strength.default_len); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 212 | ReadParam(section, "echo_can_saturate", &cfg.ep_strength.echo_can_saturate); |
| 213 | ReadParam(section, "bounded_erl", &cfg.ep_strength.bounded_erl); |
| 214 | } |
| 215 | |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 216 | if (rtc::GetValueFromJsonObject(aec3_root, "echo_audibility", §ion)) { |
| 217 | ReadParam(section, "low_render_limit", |
| 218 | &cfg.echo_audibility.low_render_limit); |
| 219 | ReadParam(section, "normal_render_limit", |
| 220 | &cfg.echo_audibility.normal_render_limit); |
| 221 | |
| 222 | ReadParam(section, "floor_power", &cfg.echo_audibility.floor_power); |
| 223 | ReadParam(section, "audibility_threshold_lf", |
| 224 | &cfg.echo_audibility.audibility_threshold_lf); |
| 225 | ReadParam(section, "audibility_threshold_mf", |
| 226 | &cfg.echo_audibility.audibility_threshold_mf); |
| 227 | ReadParam(section, "audibility_threshold_hf", |
| 228 | &cfg.echo_audibility.audibility_threshold_hf); |
Jesús de Vicente Peña | 70a5963 | 2019-04-16 12:32:15 +0200 | [diff] [blame] | 229 | ReadParam(section, "use_stationarity_properties", |
| 230 | &cfg.echo_audibility.use_stationarity_properties); |
Sam Zackrisson | 877dc89 | 2018-10-23 14:17:38 +0200 | [diff] [blame] | 231 | ReadParam(section, "use_stationarity_properties_at_init", |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 232 | &cfg.echo_audibility.use_stationarity_properties_at_init); |
| 233 | } |
| 234 | |
Per Åhgren | 01cf44d | 2018-10-20 00:17:13 +0200 | [diff] [blame] | 235 | if (rtc::GetValueFromJsonObject(aec3_root, "render_levels", §ion)) { |
| 236 | ReadParam(section, "active_render_limit", |
| 237 | &cfg.render_levels.active_render_limit); |
| 238 | ReadParam(section, "poor_excitation_render_limit", |
| 239 | &cfg.render_levels.poor_excitation_render_limit); |
| 240 | ReadParam(section, "poor_excitation_render_limit_ds8", |
| 241 | &cfg.render_levels.poor_excitation_render_limit_ds8); |
Per Åhgren | ae40e19 | 2019-10-29 22:54:05 +0100 | [diff] [blame] | 242 | ReadParam(section, "render_power_gain_db", |
| 243 | &cfg.render_levels.render_power_gain_db); |
Per Åhgren | 01cf44d | 2018-10-20 00:17:13 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 246 | if (rtc::GetValueFromJsonObject(aec3_root, "echo_removal_control", |
| 247 | §ion)) { |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 248 | ReadParam(section, "has_clock_drift", |
| 249 | &cfg.echo_removal_control.has_clock_drift); |
| 250 | ReadParam(section, "linear_and_stable_echo_path", |
| 251 | &cfg.echo_removal_control.linear_and_stable_echo_path); |
| 252 | } |
| 253 | |
| 254 | if (rtc::GetValueFromJsonObject(aec3_root, "echo_model", §ion)) { |
| 255 | Json::Value subsection; |
| 256 | ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold); |
| 257 | ReadParam(section, "min_noise_floor_power", |
| 258 | &cfg.echo_model.min_noise_floor_power); |
| 259 | ReadParam(section, "stationary_gate_slope", |
| 260 | &cfg.echo_model.stationary_gate_slope); |
| 261 | ReadParam(section, "noise_gate_power", &cfg.echo_model.noise_gate_power); |
| 262 | ReadParam(section, "noise_gate_slope", &cfg.echo_model.noise_gate_slope); |
| 263 | ReadParam(section, "render_pre_window_size", |
| 264 | &cfg.echo_model.render_pre_window_size); |
| 265 | ReadParam(section, "render_post_window_size", |
| 266 | &cfg.echo_model.render_post_window_size); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | Json::Value subsection; |
| 270 | if (rtc::GetValueFromJsonObject(aec3_root, "suppressor", §ion)) { |
| 271 | ReadParam(section, "nearend_average_blocks", |
| 272 | &cfg.suppressor.nearend_average_blocks); |
| 273 | |
| 274 | if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) { |
| 275 | ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf); |
| 276 | ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf); |
| 277 | ReadParam(subsection, "max_inc_factor", |
| 278 | &cfg.suppressor.normal_tuning.max_inc_factor); |
| 279 | ReadParam(subsection, "max_dec_factor_lf", |
| 280 | &cfg.suppressor.normal_tuning.max_dec_factor_lf); |
| 281 | } |
| 282 | |
| 283 | if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) { |
| 284 | ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf); |
| 285 | ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf); |
| 286 | ReadParam(subsection, "max_inc_factor", |
| 287 | &cfg.suppressor.nearend_tuning.max_inc_factor); |
| 288 | ReadParam(subsection, "max_dec_factor_lf", |
| 289 | &cfg.suppressor.nearend_tuning.max_dec_factor_lf); |
| 290 | } |
| 291 | |
| 292 | if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection", |
| 293 | &subsection)) { |
| 294 | ReadParam(subsection, "enr_threshold", |
| 295 | &cfg.suppressor.dominant_nearend_detection.enr_threshold); |
Gustaf Ullberg | c9f9b87 | 2018-10-22 15:15:36 +0200 | [diff] [blame] | 296 | ReadParam(subsection, "enr_exit_threshold", |
| 297 | &cfg.suppressor.dominant_nearend_detection.enr_exit_threshold); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 298 | ReadParam(subsection, "snr_threshold", |
| 299 | &cfg.suppressor.dominant_nearend_detection.snr_threshold); |
| 300 | ReadParam(subsection, "hold_duration", |
| 301 | &cfg.suppressor.dominant_nearend_detection.hold_duration); |
| 302 | ReadParam(subsection, "trigger_threshold", |
| 303 | &cfg.suppressor.dominant_nearend_detection.trigger_threshold); |
Per Åhgren | fb5c1ec | 2018-10-24 13:02:11 +0200 | [diff] [blame] | 304 | ReadParam( |
| 305 | subsection, "use_during_initial_phase", |
| 306 | &cfg.suppressor.dominant_nearend_detection.use_during_initial_phase); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | if (rtc::GetValueFromJsonObject(section, "high_bands_suppression", |
| 310 | &subsection)) { |
| 311 | ReadParam(subsection, "enr_threshold", |
| 312 | &cfg.suppressor.high_bands_suppression.enr_threshold); |
| 313 | ReadParam(subsection, "max_gain_during_echo", |
| 314 | &cfg.suppressor.high_bands_suppression.max_gain_during_echo); |
| 315 | } |
| 316 | |
| 317 | ReadParam(section, "floor_first_increase", |
| 318 | &cfg.suppressor.floor_first_increase); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 319 | } |
Per Åhgren | 370bae4 | 2018-10-25 11:32:39 +0200 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) { |
| 323 | EchoCanceller3Config cfg; |
| 324 | bool not_used; |
| 325 | Aec3ConfigFromJsonString(json_string, &cfg, ¬_used); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 326 | return cfg; |
| 327 | } |
| 328 | |
| 329 | std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) { |
| 330 | rtc::StringBuilder ost; |
| 331 | ost << "{"; |
| 332 | ost << "\"aec3\": {"; |
Per Åhgren | c1d2092 | 2019-04-22 23:36:58 +0200 | [diff] [blame] | 333 | ost << "\"buffering\": {"; |
| 334 | ost << "\"excess_render_detection_interval_blocks\": " |
| 335 | << config.buffering.excess_render_detection_interval_blocks << ","; |
| 336 | ost << "\"max_allowed_excess_render_blocks\": " |
| 337 | << config.buffering.max_allowed_excess_render_blocks; |
| 338 | ost << "},"; |
| 339 | |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 340 | ost << "\"delay\": {"; |
| 341 | ost << "\"default_delay\": " << config.delay.default_delay << ","; |
| 342 | ost << "\"down_sampling_factor\": " << config.delay.down_sampling_factor |
| 343 | << ","; |
| 344 | ost << "\"num_filters\": " << config.delay.num_filters << ","; |
Gustaf Ullberg | 9249fbf | 2019-03-14 11:24:54 +0100 | [diff] [blame] | 345 | ost << "\"delay_headroom_samples\": " << config.delay.delay_headroom_samples |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 346 | << ","; |
Gustaf Ullberg | 9249fbf | 2019-03-14 11:24:54 +0100 | [diff] [blame] | 347 | ost << "\"hysteresis_limit_blocks\": " << config.delay.hysteresis_limit_blocks |
| 348 | << ","; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 349 | ost << "\"fixed_capture_delay_samples\": " |
| 350 | << config.delay.fixed_capture_delay_samples << ","; |
| 351 | ost << "\"delay_estimate_smoothing\": " |
| 352 | << config.delay.delay_estimate_smoothing << ","; |
| 353 | ost << "\"delay_candidate_detection_threshold\": " |
| 354 | << config.delay.delay_candidate_detection_threshold << ","; |
| 355 | |
| 356 | ost << "\"delay_selection_thresholds\": {"; |
| 357 | ost << "\"initial\": " << config.delay.delay_selection_thresholds.initial |
| 358 | << ","; |
| 359 | ost << "\"converged\": " << config.delay.delay_selection_thresholds.converged; |
Gustaf Ullberg | ee84d39 | 2019-09-10 09:36:43 +0200 | [diff] [blame] | 360 | ost << "},"; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 361 | |
Gustaf Ullberg | ee84d39 | 2019-09-10 09:36:43 +0200 | [diff] [blame] | 362 | ost << "\"use_external_delay_estimator\": " |
| 363 | << (config.delay.use_external_delay_estimator ? "true" : "false") << ","; |
| 364 | ost << "\"downmix_before_delay_estimation\": " |
Sam Zackrisson | ffc8452 | 2019-10-15 13:43:02 +0200 | [diff] [blame] | 365 | << (config.delay.downmix_before_delay_estimation ? "true" : "false") |
| 366 | << ","; |
| 367 | ost << "\"log_warning_on_delay_changes\": " |
| 368 | << (config.delay.log_warning_on_delay_changes ? "true" : "false"); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 369 | ost << "},"; |
| 370 | |
| 371 | ost << "\"filter\": {"; |
| 372 | ost << "\"main\": ["; |
| 373 | ost << config.filter.main.length_blocks << ","; |
| 374 | ost << config.filter.main.leakage_converged << ","; |
| 375 | ost << config.filter.main.leakage_diverged << ","; |
| 376 | ost << config.filter.main.error_floor << ","; |
| 377 | ost << config.filter.main.error_ceil << ","; |
| 378 | ost << config.filter.main.noise_gate; |
| 379 | ost << "],"; |
| 380 | |
| 381 | ost << "\"shadow\": ["; |
| 382 | ost << config.filter.shadow.length_blocks << ","; |
| 383 | ost << config.filter.shadow.rate << ","; |
| 384 | ost << config.filter.shadow.noise_gate; |
| 385 | ost << "],"; |
| 386 | |
| 387 | ost << "\"main_initial\": ["; |
| 388 | ost << config.filter.main_initial.length_blocks << ","; |
| 389 | ost << config.filter.main_initial.leakage_converged << ","; |
| 390 | ost << config.filter.main_initial.leakage_diverged << ","; |
| 391 | ost << config.filter.main_initial.error_floor << ","; |
| 392 | ost << config.filter.main_initial.error_ceil << ","; |
| 393 | ost << config.filter.main_initial.noise_gate; |
| 394 | ost << "],"; |
| 395 | |
| 396 | ost << "\"shadow_initial\": ["; |
| 397 | ost << config.filter.shadow_initial.length_blocks << ","; |
| 398 | ost << config.filter.shadow_initial.rate << ","; |
| 399 | ost << config.filter.shadow_initial.noise_gate; |
| 400 | ost << "],"; |
| 401 | |
| 402 | ost << "\"config_change_duration_blocks\": " |
| 403 | << config.filter.config_change_duration_blocks << ","; |
| 404 | ost << "\"initial_state_seconds\": " << config.filter.initial_state_seconds |
| 405 | << ","; |
| 406 | ost << "\"conservative_initial_phase\": " |
| 407 | << (config.filter.conservative_initial_phase ? "true" : "false") << ","; |
| 408 | ost << "\"enable_shadow_filter_output_usage\": " |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 409 | << (config.filter.enable_shadow_filter_output_usage ? "true" : "false") |
| 410 | << ","; |
| 411 | ost << "\"use_linear_filter\": " |
| 412 | << (config.filter.use_linear_filter ? "true" : "false") << ","; |
| 413 | ost << "\"export_linear_aec_output\": " |
| 414 | << (config.filter.export_linear_aec_output ? "true" : "false"); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 415 | |
| 416 | ost << "},"; |
| 417 | |
| 418 | ost << "\"erle\": {"; |
| 419 | ost << "\"min\": " << config.erle.min << ","; |
| 420 | ost << "\"max_l\": " << config.erle.max_l << ","; |
| 421 | ost << "\"max_h\": " << config.erle.max_h << ","; |
| 422 | ost << "\"onset_detection\": " |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 423 | << (config.erle.onset_detection ? "true" : "false") << ","; |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 424 | ost << "\"num_sections\": " << config.erle.num_sections << ","; |
| 425 | ost << "\"clamp_quality_estimate_to_zero\": " |
| 426 | << (config.erle.clamp_quality_estimate_to_zero ? "true" : "false") << ","; |
| 427 | ost << "\"clamp_quality_estimate_to_one\": " |
| 428 | << (config.erle.clamp_quality_estimate_to_one ? "true" : "false"); |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 429 | ost << "},"; |
| 430 | |
| 431 | ost << "\"ep_strength\": {"; |
Per Åhgren | e8efbbd | 2019-03-14 11:29:39 +0100 | [diff] [blame] | 432 | ost << "\"default_gain\": " << config.ep_strength.default_gain << ","; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 433 | ost << "\"default_len\": " << config.ep_strength.default_len << ","; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 434 | ost << "\"echo_can_saturate\": " |
| 435 | << (config.ep_strength.echo_can_saturate ? "true" : "false") << ","; |
| 436 | ost << "\"bounded_erl\": " |
| 437 | << (config.ep_strength.bounded_erl ? "true" : "false"); |
| 438 | |
| 439 | ost << "},"; |
| 440 | |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 441 | ost << "\"echo_audibility\": {"; |
| 442 | ost << "\"low_render_limit\": " << config.echo_audibility.low_render_limit |
| 443 | << ","; |
| 444 | ost << "\"normal_render_limit\": " |
| 445 | << config.echo_audibility.normal_render_limit << ","; |
| 446 | ost << "\"floor_power\": " << config.echo_audibility.floor_power << ","; |
| 447 | ost << "\"audibility_threshold_lf\": " |
| 448 | << config.echo_audibility.audibility_threshold_lf << ","; |
| 449 | ost << "\"audibility_threshold_mf\": " |
| 450 | << config.echo_audibility.audibility_threshold_mf << ","; |
| 451 | ost << "\"audibility_threshold_hf\": " |
| 452 | << config.echo_audibility.audibility_threshold_hf << ","; |
Jesús de Vicente Peña | 70a5963 | 2019-04-16 12:32:15 +0200 | [diff] [blame] | 453 | ost << "\"use_stationarity_properties\": " |
| 454 | << (config.echo_audibility.use_stationarity_properties ? "true" : "false") |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 455 | << ","; |
| 456 | ost << "\"use_stationarity_properties_at_init\": " |
| 457 | << (config.echo_audibility.use_stationarity_properties_at_init ? "true" |
| 458 | : "false"); |
| 459 | ost << "},"; |
| 460 | |
| 461 | ost << "\"render_levels\": {"; |
| 462 | ost << "\"active_render_limit\": " << config.render_levels.active_render_limit |
| 463 | << ","; |
| 464 | ost << "\"poor_excitation_render_limit\": " |
| 465 | << config.render_levels.poor_excitation_render_limit << ","; |
| 466 | ost << "\"poor_excitation_render_limit_ds8\": " |
Per Åhgren | ae40e19 | 2019-10-29 22:54:05 +0100 | [diff] [blame] | 467 | << config.render_levels.poor_excitation_render_limit_ds8 << ","; |
| 468 | ost << "\"render_power_gain_db\": " |
| 469 | << config.render_levels.render_power_gain_db; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 470 | ost << "},"; |
| 471 | |
| 472 | ost << "\"echo_removal_control\": {"; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 473 | ost << "\"has_clock_drift\": " |
| 474 | << (config.echo_removal_control.has_clock_drift ? "true" : "false") |
| 475 | << ","; |
| 476 | ost << "\"linear_and_stable_echo_path\": " |
| 477 | << (config.echo_removal_control.linear_and_stable_echo_path ? "true" |
| 478 | : "false"); |
| 479 | |
| 480 | ost << "},"; |
| 481 | |
| 482 | ost << "\"echo_model\": {"; |
| 483 | ost << "\"noise_floor_hold\": " << config.echo_model.noise_floor_hold << ","; |
| 484 | ost << "\"min_noise_floor_power\": " |
| 485 | << config.echo_model.min_noise_floor_power << ","; |
| 486 | ost << "\"stationary_gate_slope\": " |
| 487 | << config.echo_model.stationary_gate_slope << ","; |
| 488 | ost << "\"noise_gate_power\": " << config.echo_model.noise_gate_power << ","; |
| 489 | ost << "\"noise_gate_slope\": " << config.echo_model.noise_gate_slope << ","; |
| 490 | ost << "\"render_pre_window_size\": " |
| 491 | << config.echo_model.render_pre_window_size << ","; |
| 492 | ost << "\"render_post_window_size\": " |
Gustaf Ullberg | ec51ce0 | 2019-04-04 13:38:52 +0200 | [diff] [blame] | 493 | << config.echo_model.render_post_window_size; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 494 | ost << "},"; |
| 495 | |
| 496 | ost << "\"suppressor\": {"; |
| 497 | ost << "\"nearend_average_blocks\": " |
| 498 | << config.suppressor.nearend_average_blocks << ","; |
| 499 | ost << "\"normal_tuning\": {"; |
| 500 | ost << "\"mask_lf\": ["; |
| 501 | ost << config.suppressor.normal_tuning.mask_lf.enr_transparent << ","; |
| 502 | ost << config.suppressor.normal_tuning.mask_lf.enr_suppress << ","; |
| 503 | ost << config.suppressor.normal_tuning.mask_lf.emr_transparent; |
| 504 | ost << "],"; |
| 505 | ost << "\"mask_hf\": ["; |
| 506 | ost << config.suppressor.normal_tuning.mask_hf.enr_transparent << ","; |
| 507 | ost << config.suppressor.normal_tuning.mask_hf.enr_suppress << ","; |
| 508 | ost << config.suppressor.normal_tuning.mask_hf.emr_transparent; |
| 509 | ost << "],"; |
| 510 | ost << "\"max_inc_factor\": " |
| 511 | << config.suppressor.normal_tuning.max_inc_factor << ","; |
| 512 | ost << "\"max_dec_factor_lf\": " |
| 513 | << config.suppressor.normal_tuning.max_dec_factor_lf; |
| 514 | ost << "},"; |
| 515 | ost << "\"nearend_tuning\": {"; |
| 516 | ost << "\"mask_lf\": ["; |
| 517 | ost << config.suppressor.nearend_tuning.mask_lf.enr_transparent << ","; |
| 518 | ost << config.suppressor.nearend_tuning.mask_lf.enr_suppress << ","; |
| 519 | ost << config.suppressor.nearend_tuning.mask_lf.emr_transparent; |
| 520 | ost << "],"; |
| 521 | ost << "\"mask_hf\": ["; |
| 522 | ost << config.suppressor.nearend_tuning.mask_hf.enr_transparent << ","; |
| 523 | ost << config.suppressor.nearend_tuning.mask_hf.enr_suppress << ","; |
| 524 | ost << config.suppressor.nearend_tuning.mask_hf.emr_transparent; |
| 525 | ost << "],"; |
| 526 | ost << "\"max_inc_factor\": " |
| 527 | << config.suppressor.nearend_tuning.max_inc_factor << ","; |
| 528 | ost << "\"max_dec_factor_lf\": " |
| 529 | << config.suppressor.nearend_tuning.max_dec_factor_lf; |
| 530 | ost << "},"; |
| 531 | ost << "\"dominant_nearend_detection\": {"; |
| 532 | ost << "\"enr_threshold\": " |
| 533 | << config.suppressor.dominant_nearend_detection.enr_threshold << ","; |
Gustaf Ullberg | c9f9b87 | 2018-10-22 15:15:36 +0200 | [diff] [blame] | 534 | ost << "\"enr_exit_threshold\": " |
| 535 | << config.suppressor.dominant_nearend_detection.enr_exit_threshold << ","; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 536 | ost << "\"snr_threshold\": " |
| 537 | << config.suppressor.dominant_nearend_detection.snr_threshold << ","; |
| 538 | ost << "\"hold_duration\": " |
| 539 | << config.suppressor.dominant_nearend_detection.hold_duration << ","; |
| 540 | ost << "\"trigger_threshold\": " |
Per Åhgren | fb5c1ec | 2018-10-24 13:02:11 +0200 | [diff] [blame] | 541 | << config.suppressor.dominant_nearend_detection.trigger_threshold << ","; |
| 542 | ost << "\"use_during_initial_phase\": " |
| 543 | << config.suppressor.dominant_nearend_detection.use_during_initial_phase; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 544 | ost << "},"; |
| 545 | ost << "\"high_bands_suppression\": {"; |
| 546 | ost << "\"enr_threshold\": " |
| 547 | << config.suppressor.high_bands_suppression.enr_threshold << ","; |
| 548 | ost << "\"max_gain_during_echo\": " |
| 549 | << config.suppressor.high_bands_suppression.max_gain_during_echo; |
| 550 | ost << "},"; |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 551 | ost << "\"floor_first_increase\": " << config.suppressor.floor_first_increase; |
Sam Zackrisson | a4c8514 | 2018-10-10 10:44:43 +0200 | [diff] [blame] | 552 | ost << "}"; |
| 553 | ost << "}"; |
| 554 | ost << "}"; |
| 555 | |
| 556 | return ost.Release(); |
| 557 | } |
| 558 | } // namespace webrtc |