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

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: Change ProcessStream interface 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, DownmixInterleavedToMono) {
122 {
123 const int kNumMultichannelFrames = 4;
Andrew MacDonald 2015/07/22 22:47:21 Same here (and possibly elsewhere?) kNumFrames or
mgraczyk 2015/07/23 00:16:54 Done.
124 const int kNumChannels = 1;
125 const int16_t interleaved[kNumChannels * kNumMultichannelFrames] = {1, 2,
126 -1, -3};
127 int16_t deinterleaved[kNumMultichannelFrames];
128
129 DownmixInterleavedToMono(interleaved, kNumMultichannelFrames, kNumChannels,
130 deinterleaved);
131
132 EXPECT_THAT(deinterleaved, ElementsAreArray(interleaved));
133 }
134 {
135 const int kNumMultichannelFrames = 2;
136 const int kNumChannels = 2;
137 const int16_t interleaved[kNumChannels * kNumMultichannelFrames] = {
138 10, 20, -10, -30};
139 int16_t deinterleaved[kNumMultichannelFrames];
140
141 DownmixInterleavedToMono(interleaved, kNumMultichannelFrames, kNumChannels,
142 deinterleaved);
143 const int16_t expected[kNumMultichannelFrames] = {15, -20};
144
145 EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
146 }
147 {
148 const int kNumMultichannelFrames = 3;
149 const int kNumChannels = 3;
150 const int16_t interleaved[kNumChannels * kNumMultichannelFrames] = {
151 30000, 30000, 24001, -5, -10, -20, -30000, -30999, -30000};
152 int16_t deinterleaved[kNumMultichannelFrames];
153
154 DownmixInterleavedToMono(interleaved, kNumMultichannelFrames, kNumChannels,
155 deinterleaved);
156 const int16_t expected[kNumMultichannelFrames] = {28000, -11, -30333};
157
158 EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
159 }
160 }
161
162 TEST(AudioUtilTest, DownmixToMonoTest) {
163 {
164 const int kNumMultichannelFrames = 4;
165 const int kNumChannels = 1;
166 const float input_data[kNumChannels][kNumMultichannelFrames] = {
167 {1.f, 2.f, -1.f, -3.f}};
168 const float* input[kNumChannels];
169 for (int i = 0; i < kNumChannels; ++i) {
170 input[i] = input_data[i];
171 }
172
173 float downmixed[kNumMultichannelFrames];
174
175 DownmixToMono<float, float>(input, kNumMultichannelFrames, kNumChannels,
176 downmixed);
177
178 EXPECT_THAT(downmixed, ElementsAreArray(input_data[0]));
179 }
180 {
181 const int kNumMultichannelFrames = 3;
182 const int kNumChannels = 2;
183 const float input_data[kNumChannels][kNumMultichannelFrames] = {
184 {1.f, 2.f, -1.f}, {3.f, 0.f, 1.f}};
185 const float* input[kNumChannels];
186 for (int i = 0; i < kNumChannels; ++i) {
187 input[i] = input_data[i];
188 }
189
190 float downmixed[kNumMultichannelFrames];
191 const float expected[kNumMultichannelFrames] = {2.f, 1.f, 0.f};
192
193 DownmixToMono<float, float>(input, kNumMultichannelFrames, kNumChannels,
194 downmixed);
195
196 EXPECT_THAT(downmixed, ElementsAreArray(expected));
197 }
198 {
199 const int kNumMultichannelFrames = 3;
200 const int kNumChannels = 3;
201 const int16_t input_data[kNumChannels][kNumMultichannelFrames] = {
202 {30000, -5, -30000}, {30000, -10, -30999}, {24001, -20, -30000}};
203 const int16_t* input[kNumChannels];
204 for (int i = 0; i < kNumChannels; ++i) {
205 input[i] = input_data[i];
206 }
207
208 int16_t downmixed[kNumMultichannelFrames];
209 const int16_t expected[kNumMultichannelFrames] = {28000, -11, -30333};
210
211 DownmixToMono<int16_t, int32_t>(input, kNumMultichannelFrames, kNumChannels,
212 downmixed);
Andrew MacDonald 2015/07/22 22:47:21 Indentation doesn't look right. Run clang-format.
mgraczyk 2015/07/23 00:16:54 Done.
213
214 EXPECT_THAT(downmixed, ElementsAreArray(expected));
215 }
216 }
217
218 } // namespace
117 } // namespace webrtc 219 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698