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

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

Issue 2644123002: Adding full initial version of delay estimation functionality in echo canceller 3 (Closed)
Patch Set: Changes in response to reviewer comments 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/decimator_by_4.h"
12
13 #include <math.h>
14 #include <algorithm>
15 #include <array>
16 #include <sstream>
17 #include <string>
18 #include <vector>
19
20 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
21 #include "webrtc/test/gtest.h"
22
23 namespace webrtc {
24
25 namespace {
26
27 std::string ProduceDebugText(int sample_rate_hz) {
28 std::ostringstream ss;
29 ss << "Sample rate: " << sample_rate_hz;
30 return ss.str();
31 }
32
33 constexpr float kPi = 3.141592f;
34 constexpr size_t kNumStartupBlocks = 50;
35 constexpr size_t kNumBlocks = 1000;
36
37 void ProduceDecimatedSinusoidalOutputPower(int rate,
hlundin-webrtc 2017/02/06 09:13:18 sample_rate
peah-webrtc 2017/02/06 11:25:38 Done.
38 float sinusoidal_frequency,
39 double* input_power,
40 double* output_power) {
41 float input[kBlockSize * kNumBlocks];
42
43 // Produce a sinusoid of frequency 3/8 * sample rate.
hlundin-webrtc 2017/02/06 09:13:18 Two spaces between "sinusoid" and "of". And commen
peah-webrtc 2017/02/06 11:25:38 Ah, thanks! Done.
44 for (size_t k = 0; k < kBlockSize * kNumBlocks; ++k) {
45 input[k] = 32767.f * sin(2.f * kPi * sinusoidal_frequency * k / rate);
46 }
47
48 DecimatorBy4 decimator;
49 std::array<float, kSubBlockSize * kNumBlocks> output;
50
51 for (size_t k = 0; k < kNumBlocks; ++k) {
52 std::array<float, kSubBlockSize> sub_block;
53
54 decimator.Decimate(
55 rtc::ArrayView<const float>(&input[k * kBlockSize], kBlockSize),
56 &sub_block);
57
58 std::copy(sub_block.begin(), sub_block.end(),
59 output.begin() + k * kSubBlockSize);
60 }
61
62 RTC_DCHECK_GT(kNumBlocks, kNumStartupBlocks);
hlundin-webrtc 2017/02/06 09:13:18 ASSERT_GT. Don't crash the test binary.
peah-webrtc 2017/02/06 11:25:38 Done.
63 rtc::ArrayView<const float> input_to_evaluate(
64 &input[kNumStartupBlocks * kBlockSize],
65 (kNumBlocks - kNumStartupBlocks) * kBlockSize);
66 rtc::ArrayView<const float> output_to_evaluate(
67 &output[kNumStartupBlocks * kSubBlockSize],
68 (kNumBlocks - kNumStartupBlocks) * kSubBlockSize);
69 *input_power =
70 std::inner_product(input_to_evaluate.begin(), input_to_evaluate.end(),
71 input_to_evaluate.begin(), 0.) /
hlundin-webrtc 2017/02/06 09:13:18 Looks a bit odd with just "0."; maybe write "0.f"
peah-webrtc 2017/02/06 11:25:38 I actually think that 0.0 would be the correct her
72 input_to_evaluate.size();
73 *output_power =
74 std::inner_product(output_to_evaluate.begin(), output_to_evaluate.end(),
75 output_to_evaluate.begin(), 0.) /
hlundin-webrtc 2017/02/06 09:13:18 Same here.
peah-webrtc 2017/02/06 11:25:38 Done.
76 output_to_evaluate.size();
77 }
78
79 } // namespace
80
81 // Verifies that there is little aliasing from upper frequencies in the
82 // downsampling.
83 TEST(DecimatorBy4, NoLeakageFromUpperFrequencies) {
84 double input_power;
85 double output_power;
86 for (auto rate : {8000, 16000, 32000, 48000}) {
87 ProduceDebugText(rate);
88 ProduceDecimatedSinusoidalOutputPower(rate, 3.f / 8.f * rate, &input_power,
89 &output_power);
90 EXPECT_GT(0.0001f * input_power, output_power);
91 }
92 }
93
94 // Verifies that the impact of low-frequency content is small during the
95 // downsampling.
96 TEST(DecimatorBy4, NoImpactOnLowerFrequencies) {
97 double input_power;
98 double output_power;
99 for (auto rate : {8000, 16000, 32000, 48000}) {
100 ProduceDebugText(rate);
101 ProduceDecimatedSinusoidalOutputPower(rate, 200.f, &input_power,
102 &output_power);
103 EXPECT_LT(0.7f * input_power, output_power);
104 }
105 }
106
107 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
108 // Verifies the check for the input size.
109 TEST(DecimatorBy4, WrongInputSize) {
110 DecimatorBy4 decimator;
111 std::vector<float> x(std::vector<float>(kBlockSize - 1, 0.f));
112 std::array<float, kSubBlockSize> x_downsampled;
113 EXPECT_DEATH(decimator.Decimate(x, &x_downsampled), "");
114 }
115
116 // Verifies the check for non-null output.
117 TEST(DecimatorBy4, WrongOutputSize) {
hlundin-webrtc 2017/02/06 09:13:18 The name of the test is not consistent with the co
peah-webrtc 2017/02/06 11:25:38 Not fully sure that I understood your comment corr
hlundin-webrtc 2017/02/06 14:33:34 But the test name is WrongOutputSize.
peah-webrtc 2017/02/07 05:40:57 (facepalm) Thanks! I cannot see how I could miss t
118 DecimatorBy4 decimator;
119 std::vector<float> x(std::vector<float>(kBlockSize, 0.f));
120
hlundin-webrtc 2017/02/06 09:13:18 You can drop this blank line.
peah-webrtc 2017/02/06 11:25:38 Done.
121 EXPECT_DEATH(decimator.Decimate(x, nullptr), "");
122 }
123
124 #endif
125
126 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698