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

Side by Side Diff: webrtc/modules/audio_processing/utility/lapped_transform_unittest.cc

Issue 1846903004: Moved ring-buffer related files from common_audio to audio_processing (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected order of includes Created 4 years, 8 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/lapped_transform.h" 11 #include "webrtc/modules/audio_processing/utility/lapped_transform.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <cmath> 14 #include <cmath>
15 #include <cstring> 15 #include <cstring>
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using std::complex; 19 using std::complex;
20 20
21 namespace { 21 namespace {
22 22
23 class NoopCallback : public webrtc::LappedTransform::Callback { 23 class NoopCallback : public webrtc::LappedTransform::Callback {
24 public: 24 public:
25 NoopCallback() : block_num_(0) {} 25 NoopCallback() : block_num_(0) {}
26 26
27 virtual void ProcessAudioBlock(const complex<float>* const* in_block, 27 virtual void ProcessAudioBlock(const complex<float>* const* in_block,
28 size_t in_channels, 28 size_t in_channels,
29 size_t frames, 29 size_t frames,
30 size_t out_channels, 30 size_t out_channels,
31 complex<float>* const* out_block) { 31 complex<float>* const* out_block) {
32 RTC_CHECK_EQ(in_channels, out_channels); 32 RTC_CHECK_EQ(in_channels, out_channels);
33 for (size_t i = 0; i < out_channels; ++i) { 33 for (size_t i = 0; i < out_channels; ++i) {
34 memcpy(out_block[i], in_block[i], sizeof(**in_block) * frames); 34 memcpy(out_block[i], in_block[i], sizeof(**in_block) * frames);
35 } 35 }
36 ++block_num_; 36 ++block_num_;
37 } 37 }
38 38
39 size_t block_num() { 39 size_t block_num() { return block_num_; }
40 return block_num_;
41 }
42 40
43 private: 41 private:
44 size_t block_num_; 42 size_t block_num_;
45 }; 43 };
46 44
47 class FftCheckerCallback : public webrtc::LappedTransform::Callback { 45 class FftCheckerCallback : public webrtc::LappedTransform::Callback {
48 public: 46 public:
49 FftCheckerCallback() : block_num_(0) {} 47 FftCheckerCallback() : block_num_(0) {}
50 48
51 virtual void ProcessAudioBlock(const complex<float>* const* in_block, 49 virtual void ProcessAudioBlock(const complex<float>* const* in_block,
(...skipping 10 matching lines...) Expand all
62 ASSERT_NEAR(in_block[0][0].real(), static_cast<float>(full_length), 60 ASSERT_NEAR(in_block[0][0].real(), static_cast<float>(full_length),
63 1e-5f); 61 1e-5f);
64 ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f); 62 ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f);
65 for (size_t i = 1; i < frames; ++i) { 63 for (size_t i = 1; i < frames; ++i) {
66 ASSERT_NEAR(in_block[0][i].real(), 0.0f, 1e-5f); 64 ASSERT_NEAR(in_block[0][i].real(), 0.0f, 1e-5f);
67 ASSERT_NEAR(in_block[0][i].imag(), 0.0f, 1e-5f); 65 ASSERT_NEAR(in_block[0][i].imag(), 0.0f, 1e-5f);
68 } 66 }
69 } 67 }
70 } 68 }
71 69
72 size_t block_num() { 70 size_t block_num() { return block_num_; }
73 return block_num_;
74 }
75 71
76 private: 72 private:
77 size_t block_num_; 73 size_t block_num_;
78 }; 74 };
79 75
80 void SetFloatArray(float value, int rows, int cols, float* const* array) { 76 void SetFloatArray(float value, int rows, int cols, float* const* array) {
81 for (int i = 0; i < rows; ++i) { 77 for (int i = 0; i < rows; ++i) {
82 for (int j = 0; j < cols; ++j) { 78 for (int j = 0; j < cols; ++j) {
83 array[i][j] = value; 79 array[i][j] = value;
84 } 80 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 float* in_chunk = in_buffer; 139 float* in_chunk = in_buffer;
144 float out_buffer[kChunkLength]; 140 float out_buffer[kChunkLength];
145 float* out_chunk = out_buffer; 141 float* out_chunk = out_buffer;
146 142
147 SetFloatArray(2.0f, 1, kChunkLength, &in_chunk); 143 SetFloatArray(2.0f, 1, kChunkLength, &in_chunk);
148 SetFloatArray(-1.0f, 1, kChunkLength, &out_chunk); 144 SetFloatArray(-1.0f, 1, kChunkLength, &out_chunk);
149 145
150 trans.ProcessChunk(&in_chunk, &out_chunk); 146 trans.ProcessChunk(&in_chunk, &out_chunk);
151 147
152 for (size_t i = 0; i < kChunkLength; ++i) { 148 for (size_t i = 0; i < kChunkLength; ++i) {
153 ASSERT_NEAR(out_chunk[i], 149 ASSERT_NEAR(out_chunk[i], (i < kBlockLength - kShiftAmount) ? 0.0f : 2.0f,
154 (i < kBlockLength - kShiftAmount) ? 0.0f : 2.0f,
155 1e-5f); 150 1e-5f);
156 } 151 }
157 152
158 ASSERT_EQ(kChunkLength / kShiftAmount, noop.block_num()); 153 ASSERT_EQ(kChunkLength / kShiftAmount, noop.block_num());
159 } 154 }
160 155
161 TEST(LappedTransformTest, Callbacks) { 156 TEST(LappedTransformTest, Callbacks) {
162 const size_t kChunkLength = 512; 157 const size_t kChunkLength = 512;
163 const size_t kBlockLength = 64; 158 const size_t kBlockLength = 64;
164 FftCheckerCallback call; 159 FftCheckerCallback call;
165 160
166 // Rectangular window. 161 // Rectangular window.
167 float window[kBlockLength]; 162 float window[kBlockLength];
168 std::fill(window, &window[kBlockLength], 1.0f); 163 std::fill(window, &window[kBlockLength], 1.0f);
169 164
170 LappedTransform trans(1, 1, kChunkLength, window, kBlockLength, 165 LappedTransform trans(1, 1, kChunkLength, window, kBlockLength, kBlockLength,
171 kBlockLength, &call); 166 &call);
172 float in_buffer[kChunkLength]; 167 float in_buffer[kChunkLength];
173 float* in_chunk = in_buffer; 168 float* in_chunk = in_buffer;
174 float out_buffer[kChunkLength]; 169 float out_buffer[kChunkLength];
175 float* out_chunk = out_buffer; 170 float* out_chunk = out_buffer;
176 171
177 SetFloatArray(1.0f, 1, kChunkLength, &in_chunk); 172 SetFloatArray(1.0f, 1, kChunkLength, &in_chunk);
178 SetFloatArray(-1.0f, 1, kChunkLength, &out_chunk); 173 SetFloatArray(-1.0f, 1, kChunkLength, &out_chunk);
179 174
180 trans.ProcessChunk(&in_chunk, &out_chunk); 175 trans.ProcessChunk(&in_chunk, &out_chunk);
181 176
(...skipping 17 matching lines...) Expand all
199 { 194 {
200 const size_t kExpectedChunkLength = 160; 195 const size_t kExpectedChunkLength = 160;
201 const LappedTransform trans(1, 1, kExpectedChunkLength, window, 196 const LappedTransform trans(1, 1, kExpectedChunkLength, window,
202 kBlockLength, kBlockLength, &call); 197 kBlockLength, kBlockLength, &call);
203 198
204 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); 199 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length());
205 } 200 }
206 } 201 }
207 202
208 } // namespace webrtc 203 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698