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

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

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: Fixed compilation error Created 3 years, 9 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/render_signal_analyzer.h"
12
13 #include <math.h>
14 #include <array>
15 #include <vector>
16
17 #include "webrtc/base/array_view.h"
18 #include "webrtc/base/random.h"
19 #include "webrtc/modules/audio_processing/aec3/aec3_common.h"
20 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h"
21 #include "webrtc/modules/audio_processing/aec3/fft_buffer.h"
22 #include "webrtc/modules/audio_processing/aec3/fft_data.h"
23 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h"
24 #include "webrtc/test/gtest.h"
25
26 namespace webrtc {
27 namespace {
28
29 constexpr float kPi = 3.141592f;
30
31 void ProduceSinusoid(int sample_rate_hz,
32 float sinusoidal_frequency_hz,
33 size_t* sample_counter,
34 rtc::ArrayView<float> x) {
35 // Produce a sinusoid of the specified frequency.
36 for (size_t k = *sample_counter, j = 0; k < (*sample_counter + kBlockSize);
37 ++k, ++j) {
38 x[j] =
39 32767.f * sin(2.f * kPi * sinusoidal_frequency_hz * k / sample_rate_hz);
40 }
41 *sample_counter = *sample_counter + kBlockSize;
42 }
43
44 } // namespace
45
46 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
47 // Verifies that the check for non-null output parameter works.
48 TEST(RenderSignalAnalyzer, NullMaskOutput) {
49 RenderSignalAnalyzer analyzer;
50 EXPECT_DEATH(analyzer.MaskRegionsAroundNarrowBands(nullptr), "");
51 }
52
53 #endif
54
55 // Verify that no narrow bands are detected in a Gaussian noise signal.
56 TEST(RenderSignalAnalyzer, NoFalseDetectionOfNarrowBands) {
57 RenderSignalAnalyzer analyzer;
58 Random random_generator(42U);
59 std::vector<float> x(kBlockSize, 0.f);
60 std::array<float, kBlockSize> x_old;
61 FftData X;
62 Aec3Fft fft;
63 FftBuffer X_buffer(Aec3Optimization::kNone, 1, std::vector<size_t>(1, 1));
64 std::array<float, kFftLengthBy2Plus1> mask;
65 x_old.fill(0.f);
66
67 for (size_t k = 0; k < 100; ++k) {
68 RandomizeSampleVector(&random_generator, x);
69 fft.PaddedFft(x, x_old, &X);
70 X_buffer.Insert(X);
71 analyzer.Update(X_buffer, rtc::Optional<size_t>(0));
72 }
73
74 mask.fill(1.f);
75 analyzer.MaskRegionsAroundNarrowBands(&mask);
76 EXPECT_TRUE(
77 std::all_of(mask.begin(), mask.end(), [](float a) { return a == 1.f; }));
78 EXPECT_FALSE(analyzer.PoorSignalExcitation());
79 }
80
81 // Verify that a sinusiod signal is detected as narrow bands.
82 TEST(RenderSignalAnalyzer, NarrowBandDetection) {
83 RenderSignalAnalyzer analyzer;
84 Random random_generator(42U);
85 std::vector<float> x(kBlockSize, 0.f);
86 std::array<float, kBlockSize> x_old;
87 FftData X;
88 Aec3Fft fft;
89 FftBuffer X_buffer(Aec3Optimization::kNone, 1, std::vector<size_t>(1, 1));
90 std::array<float, kFftLengthBy2Plus1> mask;
91 x_old.fill(0.f);
92 constexpr int kSinusFrequencyBin = 32;
93
94 auto generate_sinusoid_test = [&](bool known_delay) {
95 size_t sample_counter = 0;
96 for (size_t k = 0; k < 100; ++k) {
97 ProduceSinusoid(16000, 16000 / 2 * kSinusFrequencyBin / kFftLengthBy2,
98 &sample_counter, x);
99 fft.PaddedFft(x, x_old, &X);
100 X_buffer.Insert(X);
101 analyzer.Update(
102 X_buffer,
103 known_delay ? rtc::Optional<size_t>(0) : rtc::Optional<size_t>());
104 }
105 };
106
107 generate_sinusoid_test(true);
108 mask.fill(1.f);
109 analyzer.MaskRegionsAroundNarrowBands(&mask);
110 for (int k = 0; k < static_cast<int>(mask.size()); ++k) {
111 EXPECT_EQ(abs(k - kSinusFrequencyBin) <= 2 ? 0.f : 1.f, mask[k]);
112 }
113 EXPECT_TRUE(analyzer.PoorSignalExcitation());
114
115 // Verify that no bands are detected as narrow when the delay is unknown.
116 generate_sinusoid_test(false);
117 mask.fill(1.f);
118 analyzer.MaskRegionsAroundNarrowBands(&mask);
119 std::for_each(mask.begin(), mask.end(), [](float a) { EXPECT_EQ(1.f, a); });
120 EXPECT_FALSE(analyzer.PoorSignalExcitation());
121 }
122
123 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698