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

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

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: Fixed compilation error 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/comfort_noise_generator.h"
12
13 #include <algorithm>
14 #include <numeric>
15
16 #include "webrtc/typedefs.h"
17 #include "webrtc/base/random.h"
18 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
19 #include "webrtc/test/gtest.h"
20
21 namespace webrtc {
22 namespace aec3 {
23 namespace {
24
25 float Power(const FftData& N) {
26 std::array<float, kFftLengthBy2Plus1> N2;
27 N.Spectrum(Aec3Optimization::kNone, &N2);
28 return std::accumulate(N2.begin(), N2.end(), 0.f) / N2.size();
29 }
30
31 } // namespace
32
33 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
34
35 TEST(ComfortNoiseGenerator, NullLowerBandNoise) {
36 std::array<float, kFftLengthBy2Plus1> N2;
37 FftData noise;
38 EXPECT_DEATH(ComfortNoiseGenerator(DetectOptimization())
39 .Compute(AecState(), N2, nullptr, &noise),
40 "");
41 }
42
43 TEST(ComfortNoiseGenerator, NullUpperBandNoise) {
44 std::array<float, kFftLengthBy2Plus1> N2;
45 FftData noise;
46 EXPECT_DEATH(ComfortNoiseGenerator(DetectOptimization())
47 .Compute(AecState(), N2, &noise, nullptr),
48 "");
49 }
50
51 #endif
52
53 #if defined(WEBRTC_ARCH_X86_FAMILY)
54 // Verifies that the optimized methods are bitexact to their reference
55 // counterparts.
56 TEST(ComfortNoiseGenerator, TestOptimizations) {
57 if (WebRtc_GetCPUInfo(kSSE2) != 0) {
58 Random random_generator(42U);
59 uint32_t seed = 42;
60 uint32_t seed_SSE2 = 42;
61 std::array<float, kFftLengthBy2Plus1> N2;
62 FftData lower_band_noise;
63 FftData upper_band_noise;
64 FftData lower_band_noise_SSE2;
65 FftData upper_band_noise_SSE2;
66 for (int k = 0; k < 10; ++k) {
67 for (size_t j = 0; j < N2.size(); ++j) {
68 N2[j] = random_generator.Rand<float>() * 1000.f;
69 }
70
71 EstimateComfortNoise(N2, &seed, &lower_band_noise, &upper_band_noise);
72 EstimateComfortNoise_SSE2(N2, &seed_SSE2, &lower_band_noise_SSE2,
73 &upper_band_noise_SSE2);
74 for (size_t j = 0; j < lower_band_noise.re.size(); ++j) {
75 EXPECT_NEAR(lower_band_noise.re[j], lower_band_noise_SSE2.re[j],
76 0.00001f);
77 EXPECT_NEAR(upper_band_noise.re[j], upper_band_noise_SSE2.re[j],
78 0.00001f);
79 }
80 for (size_t j = 1; j < lower_band_noise.re.size() - 1; ++j) {
81 EXPECT_NEAR(lower_band_noise.im[j], lower_band_noise_SSE2.im[j],
82 0.00001f);
83 EXPECT_NEAR(upper_band_noise.im[j], upper_band_noise_SSE2.im[j],
84 0.00001f);
85 }
86 }
87 }
88 }
89
90 #endif
91
92 TEST(ComfortNoiseGenerator, CorrectLevel) {
93 ComfortNoiseGenerator cng(DetectOptimization());
94 AecState aec_state;
95
96 std::array<float, kFftLengthBy2Plus1> N2;
97 N2.fill(1000.f * 1000.f);
98
99 FftData n_lower;
100 FftData n_upper;
101 n_lower.re.fill(0.f);
102 n_lower.im.fill(0.f);
103 n_upper.re.fill(0.f);
104 n_upper.im.fill(0.f);
105
106 // Ensure instantaneous updata to nonzero noise.
107 cng.Compute(aec_state, N2, &n_lower, &n_upper);
108 EXPECT_LT(0.f, Power(n_lower));
109 EXPECT_LT(0.f, Power(n_upper));
110
111 for (int k = 0; k < 10000; ++k) {
112 cng.Compute(aec_state, N2, &n_lower, &n_upper);
113 }
114 EXPECT_NEAR(N2[0], Power(n_lower), N2[0] / 10.f);
115 EXPECT_NEAR(N2[0], Power(n_upper), N2[0] / 10.f);
116 }
117
118 } // namespace aec3
119 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698