1 /*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "api/audio/echo_canceller3_config_json.h"
12
13 #include "api/audio/echo_canceller3_config.h"
14 #include "test/gtest.h"
15
16 namespace webrtc {
17
TEST(EchoCanceller3JsonHelpers,ToStringAndParseJson)18 TEST(EchoCanceller3JsonHelpers, ToStringAndParseJson) {
19 EchoCanceller3Config cfg;
20 cfg.delay.down_sampling_factor = 1u;
21 cfg.delay.log_warning_on_delay_changes = true;
22 cfg.filter.refined.error_floor = 2.f;
23 cfg.filter.coarse_initial.length_blocks = 3u;
24 cfg.filter.high_pass_filter_echo_reference =
25 !cfg.filter.high_pass_filter_echo_reference;
26 cfg.comfort_noise.noise_floor_dbfs = 100.f;
27 cfg.echo_model.model_reverb_in_nonlinear_mode = false;
28 cfg.suppressor.normal_tuning.mask_hf.enr_suppress = .5f;
29 cfg.suppressor.subband_nearend_detection.nearend_average_blocks = 3;
30 cfg.suppressor.subband_nearend_detection.subband1 = {1, 3};
31 cfg.suppressor.subband_nearend_detection.subband1 = {4, 5};
32 cfg.suppressor.subband_nearend_detection.nearend_threshold = 2.f;
33 cfg.suppressor.subband_nearend_detection.snr_threshold = 100.f;
34 cfg.multi_channel.detect_stereo_content =
35 !cfg.multi_channel.detect_stereo_content;
36 cfg.multi_channel.stereo_detection_threshold += 1.0f;
37 cfg.multi_channel.stereo_detection_timeout_threshold_seconds += 1;
38 cfg.multi_channel.stereo_detection_hysteresis_seconds += 1;
39 std::string json_string = Aec3ConfigToJsonString(cfg);
40 EchoCanceller3Config cfg_transformed = Aec3ConfigFromJsonString(json_string);
41
42 // Expect unchanged values to remain default.
43 EXPECT_EQ(cfg.ep_strength.default_len,
44 cfg_transformed.ep_strength.default_len);
45 EXPECT_EQ(cfg.ep_strength.nearend_len,
46 cfg_transformed.ep_strength.nearend_len);
47 EXPECT_EQ(cfg.suppressor.normal_tuning.mask_lf.enr_suppress,
48 cfg_transformed.suppressor.normal_tuning.mask_lf.enr_suppress);
49
50 // Expect changed values to carry through the transformation.
51 EXPECT_EQ(cfg.delay.down_sampling_factor,
52 cfg_transformed.delay.down_sampling_factor);
53 EXPECT_EQ(cfg.delay.log_warning_on_delay_changes,
54 cfg_transformed.delay.log_warning_on_delay_changes);
55 EXPECT_EQ(cfg.filter.coarse_initial.length_blocks,
56 cfg_transformed.filter.coarse_initial.length_blocks);
57 EXPECT_EQ(cfg.filter.refined.error_floor,
58 cfg_transformed.filter.refined.error_floor);
59 EXPECT_EQ(cfg.filter.high_pass_filter_echo_reference,
60 cfg_transformed.filter.high_pass_filter_echo_reference);
61 EXPECT_EQ(cfg.comfort_noise.noise_floor_dbfs,
62 cfg_transformed.comfort_noise.noise_floor_dbfs);
63 EXPECT_EQ(cfg.echo_model.model_reverb_in_nonlinear_mode,
64 cfg_transformed.echo_model.model_reverb_in_nonlinear_mode);
65 EXPECT_EQ(cfg.suppressor.normal_tuning.mask_hf.enr_suppress,
66 cfg_transformed.suppressor.normal_tuning.mask_hf.enr_suppress);
67 EXPECT_EQ(cfg.suppressor.subband_nearend_detection.nearend_average_blocks,
68 cfg_transformed.suppressor.subband_nearend_detection
69 .nearend_average_blocks);
70 EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband1.low,
71 cfg_transformed.suppressor.subband_nearend_detection.subband1.low);
72 EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband1.high,
73 cfg_transformed.suppressor.subband_nearend_detection.subband1.high);
74 EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband2.low,
75 cfg_transformed.suppressor.subband_nearend_detection.subband2.low);
76 EXPECT_EQ(cfg.suppressor.subband_nearend_detection.subband2.high,
77 cfg_transformed.suppressor.subband_nearend_detection.subband2.high);
78 EXPECT_EQ(
79 cfg.suppressor.subband_nearend_detection.nearend_threshold,
80 cfg_transformed.suppressor.subband_nearend_detection.nearend_threshold);
81 EXPECT_EQ(cfg.suppressor.subband_nearend_detection.snr_threshold,
82 cfg_transformed.suppressor.subband_nearend_detection.snr_threshold);
83 EXPECT_EQ(cfg.multi_channel.detect_stereo_content,
84 cfg_transformed.multi_channel.detect_stereo_content);
85 EXPECT_EQ(cfg.multi_channel.stereo_detection_threshold,
86 cfg_transformed.multi_channel.stereo_detection_threshold);
87 EXPECT_EQ(
88 cfg.multi_channel.stereo_detection_timeout_threshold_seconds,
89 cfg_transformed.multi_channel.stereo_detection_timeout_threshold_seconds);
90 EXPECT_EQ(cfg.multi_channel.stereo_detection_hysteresis_seconds,
91 cfg_transformed.multi_channel.stereo_detection_hysteresis_seconds);
92 }
93 } // namespace webrtc
94