Add JSON parsing and corresponding ToString to EchoCanceller3Config

Bug: webrtc:9535
Change-Id: I51eaaac4009a30536444292a32938b21e69386bf
Reviewed-on: https://webrtc-review.googlesource.com/c/102980
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25083}
This commit is contained in:
Sam Zackrisson 2018-10-10 10:44:43 +02:00 committed by Commit Bot
parent 2558c4e938
commit a4c8514258
10 changed files with 956 additions and 600 deletions

View File

@ -39,6 +39,24 @@ rtc_source_set("aec3_config") {
"echo_canceller3_config.cc",
"echo_canceller3_config.h",
]
deps = [
"../../rtc_base:rtc_base_approved",
"../../rtc_base:safe_minmax",
]
}
rtc_source_set("aec3_config_json") {
visibility = [ "*" ]
sources = [
"echo_canceller3_config_json.cc",
"echo_canceller3_config_json.h",
]
deps = [
":aec3_config",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_json",
"//third_party/abseil-cpp/absl/strings:strings",
]
}
rtc_source_set("aec3_factory") {

View File

@ -9,7 +9,34 @@
*/
#include "api/audio/echo_canceller3_config.h"
#include <algorithm>
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h"
namespace webrtc {
namespace {
bool Limit(float* value, float min, float max) {
float clamped = rtc::SafeClamp(*value, min, max);
bool res = *value == clamped;
*value = clamped;
return res;
}
bool Limit(size_t* value, size_t min, size_t max) {
size_t clamped = rtc::SafeClamp(*value, min, max);
bool res = *value == clamped;
*value = clamped;
return res;
}
bool Limit(int* value, int min, int max) {
int clamped = rtc::SafeClamp(*value, min, max);
bool res = *value == clamped;
*value = clamped;
return res;
}
} // namespace
EchoCanceller3Config::EchoCanceller3Config() = default;
EchoCanceller3Config::EchoCanceller3Config(const EchoCanceller3Config& e) =
@ -51,4 +78,191 @@ EchoCanceller3Config::Suppressor::Tuning::Tuning(MaskingThresholds mask_lf,
EchoCanceller3Config::Suppressor::Tuning::Tuning(
const EchoCanceller3Config::Suppressor::Tuning& e) = default;
bool EchoCanceller3Config::Validate(EchoCanceller3Config* config) {
RTC_DCHECK(config);
EchoCanceller3Config* c = config;
bool res = true;
if (c->delay.down_sampling_factor != 4 &&
c->delay.down_sampling_factor != 8) {
c->delay.down_sampling_factor = 4;
res = false;
}
if (c->delay.num_filters == 0) {
c->delay.num_filters = 1;
res = false;
}
if (c->delay.api_call_jitter_blocks == 0) {
c->delay.api_call_jitter_blocks = 1;
res = false;
}
if (c->delay.api_call_jitter_blocks == 0) {
c->delay.api_call_jitter_blocks = 1;
res = false;
}
if (c->delay.delay_headroom_blocks <= 1 &&
c->delay.hysteresis_limit_1_blocks == 1) {
c->delay.hysteresis_limit_1_blocks = 0;
res = false;
}
res = res && Limit(&c->delay.delay_estimate_smoothing, 0.f, 1.f);
res = res && Limit(&c->delay.delay_candidate_detection_threshold, 0.f, 1.f);
res = res && Limit(&c->delay.delay_selection_thresholds.initial, 1, 250);
res = res && Limit(&c->delay.delay_selection_thresholds.converged, 1, 250);
res = res && Limit(&c->filter.main.length_blocks, 1, 50);
res = res && Limit(&c->filter.main.leakage_converged, 0.f, 1000.f);
res = res && Limit(&c->filter.main.leakage_diverged, 0.f, 1000.f);
res = res && Limit(&c->filter.main.error_floor, 0.f, 1000.f);
res = res && Limit(&c->filter.main.noise_gate, 0.f, 100000000.f);
res = res && Limit(&c->filter.main_initial.length_blocks, 1, 50);
res = res && Limit(&c->filter.main_initial.leakage_converged, 0.f, 1000.f);
res = res && Limit(&c->filter.main_initial.leakage_diverged, 0.f, 1000.f);
res = res && Limit(&c->filter.main_initial.error_floor, 0.f, 1000.f);
res = res && Limit(&c->filter.main_initial.noise_gate, 0.f, 100000000.f);
if (c->filter.main.length_blocks < c->filter.main_initial.length_blocks) {
c->filter.main_initial.length_blocks = c->filter.main.length_blocks;
res = false;
}
res = res && Limit(&c->filter.shadow.length_blocks, 1, 50);
res = res && Limit(&c->filter.shadow.rate, 0.f, 1.f);
res = res && Limit(&c->filter.shadow.noise_gate, 0.f, 100000000.f);
res = res && Limit(&c->filter.shadow_initial.length_blocks, 1, 50);
res = res && Limit(&c->filter.shadow_initial.rate, 0.f, 1.f);
res = res && Limit(&c->filter.shadow_initial.noise_gate, 0.f, 100000000.f);
if (c->filter.shadow.length_blocks < c->filter.shadow_initial.length_blocks) {
c->filter.shadow_initial.length_blocks = c->filter.shadow.length_blocks;
res = false;
}
res = res && Limit(&c->filter.config_change_duration_blocks, 0, 100000);
res = res && Limit(&c->filter.initial_state_seconds, 0.f, 100.f);
res = res && Limit(&c->erle.min, 1.f, 100000.f);
res = res && Limit(&c->erle.max_l, 1.f, 100000.f);
res = res && Limit(&c->erle.max_h, 1.f, 100000.f);
if (c->erle.min > c->erle.max_l || c->erle.min > c->erle.max_h) {
c->erle.min = std::min(c->erle.max_l, c->erle.max_h);
res = false;
}
res = res && Limit(&c->ep_strength.lf, 0.f, 1000000.f);
res = res && Limit(&c->ep_strength.mf, 0.f, 1000000.f);
res = res && Limit(&c->ep_strength.hf, 0.f, 1000000.f);
res = res && Limit(&c->ep_strength.default_len, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m0, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m1, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m2, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m3, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m5, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m6, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m7, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m8, 0.f, 1.f);
res = res && Limit(&c->gain_mask.m9, 0.f, 1.f);
res = res && Limit(&c->gain_mask.gain_curve_offset, 0.f, 1000.f);
res = res && Limit(&c->gain_mask.gain_curve_slope, 0.f, 1000.f);
res = res && Limit(&c->gain_mask.temporal_masking_lf, 0.f, 1000.f);
res = res && Limit(&c->gain_mask.temporal_masking_hf, 0.f, 1000.f);
res = res && Limit(&c->gain_mask.temporal_masking_lf_bands, 0, 65);
res = res &&
Limit(&c->echo_audibility.low_render_limit, 0.f, 32768.f * 32768.f);
res = res &&
Limit(&c->echo_audibility.normal_render_limit, 0.f, 32768.f * 32768.f);
res = res && Limit(&c->echo_audibility.floor_power, 0.f, 32768.f * 32768.f);
res = res && Limit(&c->echo_audibility.audibility_threshold_lf, 0.f,
32768.f * 32768.f);
res = res && Limit(&c->echo_audibility.audibility_threshold_mf, 0.f,
32768.f * 32768.f);
res = res && Limit(&c->echo_audibility.audibility_threshold_hf, 0.f,
32768.f * 32768.f);
res = res &&
Limit(&c->render_levels.active_render_limit, 0.f, 32768.f * 32768.f);
res = res && Limit(&c->render_levels.poor_excitation_render_limit, 0.f,
32768.f * 32768.f);
res = res && Limit(&c->render_levels.poor_excitation_render_limit_ds8, 0.f,
32768.f * 32768.f);
res =
res && Limit(&c->echo_removal_control.gain_rampup.initial_gain, 0.f, 1.f);
res = res && Limit(&c->echo_removal_control.gain_rampup.first_non_zero_gain,
0.f, 1.f);
res = res && Limit(&c->echo_removal_control.gain_rampup.non_zero_gain_blocks,
0, 100000);
res = res &&
Limit(&c->echo_removal_control.gain_rampup.full_gain_blocks, 0, 100000);
res = res && Limit(&c->echo_model.noise_floor_hold, 0, 1000);
res = res && Limit(&c->echo_model.min_noise_floor_power, 0, 2000000.f);
res = res && Limit(&c->echo_model.stationary_gate_slope, 0, 1000000.f);
res = res && Limit(&c->echo_model.noise_gate_power, 0, 1000000.f);
res = res && Limit(&c->echo_model.noise_gate_slope, 0, 1000000.f);
res = res && Limit(&c->echo_model.render_pre_window_size, 0, 100);
res = res && Limit(&c->echo_model.render_post_window_size, 0, 100);
res = res && Limit(&c->echo_model.render_pre_window_size_init, 0, 100);
res = res && Limit(&c->echo_model.render_post_window_size_init, 0, 100);
res = res && Limit(&c->echo_model.nonlinear_hold, 0, 100);
res = res && Limit(&c->echo_model.nonlinear_release, 0, 1.f);
res = res &&
Limit(&c->suppressor.normal_tuning.mask_lf.enr_transparent, 0.f, 100.f);
res = res &&
Limit(&c->suppressor.normal_tuning.mask_lf.enr_suppress, 0.f, 100.f);
res = res &&
Limit(&c->suppressor.normal_tuning.mask_lf.emr_transparent, 0.f, 100.f);
res = res &&
Limit(&c->suppressor.normal_tuning.mask_hf.enr_transparent, 0.f, 100.f);
res = res &&
Limit(&c->suppressor.normal_tuning.mask_hf.enr_suppress, 0.f, 100.f);
res = res &&
Limit(&c->suppressor.normal_tuning.mask_hf.emr_transparent, 0.f, 100.f);
res = res && Limit(&c->suppressor.normal_tuning.max_inc_factor, 0.f, 100.f);
res =
res && Limit(&c->suppressor.normal_tuning.max_dec_factor_lf, 0.f, 100.f);
res = res && Limit(&c->suppressor.nearend_tuning.mask_lf.enr_transparent, 0.f,
100.f);
res = res &&
Limit(&c->suppressor.nearend_tuning.mask_lf.enr_suppress, 0.f, 100.f);
res = res && Limit(&c->suppressor.nearend_tuning.mask_lf.emr_transparent, 0.f,
100.f);
res = res && Limit(&c->suppressor.nearend_tuning.mask_hf.enr_transparent, 0.f,
100.f);
res = res &&
Limit(&c->suppressor.nearend_tuning.mask_hf.enr_suppress, 0.f, 100.f);
res = res && Limit(&c->suppressor.nearend_tuning.mask_hf.emr_transparent, 0.f,
100.f);
res = res && Limit(&c->suppressor.nearend_tuning.max_inc_factor, 0.f, 100.f);
res =
res && Limit(&c->suppressor.nearend_tuning.max_dec_factor_lf, 0.f, 100.f);
res = res && Limit(&c->suppressor.dominant_nearend_detection.enr_threshold,
0.f, 1000000.f);
res = res && Limit(&c->suppressor.dominant_nearend_detection.snr_threshold,
0.f, 1000000.f);
res = res && Limit(&c->suppressor.dominant_nearend_detection.hold_duration, 0,
10000);
res =
res && Limit(&c->suppressor.dominant_nearend_detection.trigger_threshold,
0, 10000);
res = res && Limit(&c->suppressor.high_bands_suppression.enr_threshold, 0.f,
1000000.f);
res = res && Limit(&c->suppressor.high_bands_suppression.max_gain_during_echo,
0.f, 1.f);
res = res && Limit(&c->suppressor.floor_first_increase, 0.f, 1000000.f);
return res;
}
} // namespace webrtc

View File

@ -17,6 +17,10 @@ namespace webrtc {
// Configuration struct for EchoCanceller3
struct EchoCanceller3Config {
// Checks and updates the parameters in a config to lie within reasonable
// ranges. Returns true if and only of the config did not need to be changed.
static bool Validate(EchoCanceller3Config* config);
EchoCanceller3Config();
EchoCanceller3Config(const EchoCanceller3Config& e);
struct Delay {

View File

@ -0,0 +1,579 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "api/audio/echo_canceller3_config_json.h"
#include <string>
#include <vector>
#include "rtc_base/logging.h"
#include "rtc_base/strings/json.h"
#include "rtc_base/strings/string_builder.h"
namespace webrtc {
namespace {
void ReadParam(const Json::Value& root, std::string param_name, bool* param) {
RTC_DCHECK(param);
bool v;
if (rtc::GetBoolFromJsonObject(root, param_name, &v)) {
*param = v;
}
}
void ReadParam(const Json::Value& root, std::string param_name, size_t* param) {
RTC_DCHECK(param);
int v;
if (rtc::GetIntFromJsonObject(root, param_name, &v)) {
*param = v;
}
}
void ReadParam(const Json::Value& root, std::string param_name, int* param) {
RTC_DCHECK(param);
int v;
if (rtc::GetIntFromJsonObject(root, param_name, &v)) {
*param = v;
}
}
void ReadParam(const Json::Value& root, std::string param_name, float* param) {
RTC_DCHECK(param);
double v;
if (rtc::GetDoubleFromJsonObject(root, param_name, &v)) {
*param = static_cast<float>(v);
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
EchoCanceller3Config::Filter::MainConfiguration* param) {
RTC_CHECK(param);
Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 6) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
RTC_CHECK(false);
}
param->length_blocks = static_cast<size_t>(v[0]);
param->leakage_converged = static_cast<float>(v[1]);
param->leakage_diverged = static_cast<float>(v[2]);
param->error_floor = static_cast<float>(v[3]);
param->error_ceil = static_cast<float>(v[4]);
param->noise_gate = static_cast<float>(v[5]);
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
EchoCanceller3Config::Filter::ShadowConfiguration* param) {
RTC_CHECK(param);
Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 3) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
RTC_CHECK(false);
}
param->length_blocks = static_cast<size_t>(v[0]);
param->rate = static_cast<float>(v[1]);
param->noise_gate = static_cast<float>(v[2]);
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
EchoCanceller3Config::Suppressor::MaskingThresholds* param) {
RTC_CHECK(param);
Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 3) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
RTC_CHECK(false);
}
param->enr_transparent = static_cast<float>(v[0]);
param->enr_suppress = static_cast<float>(v[1]);
param->emr_transparent = static_cast<float>(v[2]);
}
}
} // namespace
EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) {
EchoCanceller3Config cfg;
Json::Value root;
bool success = Json::Reader().parse(std::string(json_string), root);
if (!success) {
RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << json_string;
return EchoCanceller3Config();
}
Json::Value aec3_root;
success = rtc::GetValueFromJsonObject(root, "aec3", &aec3_root);
if (!success) {
RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string;
return EchoCanceller3Config();
}
Json::Value section;
if (rtc::GetValueFromJsonObject(aec3_root, "delay", &section)) {
ReadParam(section, "default_delay", &cfg.delay.default_delay);
ReadParam(section, "down_sampling_factor", &cfg.delay.down_sampling_factor);
ReadParam(section, "num_filters", &cfg.delay.num_filters);
ReadParam(section, "api_call_jitter_blocks",
&cfg.delay.api_call_jitter_blocks);
ReadParam(section, "min_echo_path_delay_blocks",
&cfg.delay.min_echo_path_delay_blocks);
ReadParam(section, "delay_headroom_blocks",
&cfg.delay.delay_headroom_blocks);
ReadParam(section, "hysteresis_limit_1_blocks",
&cfg.delay.hysteresis_limit_1_blocks);
ReadParam(section, "hysteresis_limit_2_blocks",
&cfg.delay.hysteresis_limit_2_blocks);
ReadParam(section, "skew_hysteresis_blocks",
&cfg.delay.skew_hysteresis_blocks);
ReadParam(section, "fixed_capture_delay_samples",
&cfg.delay.fixed_capture_delay_samples);
ReadParam(section, "delay_estimate_smoothing",
&cfg.delay.delay_estimate_smoothing);
ReadParam(section, "delay_candidate_detection_threshold",
&cfg.delay.delay_candidate_detection_threshold);
Json::Value subsection;
if (rtc::GetValueFromJsonObject(section, "delay_selection_thresholds",
&subsection)) {
ReadParam(subsection, "initial",
&cfg.delay.delay_selection_thresholds.initial);
ReadParam(subsection, "converged",
&cfg.delay.delay_selection_thresholds.converged);
}
}
if (rtc::GetValueFromJsonObject(aec3_root, "filter", &section)) {
ReadParam(section, "main", &cfg.filter.main);
ReadParam(section, "shadow", &cfg.filter.shadow);
ReadParam(section, "main_initial", &cfg.filter.main_initial);
ReadParam(section, "shadow_initial", &cfg.filter.shadow_initial);
ReadParam(section, "config_change_duration_blocks",
&cfg.filter.config_change_duration_blocks);
ReadParam(section, "initial_state_seconds",
&cfg.filter.initial_state_seconds);
ReadParam(section, "conservative_initial_phase",
&cfg.filter.conservative_initial_phase);
ReadParam(section, "enable_shadow_filter_output_usage",
&cfg.filter.enable_shadow_filter_output_usage);
}
if (rtc::GetValueFromJsonObject(aec3_root, "erle", &section)) {
ReadParam(section, "min", &cfg.erle.min);
ReadParam(section, "max_l", &cfg.erle.max_l);
ReadParam(section, "max_h", &cfg.erle.max_h);
ReadParam(section, "onset_detection", &cfg.erle.onset_detection);
}
if (rtc::GetValueFromJsonObject(aec3_root, "ep_strength", &section)) {
ReadParam(section, "lf", &cfg.ep_strength.lf);
ReadParam(section, "mf", &cfg.ep_strength.mf);
ReadParam(section, "hf", &cfg.ep_strength.hf);
ReadParam(section, "default_len", &cfg.ep_strength.default_len);
ReadParam(section, "reverb_based_on_render",
&cfg.ep_strength.reverb_based_on_render);
ReadParam(section, "echo_can_saturate", &cfg.ep_strength.echo_can_saturate);
ReadParam(section, "bounded_erl", &cfg.ep_strength.bounded_erl);
}
if (rtc::GetValueFromJsonObject(aec3_root, "gain_mask", &section)) {
ReadParam(section, "m1", &cfg.gain_mask.m1);
ReadParam(section, "m2", &cfg.gain_mask.m2);
ReadParam(section, "m3", &cfg.gain_mask.m3);
ReadParam(section, "m5", &cfg.gain_mask.m5);
ReadParam(section, "m6", &cfg.gain_mask.m6);
ReadParam(section, "m7", &cfg.gain_mask.m7);
ReadParam(section, "m8", &cfg.gain_mask.m8);
ReadParam(section, "m9", &cfg.gain_mask.m9);
ReadParam(section, "gain_curve_offset", &cfg.gain_mask.gain_curve_offset);
ReadParam(section, "gain_curve_slope", &cfg.gain_mask.gain_curve_slope);
ReadParam(section, "temporal_masking_lf",
&cfg.gain_mask.temporal_masking_lf);
ReadParam(section, "temporal_masking_hf",
&cfg.gain_mask.temporal_masking_hf);
ReadParam(section, "temporal_masking_lf_bands",
&cfg.gain_mask.temporal_masking_lf_bands);
}
if (rtc::GetValueFromJsonObject(aec3_root, "echo_audibility", &section)) {
ReadParam(section, "low_render_limit",
&cfg.echo_audibility.low_render_limit);
ReadParam(section, "normal_render_limit",
&cfg.echo_audibility.normal_render_limit);
ReadParam(section, "floor_power", &cfg.echo_audibility.floor_power);
ReadParam(section, "audibility_threshold_lf",
&cfg.echo_audibility.audibility_threshold_lf);
ReadParam(section, "audibility_threshold_mf",
&cfg.echo_audibility.audibility_threshold_mf);
ReadParam(section, "audibility_threshold_hf",
&cfg.echo_audibility.audibility_threshold_hf);
ReadParam(section, "use_stationary_properties",
&cfg.echo_audibility.use_stationary_properties);
ReadParam(section, "use_stationary_properties_at_init",
&cfg.echo_audibility.use_stationarity_properties_at_init);
}
if (rtc::GetValueFromJsonObject(aec3_root, "echo_removal_control",
&section)) {
Json::Value subsection;
if (rtc::GetValueFromJsonObject(section, "gain_rampup", &subsection)) {
ReadParam(subsection, "initial_gain",
&cfg.echo_removal_control.gain_rampup.initial_gain);
ReadParam(subsection, "first_non_zero_gain",
&cfg.echo_removal_control.gain_rampup.first_non_zero_gain);
ReadParam(subsection, "non_zero_gain_blocks",
&cfg.echo_removal_control.gain_rampup.non_zero_gain_blocks);
ReadParam(subsection, "full_gain_blocks",
&cfg.echo_removal_control.gain_rampup.full_gain_blocks);
}
ReadParam(section, "has_clock_drift",
&cfg.echo_removal_control.has_clock_drift);
ReadParam(section, "linear_and_stable_echo_path",
&cfg.echo_removal_control.linear_and_stable_echo_path);
}
if (rtc::GetValueFromJsonObject(aec3_root, "echo_model", &section)) {
Json::Value subsection;
ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold);
ReadParam(section, "min_noise_floor_power",
&cfg.echo_model.min_noise_floor_power);
ReadParam(section, "stationary_gate_slope",
&cfg.echo_model.stationary_gate_slope);
ReadParam(section, "noise_gate_power", &cfg.echo_model.noise_gate_power);
ReadParam(section, "noise_gate_slope", &cfg.echo_model.noise_gate_slope);
ReadParam(section, "render_pre_window_size",
&cfg.echo_model.render_pre_window_size);
ReadParam(section, "render_post_window_size",
&cfg.echo_model.render_post_window_size);
ReadParam(section, "render_pre_window_size_init",
&cfg.echo_model.render_pre_window_size_init);
ReadParam(section, "render_post_window_size_init",
&cfg.echo_model.render_post_window_size_init);
ReadParam(section, "nonlinear_hold", &cfg.echo_model.nonlinear_hold);
ReadParam(section, "nonlinear_release", &cfg.echo_model.nonlinear_release);
}
Json::Value subsection;
if (rtc::GetValueFromJsonObject(aec3_root, "suppressor", &section)) {
ReadParam(section, "nearend_average_blocks",
&cfg.suppressor.nearend_average_blocks);
if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) {
ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf);
ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf);
ReadParam(subsection, "max_inc_factor",
&cfg.suppressor.normal_tuning.max_inc_factor);
ReadParam(subsection, "max_dec_factor_lf",
&cfg.suppressor.normal_tuning.max_dec_factor_lf);
}
if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) {
ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf);
ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf);
ReadParam(subsection, "max_inc_factor",
&cfg.suppressor.nearend_tuning.max_inc_factor);
ReadParam(subsection, "max_dec_factor_lf",
&cfg.suppressor.nearend_tuning.max_dec_factor_lf);
}
if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection",
&subsection)) {
ReadParam(subsection, "enr_threshold",
&cfg.suppressor.dominant_nearend_detection.enr_threshold);
ReadParam(subsection, "snr_threshold",
&cfg.suppressor.dominant_nearend_detection.snr_threshold);
ReadParam(subsection, "hold_duration",
&cfg.suppressor.dominant_nearend_detection.hold_duration);
ReadParam(subsection, "trigger_threshold",
&cfg.suppressor.dominant_nearend_detection.trigger_threshold);
}
if (rtc::GetValueFromJsonObject(section, "high_bands_suppression",
&subsection)) {
ReadParam(subsection, "enr_threshold",
&cfg.suppressor.high_bands_suppression.enr_threshold);
ReadParam(subsection, "max_gain_during_echo",
&cfg.suppressor.high_bands_suppression.max_gain_during_echo);
}
ReadParam(section, "floor_first_increase",
&cfg.suppressor.floor_first_increase);
ReadParam(section, "enforce_transparent",
&cfg.suppressor.enforce_transparent);
ReadParam(section, "enforce_empty_higher_bands",
&cfg.suppressor.enforce_empty_higher_bands);
}
return cfg;
}
std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) {
rtc::StringBuilder ost;
ost << "{";
ost << "\"aec3\": {";
ost << "\"delay\": {";
ost << "\"default_delay\": " << config.delay.default_delay << ",";
ost << "\"down_sampling_factor\": " << config.delay.down_sampling_factor
<< ",";
ost << "\"num_filters\": " << config.delay.num_filters << ",";
ost << "\"api_call_jitter_blocks\": " << config.delay.api_call_jitter_blocks
<< ",";
ost << "\"min_echo_path_delay_blocks\": "
<< config.delay.min_echo_path_delay_blocks << ",";
ost << "\"delay_headroom_blocks\": " << config.delay.delay_headroom_blocks
<< ",";
ost << "\"hysteresis_limit_1_blocks\": "
<< config.delay.hysteresis_limit_1_blocks << ",";
ost << "\"hysteresis_limit_2_blocks\": "
<< config.delay.hysteresis_limit_2_blocks << ",";
ost << "\"skew_hysteresis_blocks\": " << config.delay.skew_hysteresis_blocks
<< ",";
ost << "\"fixed_capture_delay_samples\": "
<< config.delay.fixed_capture_delay_samples << ",";
ost << "\"delay_estimate_smoothing\": "
<< config.delay.delay_estimate_smoothing << ",";
ost << "\"delay_candidate_detection_threshold\": "
<< config.delay.delay_candidate_detection_threshold << ",";
ost << "\"delay_selection_thresholds\": {";
ost << "\"initial\": " << config.delay.delay_selection_thresholds.initial
<< ",";
ost << "\"converged\": " << config.delay.delay_selection_thresholds.converged;
ost << "}";
ost << "},";
ost << "\"filter\": {";
ost << "\"main\": [";
ost << config.filter.main.length_blocks << ",";
ost << config.filter.main.leakage_converged << ",";
ost << config.filter.main.leakage_diverged << ",";
ost << config.filter.main.error_floor << ",";
ost << config.filter.main.error_ceil << ",";
ost << config.filter.main.noise_gate;
ost << "],";
ost << "\"shadow\": [";
ost << config.filter.shadow.length_blocks << ",";
ost << config.filter.shadow.rate << ",";
ost << config.filter.shadow.noise_gate;
ost << "],";
ost << "\"main_initial\": [";
ost << config.filter.main_initial.length_blocks << ",";
ost << config.filter.main_initial.leakage_converged << ",";
ost << config.filter.main_initial.leakage_diverged << ",";
ost << config.filter.main_initial.error_floor << ",";
ost << config.filter.main_initial.error_ceil << ",";
ost << config.filter.main_initial.noise_gate;
ost << "],";
ost << "\"shadow_initial\": [";
ost << config.filter.shadow_initial.length_blocks << ",";
ost << config.filter.shadow_initial.rate << ",";
ost << config.filter.shadow_initial.noise_gate;
ost << "],";
ost << "\"config_change_duration_blocks\": "
<< config.filter.config_change_duration_blocks << ",";
ost << "\"initial_state_seconds\": " << config.filter.initial_state_seconds
<< ",";
ost << "\"conservative_initial_phase\": "
<< (config.filter.conservative_initial_phase ? "true" : "false") << ",";
ost << "\"enable_shadow_filter_output_usage\": "
<< (config.filter.enable_shadow_filter_output_usage ? "true" : "false");
ost << "},";
ost << "\"erle\": {";
ost << "\"min\": " << config.erle.min << ",";
ost << "\"max_l\": " << config.erle.max_l << ",";
ost << "\"max_h\": " << config.erle.max_h << ",";
ost << "\"onset_detection\": "
<< (config.erle.onset_detection ? "true" : "false");
ost << "},";
ost << "\"ep_strength\": {";
ost << "\"lf\": " << config.ep_strength.lf << ",";
ost << "\"mf\": " << config.ep_strength.mf << ",";
ost << "\"hf\": " << config.ep_strength.hf << ",";
ost << "\"default_len\": " << config.ep_strength.default_len << ",";
ost << "\"reverb_based_on_render\": "
<< (config.ep_strength.reverb_based_on_render ? "true" : "false") << ",";
ost << "\"echo_can_saturate\": "
<< (config.ep_strength.echo_can_saturate ? "true" : "false") << ",";
ost << "\"bounded_erl\": "
<< (config.ep_strength.bounded_erl ? "true" : "false");
ost << "},";
ost << "\"gain_mask\": {";
ost << "\"m0\": " << config.gain_mask.m0 << ",";
ost << "\"m1\": " << config.gain_mask.m1 << ",";
ost << "\"m2\": " << config.gain_mask.m2 << ",";
ost << "\"m3\": " << config.gain_mask.m3 << ",";
ost << "\"m5\": " << config.gain_mask.m5 << ",";
ost << "\"m6\": " << config.gain_mask.m6 << ",";
ost << "\"m7\": " << config.gain_mask.m7 << ",";
ost << "\"m8\": " << config.gain_mask.m8 << ",";
ost << "\"m9\": " << config.gain_mask.m9 << ",";
ost << "\"gain_curve_offset\": " << config.gain_mask.gain_curve_offset << ",";
ost << "\"gain_curve_slope\": " << config.gain_mask.gain_curve_slope << ",";
ost << "\"temporal_masking_lf\": " << config.gain_mask.temporal_masking_lf
<< ",";
ost << "\"temporal_masking_hf\": " << config.gain_mask.temporal_masking_hf
<< ",";
ost << "\"temporal_masking_lf_bands\": "
<< config.gain_mask.temporal_masking_lf_bands;
ost << "},";
ost << "\"echo_audibility\": {";
ost << "\"low_render_limit\": " << config.echo_audibility.low_render_limit
<< ",";
ost << "\"normal_render_limit\": "
<< config.echo_audibility.normal_render_limit << ",";
ost << "\"floor_power\": " << config.echo_audibility.floor_power << ",";
ost << "\"audibility_threshold_lf\": "
<< config.echo_audibility.audibility_threshold_lf << ",";
ost << "\"audibility_threshold_mf\": "
<< config.echo_audibility.audibility_threshold_mf << ",";
ost << "\"audibility_threshold_hf\": "
<< config.echo_audibility.audibility_threshold_hf << ",";
ost << "\"use_stationary_properties\": "
<< (config.echo_audibility.use_stationary_properties ? "true" : "false")
<< ",";
ost << "\"use_stationarity_properties_at_init\": "
<< (config.echo_audibility.use_stationarity_properties_at_init ? "true"
: "false");
ost << "},";
ost << "\"render_levels\": {";
ost << "\"active_render_limit\": " << config.render_levels.active_render_limit
<< ",";
ost << "\"poor_excitation_render_limit\": "
<< config.render_levels.poor_excitation_render_limit << ",";
ost << "\"poor_excitation_render_limit_ds8\": "
<< config.render_levels.poor_excitation_render_limit_ds8;
ost << "},";
ost << "\"echo_removal_control\": {";
ost << "\"gain_rampup\": {";
ost << "\"initial_gain\": "
<< config.echo_removal_control.gain_rampup.initial_gain << ",";
ost << "\"first_non_zero_gain\": "
<< config.echo_removal_control.gain_rampup.first_non_zero_gain << ",";
ost << "\"non_zero_gain_blocks\": "
<< config.echo_removal_control.gain_rampup.non_zero_gain_blocks << ",";
ost << "\"full_gain_blocks\": "
<< config.echo_removal_control.gain_rampup.full_gain_blocks;
ost << "},";
ost << "\"has_clock_drift\": "
<< (config.echo_removal_control.has_clock_drift ? "true" : "false")
<< ",";
ost << "\"linear_and_stable_echo_path\": "
<< (config.echo_removal_control.linear_and_stable_echo_path ? "true"
: "false");
ost << "},";
ost << "\"echo_model\": {";
ost << "\"noise_floor_hold\": " << config.echo_model.noise_floor_hold << ",";
ost << "\"min_noise_floor_power\": "
<< config.echo_model.min_noise_floor_power << ",";
ost << "\"stationary_gate_slope\": "
<< config.echo_model.stationary_gate_slope << ",";
ost << "\"noise_gate_power\": " << config.echo_model.noise_gate_power << ",";
ost << "\"noise_gate_slope\": " << config.echo_model.noise_gate_slope << ",";
ost << "\"render_pre_window_size\": "
<< config.echo_model.render_pre_window_size << ",";
ost << "\"render_post_window_size\": "
<< config.echo_model.render_post_window_size << ",";
ost << "\"render_pre_window_size_init\": "
<< config.echo_model.render_pre_window_size_init << ",";
ost << "\"render_post_window_size_init\": "
<< config.echo_model.render_post_window_size_init << ",";
ost << "\"nonlinear_hold\": " << config.echo_model.nonlinear_hold << ",";
ost << "\"nonlinear_release\": " << config.echo_model.nonlinear_release;
ost << "},";
ost << "\"suppressor\": {";
ost << "\"nearend_average_blocks\": "
<< config.suppressor.nearend_average_blocks << ",";
ost << "\"normal_tuning\": {";
ost << "\"mask_lf\": [";
ost << config.suppressor.normal_tuning.mask_lf.enr_transparent << ",";
ost << config.suppressor.normal_tuning.mask_lf.enr_suppress << ",";
ost << config.suppressor.normal_tuning.mask_lf.emr_transparent;
ost << "],";
ost << "\"mask_hf\": [";
ost << config.suppressor.normal_tuning.mask_hf.enr_transparent << ",";
ost << config.suppressor.normal_tuning.mask_hf.enr_suppress << ",";
ost << config.suppressor.normal_tuning.mask_hf.emr_transparent;
ost << "],";
ost << "\"max_inc_factor\": "
<< config.suppressor.normal_tuning.max_inc_factor << ",";
ost << "\"max_dec_factor_lf\": "
<< config.suppressor.normal_tuning.max_dec_factor_lf;
ost << "},";
ost << "\"nearend_tuning\": {";
ost << "\"mask_lf\": [";
ost << config.suppressor.nearend_tuning.mask_lf.enr_transparent << ",";
ost << config.suppressor.nearend_tuning.mask_lf.enr_suppress << ",";
ost << config.suppressor.nearend_tuning.mask_lf.emr_transparent;
ost << "],";
ost << "\"mask_hf\": [";
ost << config.suppressor.nearend_tuning.mask_hf.enr_transparent << ",";
ost << config.suppressor.nearend_tuning.mask_hf.enr_suppress << ",";
ost << config.suppressor.nearend_tuning.mask_hf.emr_transparent;
ost << "],";
ost << "\"max_inc_factor\": "
<< config.suppressor.nearend_tuning.max_inc_factor << ",";
ost << "\"max_dec_factor_lf\": "
<< config.suppressor.nearend_tuning.max_dec_factor_lf;
ost << "},";
ost << "\"dominant_nearend_detection\": {";
ost << "\"enr_threshold\": "
<< config.suppressor.dominant_nearend_detection.enr_threshold << ",";
ost << "\"snr_threshold\": "
<< config.suppressor.dominant_nearend_detection.snr_threshold << ",";
ost << "\"hold_duration\": "
<< config.suppressor.dominant_nearend_detection.hold_duration << ",";
ost << "\"trigger_threshold\": "
<< config.suppressor.dominant_nearend_detection.trigger_threshold;
ost << "},";
ost << "\"high_bands_suppression\": {";
ost << "\"enr_threshold\": "
<< config.suppressor.high_bands_suppression.enr_threshold << ",";
ost << "\"max_gain_during_echo\": "
<< config.suppressor.high_bands_suppression.max_gain_during_echo;
ost << "},";
ost << "\"floor_first_increase\": " << config.suppressor.floor_first_increase
<< ",";
ost << "\"enforce_transparent\": "
<< (config.suppressor.enforce_transparent ? "true" : "false") << ",";
ost << "\"enforce_empty_higher_bands\": "
<< (config.suppressor.enforce_empty_higher_bands ? "true" : "false");
ost << "}";
ost << "}";
ost << "}";
return ost.Release();
}
} // namespace webrtc

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef API_AUDIO_ECHO_CANCELLER3_CONFIG_JSON_H_
#define API_AUDIO_ECHO_CANCELLER3_CONFIG_JSON_H_
#include <string>
#include "absl/strings/string_view.h"
#include "api/audio/echo_canceller3_config.h"
namespace webrtc {
// Parses a JSON-encoded string into an Aec3 config. Fields corresponds to
// substruct names, with the addition that there must be a top-level node
// "aec3". Returns default config values for anything that cannot be parsed from
// the string.
EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string);
// Encodes an Aec3 config in JSON format. Fields corresponds to substruct names,
// with the addition that the top-level node is named "aec3".
std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config);
} // namespace webrtc
#endif // API_AUDIO_ECHO_CANCELLER3_CONFIG_JSON_H_

