Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: webrtc/modules/audio_processing/aec3/suppression_gain_unittest.cc

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: Fixed failing unittest Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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 "webrtc/modules/audio_processing/aec3/suppression_gain.h"
12
13 #include "webrtc/typedefs.h"
14 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
15 #include "webrtc/test/gtest.h"
16
17 namespace webrtc {
18
19 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
20
21 // Verifies that the check for non-null output gains works.
22 TEST(SuppressionGain, NullOutputGains) {
23 std::array<float, kFftLengthBy2Plus1> E2;
24 std::array<float, kFftLengthBy2Plus1> R2;
25 std::array<float, kFftLengthBy2Plus1> N2;
26 EXPECT_DEATH(
27 SuppressionGain(DetectOptimization()).GetGain(E2, R2, N2, 0.1f, nullptr),
28 "");
29 }
30
31 #endif
32
33 #if defined(WEBRTC_ARCH_X86_FAMILY)
34 // Verifies that the optimized methods are bitexact to their reference
35 // counterparts.
36 TEST(SuppressionGain, TestOptimizations) {
37 if (WebRtc_GetCPUInfo(kSSE2) != 0) {
38 std::array<float, kFftLengthBy2 - 1> G2_old;
39 std::array<float, kFftLengthBy2 - 1> M2_old;
40 std::array<float, kFftLengthBy2 - 1> G2_old_SSE2;
41 std::array<float, kFftLengthBy2 - 1> M2_old_SSE2;
42 std::array<float, kFftLengthBy2Plus1> E2;
43 std::array<float, kFftLengthBy2Plus1> R2;
44 std::array<float, kFftLengthBy2Plus1> N2;
45 std::array<float, kFftLengthBy2Plus1> g;
46 std::array<float, kFftLengthBy2Plus1> g_SSE2;
47
48 G2_old.fill(1.f);
49 M2_old.fill(.23f);
50 G2_old_SSE2.fill(1.f);
51 M2_old_SSE2.fill(.23f);
52
53 E2.fill(10.f);
54 R2.fill(0.1f);
55 N2.fill(100.f);
56 for (int k = 0; k < 10; ++k) {
57 ComputeGains(E2, R2, N2, 0.1f, &G2_old, &M2_old, &g);
58 ComputeGains_SSE2(E2, R2, N2, 0.1f, &G2_old_SSE2, &M2_old_SSE2, &g_SSE2);
59 for (size_t j = 0; j < G2_old.size(); ++j) {
60 EXPECT_NEAR(G2_old[j], G2_old_SSE2[j], 0.0000001f);
hlundin-webrtc 2017/02/21 16:34:03 Would EXPECT_FLOAT_EQ work here?
peah-webrtc 2017/02/21 23:00:41 No, it would not, as the SSE2 sqrt method seems no
hlundin-webrtc 2017/02/22 15:24:05 Acknowledged.
peah-webrtc 2017/02/22 23:51:36 Acknowledged.
61 }
62 for (size_t j = 0; j < M2_old.size(); ++j) {
63 EXPECT_NEAR(M2_old[j], M2_old_SSE2[j], 0.0000001f);
64 }
65 for (size_t j = 0; j < g.size(); ++j) {
66 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f);
67 }
68 }
69
70 E2.fill(100.f);
71 R2.fill(0.1f);
72 N2.fill(0.f);
73 for (int k = 0; k < 10; ++k) {
74 ComputeGains(E2, R2, N2, 0.1f, &G2_old, &M2_old, &g);
75 ComputeGains_SSE2(E2, R2, N2, 0.1f, &G2_old_SSE2, &M2_old_SSE2, &g_SSE2);
76 for (size_t j = 0; j < G2_old.size(); ++j) {
77 EXPECT_NEAR(G2_old[j], G2_old_SSE2[j], 0.0000001f);
78 }
79 for (size_t j = 0; j < M2_old.size(); ++j) {
80 EXPECT_NEAR(M2_old[j], M2_old_SSE2[j], 0.0000001f);
81 }
82 for (size_t j = 0; j < g.size(); ++j) {
83 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f);
84 }
85 }
86
87 E2.fill(0.1f);
88 R2.fill(100.f);
89 N2.fill(0.f);
90 for (int k = 0; k < 10; ++k) {
91 ComputeGains(E2, R2, N2, 0.1f, &G2_old, &M2_old, &g);
92 ComputeGains_SSE2(E2, R2, N2, 0.1f, &G2_old_SSE2, &M2_old_SSE2, &g_SSE2);
93 for (size_t j = 0; j < G2_old.size(); ++j) {
94 EXPECT_NEAR(G2_old[j], G2_old_SSE2[j], 0.0000001f);
95 }
96 for (size_t j = 0; j < M2_old.size(); ++j) {
97 EXPECT_NEAR(M2_old[j], M2_old_SSE2[j], 0.0000001f);
98 }
99 for (size_t j = 0; j < g.size(); ++j) {
100 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f);
101 }
102 }
103 }
104 }
105 #endif
106
107 // Does a sanity check that the gains are correctly computed.
108 TEST(SuppressionGain, BasicGainComputation) {
109 SuppressionGain suppression_gain(DetectOptimization());
110 std::array<float, kFftLengthBy2Plus1> E2;
111 std::array<float, kFftLengthBy2Plus1> R2;
112 std::array<float, kFftLengthBy2Plus1> N2;
113 std::array<float, kFftLengthBy2Plus1> g;
114
115 // Ensure that a strong noise is detected to mask any echoes.
116 E2.fill(10.f);
117 R2.fill(0.1f);
118 N2.fill(100.f);
119 for (int k = 0; k < 10; ++k) {
120 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g);
121 }
122 std::for_each(g.begin(), g.end(),
123 [](float a) { EXPECT_NEAR(1.f, a, 0.001); });
124
125 // Ensure that a strong nearend is detected to mask any echoes.
126 E2.fill(100.f);
127 R2.fill(0.1f);
128 N2.fill(0.f);
129 for (int k = 0; k < 10; ++k) {
130 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g);
131 }
132 std::for_each(g.begin(), g.end(),
133 [](float a) { EXPECT_NEAR(1.f, a, 0.001); });
134
135 // Ensure that a strong echo is suppressed.
136 E2.fill(0.1f);
137 R2.fill(100.f);
138 N2.fill(0.f);
139 for (int k = 0; k < 10; ++k) {
140 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g);
141 }
142 std::for_each(g.begin(), g.end(),
143 [](float a) { EXPECT_NEAR(0.f, a, 0.001); });
144 }
145
146 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698