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

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: Rebase 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 <numeric>
17 #include <sstream>
18 #include <string>
19 #include <vector>
20
21 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
22 #include "webrtc/test/gtest.h"
23
24 namespace webrtc {
25
26 namespace {
27
28 std::string ProduceDebugText(int sample_rate_hz) {
29 std::ostringstream ss;
30 ss << "Sample rate: " << sample_rate_hz;
31 return ss.str();
32 }
33
34 constexpr float kPi = 3.141592f;
35 constexpr size_t kNumStartupBlocks = 50;
36 constexpr size_t kNumBlocks = 1000;
37
38 void ProduceDecimatedSinusoidalOutputPower(int sample_rate_hz,
39 float sinusoidal_frequency_hz,
40 float* input_power,
41 float* output_power) {
42 float input[kBlockSize * kNumBlocks];
43
44 // Produce a sinusoid of the specified frequency.
45 for (size_t k = 0; k < kBlockSize * kNumBlocks; ++k) {
46 input[k] =
47 32767.f * sin(2.f * kPi * sinusoidal_frequency_hz * k / sample_rate_hz);
48 }
49
50 DecimatorBy4 decimator;
51 std::array<float, kSubBlockSize * kNumBlocks> output;
52
53 for (size_t k = 0; k < kNumBlocks; ++k) {
54 std::array<float, kSubBlockSize> sub_block;
55
56 decimator.Decimate(
57 rtc::ArrayView<const float>(&input[k * kBlockSize], kBlockSize),
58 &sub_block);
59
60 std::copy(sub_block.begin(), sub_block.end(),
61 output.begin() + k * kSubBlockSize);
62 }
63
64 ASSERT_GT(kNumBlocks, kNumStartupBlocks);
65 rtc::ArrayView<const float> input_to_evaluate(
66 &input[kNumStartupBlocks * kBlockSize],
67 (kNumBlocks - kNumStartupBlocks) * kBlockSize);
68 rtc::ArrayView<const float> output_to_evaluate(
69 &output[kNumStartupBlocks * kSubBlockSize],
70 (kNumBlocks - kNumStartupBlocks) * kSubBlockSize);
71 *input_power =
72 std::inner_product(input_to_evaluate.begin(), input_to_evaluate.end(),
73 input_to_evaluate.begin(), 0.f) /
74 input_to_evaluate.size();
75 *output_power =
76 std::inner_product(output_to_evaluate.begin(), output_to_evaluate.end(),
77 output_to_evaluate.begin(), 0.f) /
78 output_to_evaluate.size();
79 }
80
81 } // namespace
82
83 // Verifies that there is little aliasing from upper frequencies in the
84 // downsampling.
85 TEST(DecimatorBy4, NoLeakageFromUpperFrequencies) {
86 float input_power;
87 float output_power;
88 for (auto rate : {8000, 16000, 32000, 48000}) {
89 ProduceDebugText(rate);
90 ProduceDecimatedSinusoidalOutputPower(rate, 3.f / 8.f * rate, &input_power,
91 &output_power);
92 EXPECT_GT(0.0001f * input_power, output_power);
93 }
94 }
95
96 // Verifies that the impact of low-frequency content is small during the
97 // downsampling.
98 TEST(DecimatorBy4, NoImpactOnLowerFrequencies) {
99 float input_power;
100 float output_power;
101 for (auto rate : {8000, 16000, 32000, 48000}) {
102 ProduceDebugText(rate);
103 ProduceDecimatedSinusoidalOutputPower(rate, 200.f, &input_power,
104 &output_power);
105 EXPECT_LT(0.7f * input_power, output_power);
106 }
107 }
108
109 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
110 // Verifies the check for the input size.
111 TEST(DecimatorBy4, WrongInputSize) {
112 DecimatorBy4 decimator;
113 std::vector<float> x(std::vector<float>(kBlockSize - 1, 0.f));
114 std::array<float, kSubBlockSize> x_downsampled;
115 EXPECT_DEATH(decimator.Decimate(x, &x_downsampled), "");
116 }
117
118 // Verifies the check for non-null output parameter.
119 TEST(DecimatorBy4, NullOutput) {
120 DecimatorBy4 decimator;
121 std::vector<float> x(std::vector<float>(kBlockSize, 0.f));
122 EXPECT_DEATH(decimator.Decimate(x, nullptr), "");
123 }
124
125 #endif
126
127 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec3/decimator_by_4.cc ('k') | webrtc/modules/audio_processing/aec3/echo_canceller3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698