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

Side by Side Diff: webrtc/common_audio/blocker_unittest.cc

Issue 1534193008: Misc. small cleanups (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Unnecessary parens Created 4 years, 11 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
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/common_audio/blocker.h" 11 #include "webrtc/common_audio/blocker.h"
12 12
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/base/arraysize.h"
14 15
15 namespace { 16 namespace {
16 17
17 // Callback Function to add 3 to every sample in the signal. 18 // Callback Function to add 3 to every sample in the signal.
18 class PlusThreeBlockerCallback : public webrtc::BlockerCallback { 19 class PlusThreeBlockerCallback : public webrtc::BlockerCallback {
19 public: 20 public:
20 void ProcessBlock(const float* const* input, 21 void ProcessBlock(const float* const* input,
21 size_t num_frames, 22 size_t num_frames,
22 int num_input_channels, 23 int num_input_channels,
23 int num_output_channels, 24 int num_output_channels,
(...skipping 25 matching lines...) Expand all
49 } // namespace 50 } // namespace
50 51
51 namespace webrtc { 52 namespace webrtc {
52 53
53 // Tests blocking with a window that multiplies the signal by 2, a callback 54 // Tests blocking with a window that multiplies the signal by 2, a callback
54 // that adds 3 to each sample in the signal, and different combinations of chunk 55 // that adds 3 to each sample in the signal, and different combinations of chunk
55 // size, block size, and shift amount. 56 // size, block size, and shift amount.
56 class BlockerTest : public ::testing::Test { 57 class BlockerTest : public ::testing::Test {
57 protected: 58 protected:
58 void RunTest(Blocker* blocker, 59 void RunTest(Blocker* blocker,
59 int chunk_size, 60 size_t chunk_size,
60 int num_frames, 61 size_t num_frames,
61 const float* const* input, 62 const float* const* input,
62 float* const* input_chunk, 63 float* const* input_chunk,
63 float* const* output, 64 float* const* output,
64 float* const* output_chunk, 65 float* const* output_chunk,
65 int num_input_channels, 66 int num_input_channels,
66 int num_output_channels) { 67 int num_output_channels) {
67 int start = 0; 68 size_t start = 0;
68 int end = chunk_size - 1; 69 size_t end = chunk_size - 1;
69 while (end < num_frames) { 70 while (end < num_frames) {
70 CopyTo(input_chunk, 0, start, num_input_channels, chunk_size, input); 71 CopyTo(input_chunk, 0, start, num_input_channels, chunk_size, input);
71 blocker->ProcessChunk(input_chunk, 72 blocker->ProcessChunk(input_chunk,
72 chunk_size, 73 chunk_size,
73 num_input_channels, 74 num_input_channels,
74 num_output_channels, 75 num_output_channels,
75 output_chunk); 76 output_chunk);
76 CopyTo(output, start, 0, num_output_channels, chunk_size, output_chunk); 77 CopyTo(output, start, 0, num_output_channels, chunk_size, output_chunk);
77 78
78 start = start + chunk_size; 79 start += chunk_size;
79 end = end + chunk_size; 80 end += chunk_size;
80 } 81 }
81 } 82 }
82 83
83 void ValidateSignalEquality(const float* const* expected, 84 void ValidateSignalEquality(const float* const* expected,
84 const float* const* actual, 85 const float* const* actual,
85 int num_channels, 86 int num_channels,
86 int num_frames) { 87 size_t num_frames) {
87 for (int i = 0; i < num_channels; ++i) { 88 for (int i = 0; i < num_channels; ++i) {
88 for (int j = 0; j < num_frames; ++j) { 89 for (size_t j = 0; j < num_frames; ++j) {
89 EXPECT_FLOAT_EQ(expected[i][j], actual[i][j]); 90 EXPECT_FLOAT_EQ(expected[i][j], actual[i][j]);
90 } 91 }
91 } 92 }
92 } 93 }
93 94
94 void ValidateInitialDelay(const float* const* output, 95 void ValidateInitialDelay(const float* const* output,
95 int num_channels, 96 int num_channels,
96 int num_frames, 97 size_t num_frames,
97 int initial_delay) { 98 size_t initial_delay) {
98 for (int i = 0; i < num_channels; ++i) { 99 for (int i = 0; i < num_channels; ++i) {
99 for (int j = 0; j < num_frames; ++j) { 100 for (size_t j = 0; j < num_frames; ++j) {
100 if (j < initial_delay) { 101 if (j < initial_delay) {
101 EXPECT_FLOAT_EQ(output[i][j], 0.f); 102 EXPECT_FLOAT_EQ(output[i][j], 0.f);
102 } else { 103 } else {
103 EXPECT_GT(output[i][j], 0.f); 104 EXPECT_GT(output[i][j], 0.f);
104 } 105 }
105 } 106 }
106 } 107 }
107 } 108 }
108 109
109 static void CopyTo(float* const* dst, 110 static void CopyTo(float* const* dst,
110 int start_index_dst, 111 size_t start_index_dst,
111 int start_index_src, 112 size_t start_index_src,
112 int num_channels, 113 int num_channels,
113 int num_frames, 114 size_t num_frames,
114 const float* const* src) { 115 const float* const* src) {
115 for (int i = 0; i < num_channels; ++i) { 116 for (int i = 0; i < num_channels; ++i) {
116 memcpy(&dst[i][start_index_dst], 117 memcpy(&dst[i][start_index_dst],
117 &src[i][start_index_src], 118 &src[i][start_index_src],
118 num_frames * sizeof(float)); 119 num_frames * sizeof(float));
119 } 120 }
120 } 121 }
121 }; 122 };
122 123
123 TEST_F(BlockerTest, TestBlockerMutuallyPrimeChunkandBlockSize) { 124 TEST_F(BlockerTest, TestBlockerMutuallyPrimeChunkandBlockSize) {
124 const int kNumInputChannels = 3; 125 const int kNumInputChannels = 3;
125 const int kNumOutputChannels = 2; 126 const int kNumOutputChannels = 2;
126 const int kNumFrames = 10; 127 const size_t kNumFrames = 10;
127 const int kBlockSize = 4; 128 const size_t kBlockSize = 4;
128 const int kChunkSize = 5; 129 const size_t kChunkSize = 5;
129 const int kShiftAmount = 2; 130 const size_t kShiftAmount = 2;
130 131
131 const float kInput[kNumInputChannels][kNumFrames] = { 132 const float kInput[kNumInputChannels][kNumFrames] = {
132 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 133 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
133 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 134 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
134 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}}; 135 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}};
135 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels); 136 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels);
136 input_cb.SetDataForTesting(kInput[0], sizeof(kInput) / sizeof(**kInput)); 137 input_cb.SetDataForTesting(kInput[0], sizeof(kInput) / sizeof(**kInput));
137 138
138 const float kExpectedOutput[kNumInputChannels][kNumFrames] = { 139 const float kExpectedOutput[kNumInputChannels][kNumFrames] = {
139 {6, 6, 12, 20, 20, 20, 20, 20, 20, 20}, 140 {6, 6, 12, 20, 20, 20, 20, 20, 20, 20},
(...skipping 29 matching lines...) Expand all
169 170
170 ValidateSignalEquality(expected_output_cb.channels(), 171 ValidateSignalEquality(expected_output_cb.channels(),
171 actual_output_cb.channels(), 172 actual_output_cb.channels(),
172 kNumOutputChannels, 173 kNumOutputChannels,
173 kNumFrames); 174 kNumFrames);
174 } 175 }
175 176
176 TEST_F(BlockerTest, TestBlockerMutuallyPrimeShiftAndBlockSize) { 177 TEST_F(BlockerTest, TestBlockerMutuallyPrimeShiftAndBlockSize) {
177 const int kNumInputChannels = 3; 178 const int kNumInputChannels = 3;
178 const int kNumOutputChannels = 2; 179 const int kNumOutputChannels = 2;
179 const int kNumFrames = 12; 180 const size_t kNumFrames = 12;
180 const int kBlockSize = 4; 181 const size_t kBlockSize = 4;
181 const int kChunkSize = 6; 182 const size_t kChunkSize = 6;
182 const int kShiftAmount = 3; 183 const size_t kShiftAmount = 3;
183 184
184 const float kInput[kNumInputChannels][kNumFrames] = { 185 const float kInput[kNumInputChannels][kNumFrames] = {
185 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 186 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
186 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 187 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
187 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}}; 188 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}};
188 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels); 189 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels);
189 input_cb.SetDataForTesting(kInput[0], sizeof(kInput) / sizeof(**kInput)); 190 input_cb.SetDataForTesting(kInput[0], sizeof(kInput) / sizeof(**kInput));
190 191
191 const float kExpectedOutput[kNumOutputChannels][kNumFrames] = { 192 const float kExpectedOutput[kNumOutputChannels][kNumFrames] = {
192 {6, 10, 10, 20, 10, 10, 20, 10, 10, 20, 10, 10}, 193 {6, 10, 10, 20, 10, 10, 20, 10, 10, 20, 10, 10},
(...skipping 29 matching lines...) Expand all
222 223
223 ValidateSignalEquality(expected_output_cb.channels(), 224 ValidateSignalEquality(expected_output_cb.channels(),
224 actual_output_cb.channels(), 225 actual_output_cb.channels(),
225 kNumOutputChannels, 226 kNumOutputChannels,
226 kNumFrames); 227 kNumFrames);
227 } 228 }
228 229
229 TEST_F(BlockerTest, TestBlockerNoOverlap) { 230 TEST_F(BlockerTest, TestBlockerNoOverlap) {
230 const int kNumInputChannels = 3; 231 const int kNumInputChannels = 3;
231 const int kNumOutputChannels = 2; 232 const int kNumOutputChannels = 2;
232 const int kNumFrames = 12; 233 const size_t kNumFrames = 12;
233 const int kBlockSize = 4; 234 const size_t kBlockSize = 4;
234 const int kChunkSize = 4; 235 const size_t kChunkSize = 4;
235 const int kShiftAmount = 4; 236 const size_t kShiftAmount = 4;
236 237
237 const float kInput[kNumInputChannels][kNumFrames] = { 238 const float kInput[kNumInputChannels][kNumFrames] = {
238 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 239 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
239 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 240 {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
240 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}}; 241 {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}};
241 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels); 242 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels);
242 input_cb.SetDataForTesting(kInput[0], sizeof(kInput) / sizeof(**kInput)); 243 input_cb.SetDataForTesting(kInput[0], sizeof(kInput) / sizeof(**kInput));
243 244
244 const float kExpectedOutput[kNumOutputChannels][kNumFrames] = { 245 const float kExpectedOutput[kNumOutputChannels][kNumFrames] = {
245 {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 246 {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
(...skipping 29 matching lines...) Expand all
275 276
276 ValidateSignalEquality(expected_output_cb.channels(), 277 ValidateSignalEquality(expected_output_cb.channels(),
277 actual_output_cb.channels(), 278 actual_output_cb.channels(),
278 kNumOutputChannels, 279 kNumOutputChannels,
279 kNumFrames); 280 kNumFrames);
280 } 281 }
281 282
282 TEST_F(BlockerTest, InitialDelaysAreMinimum) { 283 TEST_F(BlockerTest, InitialDelaysAreMinimum) {
283 const int kNumInputChannels = 3; 284 const int kNumInputChannels = 3;
284 const int kNumOutputChannels = 2; 285 const int kNumOutputChannels = 2;
285 const int kNumFrames = 1280; 286 const size_t kNumFrames = 1280;
286 const int kChunkSize[] = 287 const size_t kChunkSize[] =
287 {80, 80, 80, 80, 80, 80, 160, 160, 160, 160, 160, 160}; 288 {80, 80, 80, 80, 80, 80, 160, 160, 160, 160, 160, 160};
288 const int kBlockSize[] = 289 const size_t kBlockSize[] =
289 {64, 64, 64, 128, 128, 128, 128, 128, 128, 256, 256, 256}; 290 {64, 64, 64, 128, 128, 128, 128, 128, 128, 256, 256, 256};
290 const int kShiftAmount[] = 291 const size_t kShiftAmount[] =
291 {16, 32, 64, 32, 64, 128, 32, 64, 128, 64, 128, 256}; 292 {16, 32, 64, 32, 64, 128, 32, 64, 128, 64, 128, 256};
292 const int kInitialDelay[] = 293 const size_t kInitialDelay[] =
293 {48, 48, 48, 112, 112, 112, 96, 96, 96, 224, 224, 224}; 294 {48, 48, 48, 112, 112, 112, 96, 96, 96, 224, 224, 224};
294 295
295 float input[kNumInputChannels][kNumFrames]; 296 float input[kNumInputChannels][kNumFrames];
296 for (int i = 0; i < kNumInputChannels; ++i) { 297 for (int i = 0; i < kNumInputChannels; ++i) {
297 for (int j = 0; j < kNumFrames; ++j) { 298 for (size_t j = 0; j < kNumFrames; ++j) {
298 input[i][j] = i + 1; 299 input[i][j] = i + 1;
299 } 300 }
300 } 301 }
301 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels); 302 ChannelBuffer<float> input_cb(kNumFrames, kNumInputChannels);
302 input_cb.SetDataForTesting(input[0], sizeof(input) / sizeof(**input)); 303 input_cb.SetDataForTesting(input[0], sizeof(input) / sizeof(**input));
303 304
304 ChannelBuffer<float> output_cb(kNumFrames, kNumOutputChannels); 305 ChannelBuffer<float> output_cb(kNumFrames, kNumOutputChannels);
305 306
306 CopyBlockerCallback callback; 307 CopyBlockerCallback callback;
307 308
308 for (size_t i = 0; i < (sizeof(kChunkSize) / sizeof(*kChunkSize)); ++i) { 309 for (size_t i = 0; i < arraysize(kChunkSize); ++i) {
309 rtc::scoped_ptr<float[]> window(new float[kBlockSize[i]]); 310 rtc::scoped_ptr<float[]> window(new float[kBlockSize[i]]);
310 for (int j = 0; j < kBlockSize[i]; ++j) { 311 for (size_t j = 0; j < kBlockSize[i]; ++j) {
311 window[j] = 1.f; 312 window[j] = 1.f;
312 } 313 }
313 314
314 ChannelBuffer<float> input_chunk_cb(kChunkSize[i], kNumInputChannels); 315 ChannelBuffer<float> input_chunk_cb(kChunkSize[i], kNumInputChannels);
315 ChannelBuffer<float> output_chunk_cb(kChunkSize[i], kNumOutputChannels); 316 ChannelBuffer<float> output_chunk_cb(kChunkSize[i], kNumOutputChannels);
316 317
317 Blocker blocker(kChunkSize[i], 318 Blocker blocker(kChunkSize[i],
318 kBlockSize[i], 319 kBlockSize[i],
319 kNumInputChannels, 320 kNumInputChannels,
320 kNumOutputChannels, 321 kNumOutputChannels,
(...skipping 12 matching lines...) Expand all
333 kNumOutputChannels); 334 kNumOutputChannels);
334 335
335 ValidateInitialDelay(output_cb.channels(), 336 ValidateInitialDelay(output_cb.channels(),
336 kNumOutputChannels, 337 kNumOutputChannels,
337 kNumFrames, 338 kNumFrames,
338 kInitialDelay[i]); 339 kInitialDelay[i]);
339 } 340 }
340 } 341 }
341 342
342 } // namespace webrtc 343 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/audio_converter_unittest.cc ('k') | webrtc/common_audio/lapped_transform_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698