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

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

Issue 1226093007: Allow more than 2 input channels in AudioProcessing. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address Comments Created 5 years, 5 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/common_audio/include/audio_util.h" 13 #include "webrtc/common_audio/include/audio_util.h"
13 #include "webrtc/typedefs.h" 14 #include "webrtc/typedefs.h"
14 15
15 namespace webrtc { 16 namespace webrtc {
17 namespace {
18
19 using ::testing::ElementsAreArray;
16 20
17 void ExpectArraysEq(const int16_t* ref, const int16_t* test, int length) { 21 void ExpectArraysEq(const int16_t* ref, const int16_t* test, int length) {
18 for (int i = 0; i < length; ++i) { 22 for (int i = 0; i < length; ++i) {
19 EXPECT_EQ(ref[i], test[i]); 23 EXPECT_EQ(ref[i], test[i]);
20 } 24 }
21 } 25 }
22 26
23 void ExpectArraysEq(const float* ref, const float* test, int length) { 27 void ExpectArraysEq(const float* ref, const float* test, int length) {
24 for (int i = 0; i < length; ++i) { 28 for (int i = 0; i < length; ++i) {
25 EXPECT_FLOAT_EQ(ref[i], test[i]); 29 EXPECT_FLOAT_EQ(ref[i], test[i]);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 int16_t mono[kSamplesPerChannel]; 111 int16_t mono[kSamplesPerChannel];
108 int16_t* deinterleaved[] = {mono}; 112 int16_t* deinterleaved[] = {mono};
109 Deinterleave(kInterleaved, kSamplesPerChannel, kNumChannels, deinterleaved); 113 Deinterleave(kInterleaved, kSamplesPerChannel, kNumChannels, deinterleaved);
110 ExpectArraysEq(kInterleaved, mono, kSamplesPerChannel); 114 ExpectArraysEq(kInterleaved, mono, kSamplesPerChannel);
111 115
112 int16_t interleaved[kSamplesPerChannel]; 116 int16_t interleaved[kSamplesPerChannel];
113 Interleave(deinterleaved, kSamplesPerChannel, kNumChannels, interleaved); 117 Interleave(deinterleaved, kSamplesPerChannel, kNumChannels, interleaved);
114 ExpectArraysEq(mono, interleaved, kSamplesPerChannel); 118 ExpectArraysEq(mono, interleaved, kSamplesPerChannel);
115 } 119 }
116 120
121 TEST(AudioUtilTest, DownmixInterleavedToMonoImpl) {
122 {
123 const int kNumMultichannelFrames = 4;
124 const int kNumChannels = 1;
125 const float interleaved[kNumChannels * kNumMultichannelFrames] = {
126 1.f, 2.f, -1.f, -3.f};
127 float deinterleaved[kNumMultichannelFrames];
128
129 DownmixInterleavedToMonoImpl<float, float>(
130 interleaved, kNumMultichannelFrames, kNumChannels, deinterleaved);
131
132 EXPECT_THAT(deinterleaved, ElementsAreArray(interleaved));
133 }
134 {
135 const int kNumMultichannelFrames = 2;
136 const int kNumChannels = 2;
137 const float interleaved[kNumChannels * kNumMultichannelFrames] = {
138 1.f, 2.f, -1.f, -3.f};
139 float deinterleaved[kNumMultichannelFrames];
140
141 DownmixInterleavedToMonoImpl<float, float>(
142 interleaved, kNumMultichannelFrames, kNumChannels, deinterleaved);
143 const float expected[kNumMultichannelFrames] = {1.5f, -2.f};
144
145 EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
146 }
147 {
148 const int kNumMultichannelFrames = 2;
149 const int kNumChannels = 3;
150 const float interleaved[kNumChannels * kNumMultichannelFrames] = {
151 1.f, 2.f, 3.f, -1.f, -3.f, 7.f};
152 float deinterleaved[kNumMultichannelFrames];
153
154 DownmixInterleavedToMonoImpl<float, float>(
155 interleaved, kNumMultichannelFrames, kNumChannels, deinterleaved);
156 const float expected[kNumMultichannelFrames] = {2.f, 1.f};
157
158 EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
159 }
160 {
161 const int kNumMultichannelFrames = 2;
162 const int kNumChannels = 2;
163 const int16_t interleaved[kNumChannels * kNumMultichannelFrames] = {
164 10, 20, -10, -30};
165 int16_t deinterleaved[kNumMultichannelFrames];
166
167 DownmixInterleavedToMonoImpl<int16_t, int32_t>(
168 interleaved, kNumMultichannelFrames, kNumChannels, deinterleaved);
169 const int16_t expected[kNumMultichannelFrames] = {15, -20};
170
171 EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
172 }
173 {
174 const int kNumMultichannelFrames = 3;
175 const int kNumChannels = 3;
176 const int16_t interleaved[kNumChannels * kNumMultichannelFrames] = {
177 30000, 30000, 24001, -5, -10, -20, -30000, -30999, -30000};
178 int16_t deinterleaved[kNumMultichannelFrames];
179
180 DownmixInterleavedToMonoImpl<int16_t, int32_t>(
181 interleaved, kNumMultichannelFrames, kNumChannels, deinterleaved);
182 const int16_t expected[kNumMultichannelFrames] = {28000, -11, -30333};
183
184 EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
185 }
186 }
187
188 TEST(AudioUtilTest, DownmixToMonoTest) {
189 {
190 const int kNumMultichannelFrames = 4;
191 const int kNumChannels = 1;
192 const float input_data[kNumChannels][kNumMultichannelFrames] = {
193 {1.f, 2.f, -1.f, -3.f}};
194 const float* input[kNumChannels];
195 for (int i = 0; i < kNumChannels; ++i) {
196 input[i] = input_data[i];
197 }
198
199 float downmixed[kNumMultichannelFrames];
200
201 DownmixToMono<float, float>(input, kNumMultichannelFrames, kNumChannels,
202 downmixed);
203
204 EXPECT_THAT(downmixed, ElementsAreArray(input_data[0]));
205 }
206 {
207 const int kNumMultichannelFrames = 3;
208 const int kNumChannels = 2;
209 const float input_data[kNumChannels][kNumMultichannelFrames] = {
210 {1.f, 2.f, -1.f}, {3.f, 0.f, 1.f}};
211 const float* input[kNumChannels];
212 for (int i = 0; i < kNumChannels; ++i) {
213 input[i] = input_data[i];
214 }
215
216 float downmixed[kNumMultichannelFrames];
217 const float expected[kNumMultichannelFrames] = {2.f, 1.f, 0.f};
218
219 DownmixToMono<float, float>(input, kNumMultichannelFrames, kNumChannels,
220 downmixed);
221
222 EXPECT_THAT(downmixed, ElementsAreArray(expected));
223 }
224 {
225 const int kNumMultichannelFrames = 3;
226 const int kNumChannels = 3;
227 const int16_t input_data[kNumChannels][kNumMultichannelFrames] = {
228 {30000, -5, -30000}, {30000, -10, -30999}, {24001, -20, -30000}};
229 const int16_t* input[kNumChannels];
230 for (int i = 0; i < kNumChannels; ++i) {
231 input[i] = input_data[i];
232 }
233
234 int16_t downmixed[kNumMultichannelFrames];
235 const int16_t expected[kNumMultichannelFrames] = {28000, -11, -30333};
236
237 DownmixToMono<int16_t, int32_t>(input, kNumMultichannelFrames, kNumChannels,
238 downmixed);
239
240 EXPECT_THAT(downmixed, ElementsAreArray(expected));
241 }
242 }
243
244 } // namespace
117 } // namespace webrtc 245 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698