View File

@ -17,8 +17,12 @@ if (rtc_include_tests) {
testonly = true
sources = [
"audio_frame_unittest.cc",
"echo_canceller3_config_json_unittest.cc",
"echo_canceller3_config_unittest.cc",
]
deps = [
"..:aec3_config",
"..:aec3_config_json",
"..:audio_frame_api",
"../../../rtc_base:rtc_base_approved",
"../../../test:test_support",

View File

@ -0,0 +1,41 @@
/*
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "api/audio/echo_canceller3_config_json.h"
#include "api/audio/echo_canceller3_config.h"
#include "test/gtest.h"
namespace webrtc {
TEST(EchoCanceller3JsonHelpers, ToStringAndParseJson) {
EchoCanceller3Config cfg;
cfg.delay.down_sampling_factor = 1u;
cfg.filter.shadow_initial.length_blocks = 7u;
cfg.suppressor.normal_tuning.mask_hf.enr_suppress = .5f;
std::string json_string = Aec3ConfigToJsonString(cfg);
EchoCanceller3Config cfg_transformed = Aec3ConfigFromJsonString(json_string);
// Expect unchanged values to remain default.
EXPECT_EQ(cfg.filter.main.error_floor,
cfg_transformed.filter.main.error_floor);
EXPECT_EQ(cfg.ep_strength.default_len,
cfg_transformed.ep_strength.default_len);
EXPECT_EQ(cfg.suppressor.normal_tuning.mask_lf.enr_suppress,
cfg_transformed.suppressor.normal_tuning.mask_lf.enr_suppress);
// Expect changed values to carry through the transformation.
EXPECT_EQ(cfg.delay.down_sampling_factor,
cfg_transformed.delay.down_sampling_factor);
EXPECT_EQ(cfg.filter.shadow_initial.length_blocks,
cfg_transformed.filter.shadow_initial.length_blocks);
EXPECT_EQ(cfg.suppressor.normal_tuning.mask_hf.enr_suppress,
cfg_transformed.suppressor.normal_tuning.mask_hf.enr_suppress);
}
} // namespace webrtc

View File

@ -0,0 +1,47 @@
/*
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <string>
#include "api/audio/echo_canceller3_config.h"
#include "api/audio/echo_canceller3_config_json.h"
#include "test/gtest.h"
namespace webrtc {
TEST(EchoCanceller3Config, ValidConfigIsNotModified) {
EchoCanceller3Config config;
EXPECT_TRUE(EchoCanceller3Config::Validate(&config));
EchoCanceller3Config default_config;
EXPECT_EQ(Aec3ConfigToJsonString(config),
Aec3ConfigToJsonString(default_config));
}
TEST(EchoCanceller3Config, InvalidConfigIsCorrected) {
// Change a parameter and validate.
EchoCanceller3Config config;
config.echo_model.min_noise_floor_power = -1600000.f;
EXPECT_FALSE(EchoCanceller3Config::Validate(&config));
EXPECT_GE(config.echo_model.min_noise_floor_power, 0.f);
// Verify remaining parameters are unchanged.
EchoCanceller3Config default_config;
config.echo_model.min_noise_floor_power =
default_config.echo_model.min_noise_floor_power;
EXPECT_EQ(Aec3ConfigToJsonString(config),
Aec3ConfigToJsonString(default_config));
}
TEST(EchoCanceller3Config, ValidatedConfigsAreValid) {
EchoCanceller3Config config;
config.delay.down_sampling_factor = 983;
EXPECT_FALSE(EchoCanceller3Config::Validate(&config));
EXPECT_TRUE(EchoCanceller3Config::Validate(&config));
}
} // namespace webrtc

View File

@ -530,6 +530,7 @@ if (rtc_include_tests) {
":audioproc_protobuf_utils",
":audioproc_test_utils",
":runtime_settings_protobuf_utils",
"../../api/audio:aec3_config_json",
"../../api/audio:aec3_factory",
"../../common_audio:common_audio",
"../../rtc_base:checks",

View File

@ -18,6 +18,7 @@
#include <vector>
#include "absl/memory/memory.h"
#include "api/audio/echo_canceller3_config_json.h"
#include "api/audio/echo_canceller3_factory.h"
#include "common_audio/include/audio_util.h"
#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
@ -34,606 +35,21 @@
namespace webrtc {
namespace test {
namespace {
// Prints out the currently used AEC3 parameter values in JSON format.
void PrintAec3ParameterValues(const EchoCanceller3Config& cfg) {
std::cout << "{";
std::cout << "\"delay\": {";
std::cout << "\"default_delay\": " << cfg.delay.default_delay << ",";
std::cout << "\"down_sampling_factor\": " << cfg.delay.down_sampling_factor
<< ",";
std::cout << "\"num_filters\": " << cfg.delay.num_filters << ",";
std::cout << "\"api_call_jitter_blocks\": "
<< cfg.delay.api_call_jitter_blocks << ",";
std::cout << "\"min_echo_path_delay_blocks\": "
<< cfg.delay.min_echo_path_delay_blocks << ",";
std::cout << "\"delay_headroom_blocks\": " << cfg.delay.delay_headroom_blocks
<< ",";
std::cout << "\"hysteresis_limit_1_blocks\": "
<< cfg.delay.hysteresis_limit_1_blocks << ",";
std::cout << "\"hysteresis_limit_2_blocks\": "
<< cfg.delay.hysteresis_limit_2_blocks << ",";
std::cout << "\"skew_hysteresis_blocks\": "
<< cfg.delay.skew_hysteresis_blocks << ",";
std::cout << "\"fixed_capture_delay_samples\": "
<< cfg.delay.fixed_capture_delay_samples << ",";
std::cout << "\"delay_estimate_smoothing\": "
<< cfg.delay.delay_estimate_smoothing << ",";
std::cout << "\"delay_candidate_detection_threshold\": "
<< cfg.delay.delay_candidate_detection_threshold << ",";
std::cout << "\"delay_selection_thresholds\": {";
std::cout << "\"initial\": " << cfg.delay.delay_selection_thresholds.initial
<< ",";
std::cout << "\"converged\": "
<< cfg.delay.delay_selection_thresholds.converged;
std::cout << "}";
std::cout << "},";
std::cout << "\"filter\": {";
std::cout << "\"main\": [";
std::cout << cfg.filter.main.length_blocks << ",";
std::cout << cfg.filter.main.leakage_converged << ",";
std::cout << cfg.filter.main.leakage_diverged << ",";
std::cout << cfg.filter.main.error_floor << ",";
std::cout << cfg.filter.main.error_ceil << ",";
std::cout << cfg.filter.main.noise_gate;
std::cout << "],";
std::cout << "\"shadow\": [";
std::cout << cfg.filter.shadow.length_blocks << ",";
std::cout << cfg.filter.shadow.rate << ",";
std::cout << cfg.filter.shadow.noise_gate;
std::cout << "],";
std::cout << "\"main_initial\": [";
std::cout << cfg.filter.main_initial.length_blocks << ",";
std::cout << cfg.filter.main_initial.leakage_converged << ",";
std::cout << cfg.filter.main_initial.leakage_diverged << ",";
std::cout << cfg.filter.main_initial.error_floor << ",";
std::cout << cfg.filter.main_initial.error_ceil << ",";
std::cout << cfg.filter.main_initial.noise_gate;
std::cout << "],";
std::cout << "\"shadow_initial\": [";
std::cout << cfg.filter.shadow_initial.length_blocks << ",";
std::cout << cfg.filter.shadow_initial.rate << ",";
std::cout << cfg.filter.shadow_initial.noise_gate;
std::cout << "],";
std::cout << "\"config_change_duration_blocks\": "
<< cfg.filter.config_change_duration_blocks << ",";
std::cout << "\"initial_state_seconds\": " << cfg.filter.initial_state_seconds
<< ",";
std::cout << "\"conservative_initial_phase\": "
<< (cfg.filter.conservative_initial_phase ? "true" : "false")
<< ",";
std::cout << "\"enable_shadow_filter_output_usage\": "
<< (cfg.filter.enable_shadow_filter_output_usage ? "true"
: "false");
std::cout << "},";
std::cout << "\"erle\": {";
std::cout << "\"min\": " << cfg.erle.min << ",";
std::cout << "\"max_l\": " << cfg.erle.max_l << ",";
std::cout << "\"max_h\": " << cfg.erle.max_h << ",";
std::cout << "\"onset_detection\": "
<< (cfg.erle.onset_detection ? "true" : "false");
std::cout << "},";
std::cout << "\"ep_strength\": {";
std::cout << "\"lf\": " << cfg.ep_strength.lf << ",";
std::cout << "\"mf\": " << cfg.ep_strength.mf << ",";
std::cout << "\"hf\": " << cfg.ep_strength.hf << ",";
std::cout << "\"default_len\": " << cfg.ep_strength.default_len << ",";
std::cout << "\"reverb_based_on_render\": "
<< (cfg.ep_strength.reverb_based_on_render ? "true" : "false")
<< ",";
std::cout << "\"echo_can_saturate\": "
<< (cfg.ep_strength.echo_can_saturate ? "true" : "false") << ",";
std::cout << "\"bounded_erl\": "
<< (cfg.ep_strength.bounded_erl ? "true" : "false");
std::cout << "},";
std::cout << "\"gain_mask\": {";
std::cout << "\"m0\": " << cfg.gain_mask.m0 << ",";
std::cout << "\"m1\": " << cfg.gain_mask.m1 << ",";
std::cout << "\"m2\": " << cfg.gain_mask.m2 << ",";
std::cout << "\"m3\": " << cfg.gain_mask.m3 << ",";
std::cout << "\"m5\": " << cfg.gain_mask.m5 << ",";
std::cout << "\"m6\": " << cfg.gain_mask.m6 << ",";
std::cout << "\"m7\": " << cfg.gain_mask.m7 << ",";
std::cout << "\"m8\": " << cfg.gain_mask.m8 << ",";
std::cout << "\"m9\": " << cfg.gain_mask.m9 << ",";
std::cout << "\"gain_curve_offset\": " << cfg.gain_mask.gain_curve_offset
<< ",";
std::cout << "\"gain_curve_slope\": " << cfg.gain_mask.gain_curve_slope
<< ",";
std::cout << "\"temporal_masking_lf\": " << cfg.gain_mask.temporal_masking_lf
<< ",";
std::cout << "\"temporal_masking_hf\": " << cfg.gain_mask.temporal_masking_hf
<< ",";
std::cout << "\"temporal_masking_lf_bands\": "
<< cfg.gain_mask.temporal_masking_lf_bands;
std::cout << "},";
std::cout << "\"echo_audibility\": {";
std::cout << "\"low_render_limit\": " << cfg.echo_audibility.low_render_limit
<< ",";
std::cout << "\"normal_render_limit\": "
<< cfg.echo_audibility.normal_render_limit << ",";
std::cout << "\"floor_power\": " << cfg.echo_audibility.floor_power << ",";
std::cout << "\"audibility_threshold_lf\": "
<< cfg.echo_audibility.audibility_threshold_lf << ",";
std::cout << "\"audibility_threshold_mf\": "
<< cfg.echo_audibility.audibility_threshold_mf << ",";
std::cout << "\"audibility_threshold_hf\": "
<< cfg.echo_audibility.audibility_threshold_hf << ",";
std::cout << "\"use_stationary_properties\": "
<< (cfg.echo_audibility.use_stationary_properties ? "true"
: "false")
<< ",";
std::cout << "\"use_stationarity_properties_at_init\": "
<< (cfg.echo_audibility.use_stationarity_properties_at_init
? "true"
: "false");
std::cout << "},";
std::cout << "\"render_levels\": {";
std::cout << "\"active_render_limit\": "
<< cfg.render_levels.active_render_limit << ",";
std::cout << "\"poor_excitation_render_limit\": "
<< cfg.render_levels.poor_excitation_render_limit << ",";
std::cout << "\"poor_excitation_render_limit_ds8\": "
<< cfg.render_levels.poor_excitation_render_limit_ds8;
std::cout << "},";
std::cout << "\"echo_removal_control\": {";
std::cout << "\"gain_rampup\": {";
std::cout << "\"initial_gain\": "
<< cfg.echo_removal_control.gain_rampup.initial_gain << ",";
std::cout << "\"first_non_zero_gain\": "
<< cfg.echo_removal_control.gain_rampup.first_non_zero_gain << ",";
std::cout << "\"non_zero_gain_blocks\": "
<< cfg.echo_removal_control.gain_rampup.non_zero_gain_blocks << ",";
std::cout << "\"full_gain_blocks\": "
<< cfg.echo_removal_control.gain_rampup.full_gain_blocks;
std::cout << "},";
std::cout << "\"has_clock_drift\": "
<< (cfg.echo_removal_control.has_clock_drift ? "true" : "false")
<< ",";
std::cout << "\"linear_and_stable_echo_path\": "
<< (cfg.echo_removal_control.linear_and_stable_echo_path ? "true"
: "false");
std::cout << "},";
std::cout << "\"echo_model\": {";
std::cout << "\"noise_floor_hold\": " << cfg.echo_model.noise_floor_hold
<< ",";
std::cout << "\"min_noise_floor_power\": "
<< cfg.echo_model.min_noise_floor_power << ",";
std::cout << "\"stationary_gate_slope\": "
<< cfg.echo_model.stationary_gate_slope << ",";
std::cout << "\"noise_gate_power\": " << cfg.echo_model.noise_gate_power
<< ",";
std::cout << "\"noise_gate_slope\": " << cfg.echo_model.noise_gate_slope
<< ",";
std::cout << "\"render_pre_window_size\": "
<< cfg.echo_model.render_pre_window_size << ",";
std::cout << "\"render_post_window_size\": "
<< cfg.echo_model.render_post_window_size << ",";
std::cout << "\"render_pre_window_size_init\": "
<< cfg.echo_model.render_pre_window_size_init << ",";
std::cout << "\"render_post_window_size_init\": "
<< cfg.echo_model.render_post_window_size_init << ",";
std::cout << "\"nonlinear_hold\": " << cfg.echo_model.nonlinear_hold << ",";
std::cout << "\"nonlinear_release\": " << cfg.echo_model.nonlinear_release;
std::cout << "},";
std::cout << "\"suppressor\": {";
std::cout << "\"nearend_average_blocks\": "
<< cfg.suppressor.nearend_average_blocks << ",";
std::cout << "\"normal_tuning\": {";
std::cout << "\"mask_lf\": [";
std::cout << cfg.suppressor.normal_tuning.mask_lf.enr_transparent << ",";
std::cout << cfg.suppressor.normal_tuning.mask_lf.enr_suppress << ",";
std::cout << cfg.suppressor.normal_tuning.mask_lf.emr_transparent;
std::cout << "],";
std::cout << "\"mask_hf\": [";
std::cout << cfg.suppressor.normal_tuning.mask_hf.enr_transparent << ",";
std::cout << cfg.suppressor.normal_tuning.mask_hf.enr_suppress << ",";
std::cout << cfg.suppressor.normal_tuning.mask_hf.emr_transparent;
std::cout << "],";
std::cout << "\"max_inc_factor\": "
<< cfg.suppressor.normal_tuning.max_inc_factor << ",";
std::cout << "\"max_dec_factor_lf\": "
<< cfg.suppressor.normal_tuning.max_dec_factor_lf;
std::cout << "},";
std::cout << "\"nearend_tuning\": {";
std::cout << "\"mask_lf\": [";
std::cout << cfg.suppressor.nearend_tuning.mask_lf.enr_transparent << ",";
std::cout << cfg.suppressor.nearend_tuning.mask_lf.enr_suppress << ",";
std::cout << cfg.suppressor.nearend_tuning.mask_lf.emr_transparent;
std::cout << "],";
std::cout << "\"mask_hf\": [";
std::cout << cfg.suppressor.nearend_tuning.mask_hf.enr_transparent << ",";
std::cout << cfg.suppressor.nearend_tuning.mask_hf.enr_suppress << ",";
std::cout << cfg.suppressor.nearend_tuning.mask_hf.emr_transparent;
std::cout << "],";
std::cout << "\"max_inc_factor\": "
<< cfg.suppressor.nearend_tuning.max_inc_factor << ",";
std::cout << "\"max_dec_factor_lf\": "
<< cfg.suppressor.nearend_tuning.max_dec_factor_lf;
std::cout << "},";
std::cout << "\"dominant_nearend_detection\": {";
std::cout << "\"enr_threshold\": "
<< cfg.suppressor.dominant_nearend_detection.enr_threshold << ",";
std::cout << "\"snr_threshold\": "
<< cfg.suppressor.dominant_nearend_detection.snr_threshold << ",";
std::cout << "\"hold_duration\": "
<< cfg.suppressor.dominant_nearend_detection.hold_duration << ",";
std::cout << "\"trigger_threshold\": "
<< cfg.suppressor.dominant_nearend_detection.trigger_threshold;
std::cout << "},";
std::cout << "\"high_bands_suppression\": {";
std::cout << "\"enr_threshold\": "
<< cfg.suppressor.high_bands_suppression.enr_threshold << ",";
std::cout << "\"max_gain_during_echo\": "
<< cfg.suppressor.high_bands_suppression.max_gain_during_echo;
std::cout << "},";
std::cout << "\"floor_first_increase\": "
<< cfg.suppressor.floor_first_increase << ",";
std::cout << "\"enforce_transparent\": "
<< (cfg.suppressor.enforce_transparent ? "true" : "false") << ",";
std::cout << "\"enforce_empty_higher_bands\": "
<< (cfg.suppressor.enforce_empty_higher_bands ? "true" : "false");
std::cout << "}";
std::cout << "}";
std::cout << std::endl;
// Helper for reading JSON from a file and parsing it to an AEC3 configuration.
EchoCanceller3Config ReadAec3ConfigFromJsonFile(const std::string& filename) {
std::string json_string;
std::string s;
std::ifstream f(filename.c_str());
if (f.fail()) {
std::cout << "Failed to open the file " << filename << std::endl;
RTC_CHECK(false);
}
while (std::getline(f, s)) {
json_string += s;
}
return Aec3ConfigFromJsonString(json_string);
}
// Class for parsing the AEC3 parameters from a JSON file and producing a config
// struct.
class Aec3ParametersParser {
public:
static EchoCanceller3Config Parse(const std::string& filename) {
return Aec3ParametersParser().ParseFile(filename);
}
private:
Aec3ParametersParser() = default;
void ReadParam(const Json::Value& root,
std::string param_name,
bool* param) const {
RTC_CHECK(param);
bool v;
if (rtc::GetBoolFromJsonObject(root, param_name, &v)) {
*param = v;
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
size_t* param) const {
RTC_CHECK(param);
int v;
if (rtc::GetIntFromJsonObject(root, param_name, &v)) {
*param = v;
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
int* param) const {
RTC_CHECK(param);
int v;
if (rtc::GetIntFromJsonObject(root, param_name, &v)) {
*param = v;
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
float* param) const {
RTC_CHECK(param);
double v;
if (rtc::GetDoubleFromJsonObject(root, param_name, &v)) {
*param = static_cast<float>(v);
}
}
void ReadParam(const Json::Value& root,
std::string param_name,
EchoCanceller3Config::Filter::MainConfiguration* param) const {
RTC_CHECK(param);
Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 6) {
std::cout << "Incorrect array size for " << param_name << std::endl;
RTC_CHECK(false);
}
param->length_blocks = static_cast<size_t>(v[0]);
param->leakage_converged = static_cast<float>(v[1]);
param->leakage_diverged = static_cast<float>(v[2]);
param->error_floor = static_cast<float>(v[3]);
param->error_ceil = static_cast<float>(v[4]);
param->noise_gate = static_cast<float>(v[5]);
}
}
void ReadParam(
const Json::Value& root,
std::string param_name,
EchoCanceller3Config::Filter::ShadowConfiguration* param) const {
RTC_CHECK(param);
Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 3) {
std::cout << "Incorrect array size for " << param_name << std::endl;
RTC_CHECK(false);
}
param->length_blocks = static_cast<size_t>(v[0]);
param->rate = static_cast<float>(v[1]);
param->noise_gate = static_cast<float>(v[2]);
}
}
void ReadParam(
const Json::Value& root,
std::string param_name,
EchoCanceller3Config::Suppressor::MaskingThresholds* param) const {
RTC_CHECK(param);
Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 3) {
std::cout << "Incorrect array size for " << param_name << std::endl;
RTC_CHECK(false);
}
param->enr_transparent = static_cast<float>(v[0]);
param->enr_suppress = static_cast<float>(v[1]);
param->emr_transparent = static_cast<float>(v[2]);
}
}
EchoCanceller3Config ParseFile(const std::string& filename) const {
EchoCanceller3Config cfg;
Json::Value root;
std::string s;
std::string json_string;
std::ifstream f(filename.c_str());
if (f.fail()) {
std::cout << "Failed to open the file " << filename << std::endl;
RTC_CHECK(false);
}
while (std::getline(f, s)) {
json_string += s;
}
bool success = Json::Reader().parse(json_string, root);
if (!success) {
std::cout << "Incorrect JSON format:" << std::endl;
std::cout << json_string << std::endl;
RTC_CHECK(false);
}
Json::Value section;
if (rtc::GetValueFromJsonObject(root, "delay", &section)) {
ReadParam(section, "default_delay", &cfg.delay.default_delay);
ReadParam(section, "down_sampling_factor",
&cfg.delay.down_sampling_factor);
ReadParam(section, "num_filters", &cfg.delay.num_filters);
ReadParam(section, "api_call_jitter_blocks",
&cfg.delay.api_call_jitter_blocks);
ReadParam(section, "min_echo_path_delay_blocks",
&cfg.delay.min_echo_path_delay_blocks);
ReadParam(section, "delay_headroom_blocks",
&cfg.delay.delay_headroom_blocks);
ReadParam(section, "hysteresis_limit_1_blocks",
&cfg.delay.hysteresis_limit_1_blocks);
ReadParam(section, "hysteresis_limit_2_blocks",
&cfg.delay.hysteresis_limit_2_blocks);
ReadParam(section, "skew_hysteresis_blocks",
&cfg.delay.skew_hysteresis_blocks);
ReadParam(section, "fixed_capture_delay_samples",
&cfg.delay.fixed_capture_delay_samples);
ReadParam(section, "delay_estimate_smoothing",
&cfg.delay.delay_estimate_smoothing);
ReadParam(section, "delay_candidate_detection_threshold",
&cfg.delay.delay_candidate_detection_threshold);
Json::Value subsection;
if (rtc::GetValueFromJsonObject(section, "delay_selection_thresholds",
&subsection)) {
ReadParam(subsection, "initial",
&cfg.delay.delay_selection_thresholds.initial);
ReadParam(subsection, "converged",
&cfg.delay.delay_selection_thresholds.converged);
}
}
if (rtc::GetValueFromJsonObject(root, "filter", &section)) {
ReadParam(section, "main", &cfg.filter.main);
ReadParam(section, "shadow", &cfg.filter.shadow);
ReadParam(section, "main_initial", &cfg.filter.main_initial);
ReadParam(section, "shadow_initial", &cfg.filter.shadow_initial);
ReadParam(section, "config_change_duration_blocks",
&cfg.filter.config_change_duration_blocks);
ReadParam(section, "initial_state_seconds",
&cfg.filter.initial_state_seconds);
ReadParam(section, "conservative_initial_phase",
&cfg.filter.conservative_initial_phase);
ReadParam(section, "enable_shadow_filter_output_usage",
&cfg.filter.enable_shadow_filter_output_usage);
}
if (rtc::GetValueFromJsonObject(root, "erle", &section)) {
ReadParam(section, "min", &cfg.erle.min);
ReadParam(section, "max_l", &cfg.erle.max_l);
ReadParam(section, "max_h", &cfg.erle.max_h);
ReadParam(section, "onset_detection", &cfg.erle.onset_detection);
}
if (rtc::GetValueFromJsonObject(root, "ep_strength", &section)) {
ReadParam(section, "lf", &cfg.ep_strength.lf);
ReadParam(section, "mf", &cfg.ep_strength.mf);
ReadParam(section, "hf", &cfg.ep_strength.hf);
ReadParam(section, "default_len", &cfg.ep_strength.default_len);
ReadParam(section, "reverb_based_on_render",
&cfg.ep_strength.reverb_based_on_render);
ReadParam(section, "echo_can_saturate",
&cfg.ep_strength.echo_can_saturate);
ReadParam(section, "bounded_erl", &cfg.ep_strength.bounded_erl);
}
if (rtc::GetValueFromJsonObject(root, "gain_mask", &section)) {
ReadParam(section, "m1", &cfg.gain_mask.m1);
ReadParam(section, "m2", &cfg.gain_mask.m2);
ReadParam(section, "m3", &cfg.gain_mask.m3);
ReadParam(section, "m5", &cfg.gain_mask.m5);
ReadParam(section, "m6", &cfg.gain_mask.m6);
ReadParam(section, "m7", &cfg.gain_mask.m7);
ReadParam(section, "m8", &cfg.gain_mask.m8);
ReadParam(section, "m9", &cfg.gain_mask.m9);
ReadParam(section, "gain_curve_offset", &cfg.gain_mask.gain_curve_offset);
ReadParam(section, "gain_curve_slope", &cfg.gain_mask.gain_curve_slope);
ReadParam(section, "temporal_masking_lf",
&cfg.gain_mask.temporal_masking_lf);
ReadParam(section, "temporal_masking_hf",
&cfg.gain_mask.temporal_masking_hf);
ReadParam(section, "temporal_masking_lf_bands",
&cfg.gain_mask.temporal_masking_lf_bands);
}
if (rtc::GetValueFromJsonObject(root, "echo_audibility", &section)) {
ReadParam(section, "low_render_limit",
&cfg.echo_audibility.low_render_limit);
ReadParam(section, "normal_render_limit",
&cfg.echo_audibility.normal_render_limit);
ReadParam(section, "floor_power", &cfg.echo_audibility.floor_power);
ReadParam(section, "audibility_threshold_lf",
&cfg.echo_audibility.audibility_threshold_lf);
ReadParam(section, "audibility_threshold_mf",
&cfg.echo_audibility.audibility_threshold_mf);
ReadParam(section, "audibility_threshold_hf",
&cfg.echo_audibility.audibility_threshold_hf);
ReadParam(section, "use_stationary_properties",
&cfg.echo_audibility.use_stationary_properties);
ReadParam(section, "use_stationary_properties_at_init",
&cfg.echo_audibility.use_stationarity_properties_at_init);
}
if (rtc::GetValueFromJsonObject(root, "echo_removal_control", &section)) {
Json::Value subsection;
if (rtc::GetValueFromJsonObject(section, "gain_rampup", &subsection)) {
ReadParam(subsection, "initial_gain",
&cfg.echo_removal_control.gain_rampup.initial_gain);
ReadParam(subsection, "first_non_zero_gain",
&cfg.echo_removal_control.gain_rampup.first_non_zero_gain);
ReadParam(subsection, "non_zero_gain_blocks",
&cfg.echo_removal_control.gain_rampup.non_zero_gain_blocks);
ReadParam(subsection, "full_gain_blocks",
&cfg.echo_removal_control.gain_rampup.full_gain_blocks);
}
ReadParam(section, "has_clock_drift",
&cfg.echo_removal_control.has_clock_drift);
ReadParam(section, "linear_and_stable_echo_path",
&cfg.echo_removal_control.linear_and_stable_echo_path);
}
if (rtc::GetValueFromJsonObject(root, "echo_model", &section)) {
Json::Value subsection;
ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold);
ReadParam(section, "min_noise_floor_power",
&cfg.echo_model.min_noise_floor_power);
ReadParam(section, "stationary_gate_slope",
&cfg.echo_model.stationary_gate_slope);
ReadParam(section, "noise_gate_power", &cfg.echo_model.noise_gate_power);
ReadParam(section, "noise_gate_slope", &cfg.echo_model.noise_gate_slope);
ReadParam(section, "render_pre_window_size",
&cfg.echo_model.render_pre_window_size);
ReadParam(section, "render_post_window_size",
&cfg.echo_model.render_post_window_size);
ReadParam(section, "render_pre_window_size_init",
&cfg.echo_model.render_pre_window_size_init);
ReadParam(section, "render_post_window_size_init",
&cfg.echo_model.render_post_window_size_init);
ReadParam(section, "nonlinear_hold", &cfg.echo_model.nonlinear_hold);
ReadParam(section, "nonlinear_release",
&cfg.echo_model.nonlinear_release);
}
Json::Value subsection;
if (rtc::GetValueFromJsonObject(root, "suppressor", &section)) {
ReadParam(section, "nearend_average_blocks",
&cfg.suppressor.nearend_average_blocks);
if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) {
ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf);
ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf);
ReadParam(subsection, "max_inc_factor",
&cfg.suppressor.normal_tuning.max_inc_factor);
ReadParam(subsection, "max_dec_factor_lf",
&cfg.suppressor.normal_tuning.max_dec_factor_lf);
}
if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) {
ReadParam(subsection, "mask_lf",
&cfg.suppressor.nearend_tuning.mask_lf);
ReadParam(subsection, "mask_hf",
&cfg.suppressor.nearend_tuning.mask_hf);
ReadParam(subsection, "max_inc_factor",
&cfg.suppressor.nearend_tuning.max_inc_factor);
ReadParam(subsection, "max_dec_factor_lf",
&cfg.suppressor.nearend_tuning.max_dec_factor_lf);
}
if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection",
&subsection)) {
ReadParam(subsection, "enr_threshold",
&cfg.suppressor.dominant_nearend_detection.enr_threshold);
ReadParam(subsection, "snr_threshold",
&cfg.suppressor.dominant_nearend_detection.snr_threshold);
ReadParam(subsection, "hold_duration",
&cfg.suppressor.dominant_nearend_detection.hold_duration);
ReadParam(subsection, "trigger_threshold",
&cfg.suppressor.dominant_nearend_detection.trigger_threshold);
}
if (rtc::GetValueFromJsonObject(section, "high_bands_suppression",
&subsection)) {
ReadParam(subsection, "enr_threshold",
&cfg.suppressor.high_bands_suppression.enr_threshold);
ReadParam(subsection, "max_gain_during_echo",
&cfg.suppressor.high_bands_suppression.max_gain_during_echo);
}
ReadParam(section, "floor_first_increase",
&cfg.suppressor.floor_first_increase);
ReadParam(section, "enforce_transparent",
&cfg.suppressor.enforce_transparent);
ReadParam(section, "enforce_empty_higher_bands",
&cfg.suppressor.enforce_empty_higher_bands);
}
std::cout << std::endl;
return cfg;
}
};
void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) {
RTC_CHECK_EQ(src.num_channels_, dest->num_channels());
RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames());
@ -947,7 +363,7 @@ void AudioProcessingSimulator::CreateAudioProcessor() {
if (settings_.use_verbose_logging) {
std::cout << "Reading AEC3 Parameters from JSON input." << std::endl;
}
cfg = Aec3ParametersParser::Parse(*settings_.aec3_settings_filename);
cfg = ReadAec3ConfigFromJsonFile(*settings_.aec3_settings_filename);
}
echo_control_factory.reset(new EchoCanceller3Factory(cfg));
@ -955,7 +371,7 @@ void AudioProcessingSimulator::CreateAudioProcessor() {
if (!settings_.use_quiet_output) {
std::cout << "AEC3 settings:" << std::endl;
}
PrintAec3ParameterValues(cfg);
std::cout << Aec3ConfigToJsonString(cfg) << std::endl;
}
}