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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 EXPECT_DEATH(SuppressionGain(DetectOptimization()) | 32 EXPECT_DEATH(SuppressionGain(DetectOptimization()) |
33 .GetGain(E2, R2, N2, false, | 33 .GetGain(E2, R2, N2, false, |
34 std::vector<std::vector<float>>( | 34 std::vector<std::vector<float>>( |
35 3, std::vector<float>(kBlockSize, 0.f)), | 35 3, std::vector<float>(kBlockSize, 0.f)), |
36 1, false, &high_bands_gain, nullptr), | 36 1, false, &high_bands_gain, nullptr), |
37 ""); | 37 ""); |
38 } | 38 } |
39 | 39 |
40 #endif | 40 #endif |
41 | 41 |
42 #if defined(WEBRTC_ARCH_X86_FAMILY) | |
43 // Verifies that the optimized methods are bitexact to their reference | |
44 // counterparts. | |
45 TEST(SuppressionGain, TestOptimizations) { | |
46 if (WebRtc_GetCPUInfo(kSSE2) != 0) { | |
47 std::array<float, kFftLengthBy2 - 1> G2_old; | |
48 std::array<float, kFftLengthBy2 - 1> M2_old; | |
49 std::array<float, kFftLengthBy2 - 1> G2_old_SSE2; | |
50 std::array<float, kFftLengthBy2 - 1> M2_old_SSE2; | |
51 std::array<float, kFftLengthBy2Plus1> E2; | |
52 std::array<float, kFftLengthBy2Plus1> R2; | |
53 std::array<float, kFftLengthBy2Plus1> N2; | |
54 std::array<float, kFftLengthBy2Plus1> g; | |
55 std::array<float, kFftLengthBy2Plus1> g_SSE2; | |
56 | |
57 G2_old.fill(1.f); | |
58 M2_old.fill(.23f); | |
59 G2_old_SSE2.fill(1.f); | |
60 M2_old_SSE2.fill(.23f); | |
61 | |
62 E2.fill(10.f); | |
63 R2.fill(0.1f); | |
64 N2.fill(100.f); | |
65 for (int k = 0; k < 10; ++k) { | |
66 ComputeGains(E2, R2, N2, 0.1f, &G2_old, &M2_old, &g); | |
67 ComputeGains_SSE2(E2, R2, N2, 0.1f, &G2_old_SSE2, &M2_old_SSE2, &g_SSE2); | |
68 for (size_t j = 0; j < G2_old.size(); ++j) { | |
69 EXPECT_NEAR(G2_old[j], G2_old_SSE2[j], 0.0000001f); | |
70 } | |
71 for (size_t j = 0; j < M2_old.size(); ++j) { | |
72 EXPECT_NEAR(M2_old[j], M2_old_SSE2[j], 0.0000001f); | |
73 } | |
74 for (size_t j = 0; j < g.size(); ++j) { | |
75 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); | |
76 } | |
77 } | |
78 | |
79 E2.fill(100.f); | |
80 R2.fill(0.1f); | |
81 N2.fill(0.f); | |
82 for (int k = 0; k < 10; ++k) { | |
83 ComputeGains(E2, R2, N2, 0.1f, &G2_old, &M2_old, &g); | |
84 ComputeGains_SSE2(E2, R2, N2, 0.1f, &G2_old_SSE2, &M2_old_SSE2, &g_SSE2); | |
85 for (size_t j = 0; j < G2_old.size(); ++j) { | |
86 EXPECT_NEAR(G2_old[j], G2_old_SSE2[j], 0.0000001f); | |
87 } | |
88 for (size_t j = 0; j < M2_old.size(); ++j) { | |
89 EXPECT_NEAR(M2_old[j], M2_old_SSE2[j], 0.0000001f); | |
90 } | |
91 for (size_t j = 0; j < g.size(); ++j) { | |
92 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); | |
93 } | |
94 } | |
95 | |
96 E2.fill(0.1f); | |
97 R2.fill(100.f); | |
98 N2.fill(0.f); | |
99 for (int k = 0; k < 10; ++k) { | |
100 ComputeGains(E2, R2, N2, 0.1f, &G2_old, &M2_old, &g); | |
101 ComputeGains_SSE2(E2, R2, N2, 0.1f, &G2_old_SSE2, &M2_old_SSE2, &g_SSE2); | |
102 for (size_t j = 0; j < G2_old.size(); ++j) { | |
103 EXPECT_NEAR(G2_old[j], G2_old_SSE2[j], 0.0000001f); | |
104 } | |
105 for (size_t j = 0; j < M2_old.size(); ++j) { | |
106 EXPECT_NEAR(M2_old[j], M2_old_SSE2[j], 0.0000001f); | |
107 } | |
108 for (size_t j = 0; j < g.size(); ++j) { | |
109 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); | |
110 } | |
111 } | |
112 } | |
113 } | |
114 #endif | |
115 | |
116 // Does a sanity check that the gains are correctly computed. | 42 // Does a sanity check that the gains are correctly computed. |
117 TEST(SuppressionGain, BasicGainComputation) { | 43 TEST(SuppressionGain, BasicGainComputation) { |
118 SuppressionGain suppression_gain(DetectOptimization()); | 44 SuppressionGain suppression_gain(DetectOptimization()); |
119 float high_bands_gain; | 45 float high_bands_gain; |
120 std::array<float, kFftLengthBy2Plus1> E2; | 46 std::array<float, kFftLengthBy2Plus1> E2; |
121 std::array<float, kFftLengthBy2Plus1> R2; | 47 std::array<float, kFftLengthBy2Plus1> R2; |
122 std::array<float, kFftLengthBy2Plus1> N2; | 48 std::array<float, kFftLengthBy2Plus1> N2; |
123 std::array<float, kFftLengthBy2Plus1> g; | 49 std::array<float, kFftLengthBy2Plus1> g; |
124 std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f)); | 50 std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f)); |
125 | 51 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 [](float a) { EXPECT_NEAR(0.f, a, 0.001); }); | 83 [](float a) { EXPECT_NEAR(0.f, a, 0.001); }); |
158 | 84 |
159 // Verify the functionality for forcing a zero gain. | 85 // Verify the functionality for forcing a zero gain. |
160 suppression_gain.GetGain(E2, R2, N2, false, x, 1, true, &high_bands_gain, &g); | 86 suppression_gain.GetGain(E2, R2, N2, false, x, 1, true, &high_bands_gain, &g); |
161 std::for_each(g.begin(), g.end(), [](float a) { EXPECT_FLOAT_EQ(0.f, a); }); | 87 std::for_each(g.begin(), g.end(), [](float a) { EXPECT_FLOAT_EQ(0.f, a); }); |
162 EXPECT_FLOAT_EQ(0.f, high_bands_gain); | 88 EXPECT_FLOAT_EQ(0.f, high_bands_gain); |
163 } | 89 } |
164 | 90 |
165 } // namespace aec3 | 91 } // namespace aec3 |
166 } // namespace webrtc | 92 } // namespace webrtc |
OLD | NEW |