OLD | NEW |
---|---|
(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_constants.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 ProduceSinusoidalSignal(int sample_rate_hz, | |
hlundin-webrtc
2017/02/13 21:37:01
Shorten the name to ProduceSinusoid.
peah-webrtc
2017/02/20 07:37:18
Done.
| |
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 TEST(RenderSignalAnalyzer, BasicSetup) { | |
56 RenderSignalAnalyzer analyzer; | |
57 | |
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(1, std::vector<size_t>(1, 1)); | |
64 std::array<float, kFftLengthBy2Plus1> mask; | |
65 x_old.fill(0.f); | |
66 constexpr int kSinusFrequencyBin = 32; | |
67 | |
68 // Verify that no narrow bands are present in a Gaussian noise signal. | |
69 for (size_t k = 0; k < 100; ++k) { | |
70 RandomizeSampleVector(&random_generator, x); | |
71 fft.PaddedFft(x, x_old, &X); | |
72 X_buffer.Insert(X); | |
73 analyzer.Update(X_buffer, rtc::Optional<size_t>(0)); | |
74 } | |
75 | |
76 mask.fill(1.f); | |
77 analyzer.MaskRegionsAroundNarrowBands(&mask); | |
78 std::for_each(mask.begin(), mask.end(), [](float a) { EXPECT_EQ(1.f, a); }); | |
hlundin-webrtc
2017/02/13 21:37:01
Consider:
EXPECT_TRUE(std::all_of(mask.begin(), ma
peah-webrtc
2017/02/20 07:37:18
Nice one!
Done.
| |
79 EXPECT_FALSE(analyzer.PoorSignalExcitation()); | |
80 | |
81 auto generate_sinusoid_test = [&](bool known_delay) { | |
82 size_t sample_counter = 0; | |
83 for (size_t k = 0; k < 100; ++k) { | |
84 ProduceSinusoidalSignal(16000, | |
85 16000 / 2 * kSinusFrequencyBin / kFftLengthBy2, | |
86 &sample_counter, x); | |
87 fft.PaddedFft(x, x_old, &X); | |
88 X_buffer.Insert(X); | |
89 analyzer.Update(X_buffer, known_delay ? rtc::Optional<size_t>(0) | |
90 : rtc::Optional<size_t>()); | |
91 } | |
92 }; | |
93 | |
94 // Verify that a sinusiod signal is detected as narrow bands. | |
hlundin-webrtc
2017/02/13 21:37:01
This seems like a new TEST.
peah-webrtc
2017/02/20 07:37:18
Done.
| |
95 generate_sinusoid_test(true); | |
96 mask.fill(1.f); | |
97 analyzer.MaskRegionsAroundNarrowBands(&mask); | |
98 for (int k = 0; k < static_cast<int>(mask.size()); ++k) { | |
99 EXPECT_EQ(abs(k - kSinusFrequencyBin) <= 2 ? 0.f : 1.f, mask[k]); | |
100 } | |
101 EXPECT_TRUE(analyzer.PoorSignalExcitation()); | |
102 | |
103 // Verify that a no bands are detected as narrow when the delay is unknown. | |
hlundin-webrtc
2017/02/13 21:37:01
Delete 'a'
hlundin-webrtc
2017/02/13 21:37:01
Seems like yet another TEST.
peah-webrtc
2017/02/20 07:37:18
Done.
peah-webrtc
2017/02/20 07:37:18
Done.
| |
104 generate_sinusoid_test(false); | |
105 mask.fill(1.f); | |
106 analyzer.MaskRegionsAroundNarrowBands(&mask); | |
107 std::for_each(mask.begin(), mask.end(), [](float a) { EXPECT_EQ(1.f, a); }); | |
108 EXPECT_FALSE(analyzer.PoorSignalExcitation()); | |
109 } | |
110 | |
hlundin-webrtc
2017/02/13 21:37:01
You are only testing with an input mask with all o
peah-webrtc
2017/02/20 07:37:18
That is tested on line 99.
| |
111 } // namespace webrtc | |
OLD | NEW |