OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/aec3/suppression_gain.h" | 11 #include "webrtc/modules/audio_processing/aec3/suppression_gain.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 14 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
15 #include "webrtc/test/gtest.h" | 15 #include "webrtc/test/gtest.h" |
16 #include "webrtc/typedefs.h" | 16 #include "webrtc/typedefs.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 namespace aec3 { | 19 namespace aec3 { |
20 | 20 |
21 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 21 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
22 | 22 |
23 // Verifies that the check for non-null output gains works. | 23 // Verifies that the check for non-null output gains works. |
24 TEST(SuppressionGain, NullOutputGains) { | 24 TEST(SuppressionGain, NullOutputGains) { |
25 std::array<float, kFftLengthBy2Plus1> E2; | 25 std::array<float, kFftLengthBy2Plus1> E2; |
26 std::array<float, kFftLengthBy2Plus1> R2; | 26 std::array<float, kFftLengthBy2Plus1> R2; |
27 std::array<float, kFftLengthBy2Plus1> N2; | 27 std::array<float, kFftLengthBy2Plus1> N2; |
28 EXPECT_DEATH( | 28 E2.fill(0.f); |
29 SuppressionGain(DetectOptimization()).GetGain(E2, R2, N2, 0.1f, nullptr), | 29 R2.fill(0.f); |
30 ""); | 30 N2.fill(0.f); |
| 31 float high_bands_gain; |
| 32 EXPECT_DEATH(SuppressionGain(DetectOptimization()) |
| 33 .GetGain(E2, R2, N2, false, |
| 34 std::vector<std::vector<float>>( |
| 35 3, std::vector<float>(kBlockSize, 0.f)), |
| 36 1, &high_bands_gain, nullptr), |
| 37 ""); |
31 } | 38 } |
32 | 39 |
33 #endif | 40 #endif |
34 | 41 |
35 #if defined(WEBRTC_ARCH_X86_FAMILY) | 42 #if defined(WEBRTC_ARCH_X86_FAMILY) |
36 // Verifies that the optimized methods are bitexact to their reference | 43 // Verifies that the optimized methods are bitexact to their reference |
37 // counterparts. | 44 // counterparts. |
38 TEST(SuppressionGain, TestOptimizations) { | 45 TEST(SuppressionGain, TestOptimizations) { |
39 if (WebRtc_GetCPUInfo(kSSE2) != 0) { | 46 if (WebRtc_GetCPUInfo(kSSE2) != 0) { |
40 std::array<float, kFftLengthBy2 - 1> G2_old; | 47 std::array<float, kFftLengthBy2 - 1> G2_old; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); | 109 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); |
103 } | 110 } |
104 } | 111 } |
105 } | 112 } |
106 } | 113 } |
107 #endif | 114 #endif |
108 | 115 |
109 // Does a sanity check that the gains are correctly computed. | 116 // Does a sanity check that the gains are correctly computed. |
110 TEST(SuppressionGain, BasicGainComputation) { | 117 TEST(SuppressionGain, BasicGainComputation) { |
111 SuppressionGain suppression_gain(DetectOptimization()); | 118 SuppressionGain suppression_gain(DetectOptimization()); |
| 119 float high_bands_gain; |
112 std::array<float, kFftLengthBy2Plus1> E2; | 120 std::array<float, kFftLengthBy2Plus1> E2; |
113 std::array<float, kFftLengthBy2Plus1> R2; | 121 std::array<float, kFftLengthBy2Plus1> R2; |
114 std::array<float, kFftLengthBy2Plus1> N2; | 122 std::array<float, kFftLengthBy2Plus1> N2; |
115 std::array<float, kFftLengthBy2Plus1> g; | 123 std::array<float, kFftLengthBy2Plus1> g; |
| 124 std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f)); |
116 | 125 |
117 // Ensure that a strong noise is detected to mask any echoes. | 126 // Ensure that a strong noise is detected to mask any echoes. |
118 E2.fill(10.f); | 127 E2.fill(10.f); |
119 R2.fill(0.1f); | 128 R2.fill(0.1f); |
120 N2.fill(100.f); | 129 N2.fill(100.f); |
121 for (int k = 0; k < 10; ++k) { | 130 for (int k = 0; k < 10; ++k) { |
122 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g); | 131 suppression_gain.GetGain(E2, R2, N2, false, x, 1, &high_bands_gain, &g); |
123 } | 132 } |
124 std::for_each(g.begin(), g.end(), | 133 std::for_each(g.begin(), g.end(), |
125 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); | 134 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); |
126 | 135 |
127 // Ensure that a strong nearend is detected to mask any echoes. | 136 // Ensure that a strong nearend is detected to mask any echoes. |
128 E2.fill(100.f); | 137 E2.fill(100.f); |
129 R2.fill(0.1f); | 138 R2.fill(0.1f); |
130 N2.fill(0.f); | 139 N2.fill(0.f); |
131 for (int k = 0; k < 10; ++k) { | 140 for (int k = 0; k < 10; ++k) { |
132 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g); | 141 suppression_gain.GetGain(E2, R2, N2, false, x, 1, &high_bands_gain, &g); |
133 } | 142 } |
134 std::for_each(g.begin(), g.end(), | 143 std::for_each(g.begin(), g.end(), |
135 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); | 144 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); |
136 | 145 |
137 // Ensure that a strong echo is suppressed. | 146 // Ensure that a strong echo is suppressed. |
138 E2.fill(0.1f); | 147 E2.fill(0.1f); |
139 R2.fill(100.f); | 148 R2.fill(100.f); |
140 N2.fill(0.f); | 149 N2.fill(0.f); |
141 for (int k = 0; k < 10; ++k) { | 150 for (int k = 0; k < 10; ++k) { |
142 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g); | 151 suppression_gain.GetGain(E2, R2, N2, false, x, 1, &high_bands_gain, &g); |
143 } | 152 } |
144 std::for_each(g.begin(), g.end(), | 153 std::for_each(g.begin(), g.end(), |
145 [](float a) { EXPECT_NEAR(0.f, a, 0.001); }); | 154 [](float a) { EXPECT_NEAR(0.f, a, 0.001); }); |
146 } | 155 } |
147 | 156 |
148 } // namespace aec3 | 157 } // namespace aec3 |
149 } // namespace webrtc | 158 } // namespace webrtc |
OLD | NEW |