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

Side by Side Diff: webrtc/audio/utility/audio_frame_operations_unittest.cc

Issue 2712743004: Support 4 channel mic in Windows Core Audio (Closed)
Patch Set: Fix compile error on mac Created 3 years, 9 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/audio/utility/audio_frame_operations.h" 11 #include "webrtc/audio/utility/audio_frame_operations.h"
12 #include "webrtc/base/checks.h" 12 #include "webrtc/base/checks.h"
13 #include "webrtc/modules/include/module_common_types.h" 13 #include "webrtc/modules/include/module_common_types.h"
14 #include "webrtc/test/gtest.h" 14 #include "webrtc/test/gtest.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 namespace { 17 namespace {
18 18
19 class AudioFrameOperationsTest : public ::testing::Test { 19 class AudioFrameOperationsTest : public ::testing::Test {
20 protected: 20 protected:
21 AudioFrameOperationsTest() { 21 AudioFrameOperationsTest() {
22 // Set typical values. 22 // Set typical values.
23 frame_.samples_per_channel_ = 320; 23 frame_.samples_per_channel_ = 320;
24 frame_.num_channels_ = 2; 24 frame_.num_channels_ = 2;
25 } 25 }
26 26
27 AudioFrame frame_; 27 AudioFrame frame_;
28 }; 28 };
29 29
30 void SetFrameData(int16_t ch1,
31 int16_t ch2,
32 int16_t ch3,
33 int16_t ch4,
34 AudioFrame* frame) {
35 for (size_t i = 0; i < frame->samples_per_channel_ * 4; i += 4) {
36 frame->data_[i] = ch1;
37 frame->data_[i + 1] = ch2;
38 frame->data_[i + 2] = ch3;
39 frame->data_[i + 3] = ch4;
40 }
41 }
42
30 void SetFrameData(AudioFrame* frame, int16_t left, int16_t right) { 43 void SetFrameData(AudioFrame* frame, int16_t left, int16_t right) {
31 for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) { 44 for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
32 frame->data_[i] = left; 45 frame->data_[i] = left;
33 frame->data_[i + 1] = right; 46 frame->data_[i + 1] = right;
34 } 47 }
35 } 48 }
36 49
37 void SetFrameData(AudioFrame* frame, int16_t data) { 50 void SetFrameData(AudioFrame* frame, int16_t data) {
38 for (size_t i = 0; i < frame->samples_per_channel_; i++) { 51 for (size_t i = 0; i < frame->samples_per_channel_; i++) {
39 frame->data_[i] = data; 52 frame->data_[i] = data;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 SetFrameData(&frame_, -32768, -32768); 151 SetFrameData(&frame_, -32768, -32768);
139 EXPECT_EQ(0, AudioFrameOperations::StereoToMono(&frame_)); 152 EXPECT_EQ(0, AudioFrameOperations::StereoToMono(&frame_));
140 153
141 AudioFrame mono_frame; 154 AudioFrame mono_frame;
142 mono_frame.samples_per_channel_ = 320; 155 mono_frame.samples_per_channel_ = 320;
143 mono_frame.num_channels_ = 1; 156 mono_frame.num_channels_ = 1;
144 SetFrameData(&mono_frame, -32768); 157 SetFrameData(&mono_frame, -32768);
145 VerifyFramesAreEqual(mono_frame, frame_); 158 VerifyFramesAreEqual(mono_frame, frame_);
146 } 159 }
147 160
161 TEST_F(AudioFrameOperationsTest, QuadToMonoFailsWithBadParameters) {
162 frame_.num_channels_ = 1;
163 EXPECT_EQ(-1, AudioFrameOperations::QuadToMono(&frame_));
164 frame_.num_channels_ = 2;
165 EXPECT_EQ(-1, AudioFrameOperations::QuadToMono(&frame_));
166 }
167
168 TEST_F(AudioFrameOperationsTest, QuadToMonoSucceeds) {
169 frame_.num_channels_ = 4;
170 SetFrameData(4, 2, 6, 8, &frame_);
171 AudioFrame temp_frame;
172 temp_frame.CopyFrom(frame_);
173 EXPECT_EQ(0, AudioFrameOperations::QuadToMono(&frame_));
174
175 AudioFrame mono_frame;
176 mono_frame.samples_per_channel_ = 320;
177 mono_frame.num_channels_ = 1;
178 SetFrameData(&mono_frame, 5);
179 VerifyFramesAreEqual(mono_frame, frame_);
180 }
181
182 TEST_F(AudioFrameOperationsTest, QuadToMonoBufferSucceeds) {
183 AudioFrame target_frame;
184 frame_.num_channels_ = 4;
185 SetFrameData(4, 2, 6, 8, &frame_);
186
187 target_frame.num_channels_ = 1;
188 target_frame.samples_per_channel_ = frame_.samples_per_channel_;
189
190 AudioFrameOperations::QuadToMono(frame_.data_, frame_.samples_per_channel_,
191 target_frame.data_);
192 AudioFrame mono_frame;
193 mono_frame.samples_per_channel_ = 320;
194 mono_frame.num_channels_ = 1;
195 SetFrameData(&mono_frame, 5);
196 VerifyFramesAreEqual(mono_frame, target_frame);
197 }
198
199 TEST_F(AudioFrameOperationsTest, QuadToMonoDoesNotWrapAround) {
200 frame_.num_channels_ = 4;
201 SetFrameData(-32768, -32768, -32768, -32768, &frame_);
202 EXPECT_EQ(0, AudioFrameOperations::QuadToMono(&frame_));
203
204 AudioFrame mono_frame;
205 mono_frame.samples_per_channel_ = 320;
206 mono_frame.num_channels_ = 1;
207 SetFrameData(&mono_frame, -32768);
208 VerifyFramesAreEqual(mono_frame, frame_);
209 }
210
211 TEST_F(AudioFrameOperationsTest, QuadToStereoFailsWithBadParameters) {
212 frame_.num_channels_ = 1;
213 EXPECT_EQ(-1, AudioFrameOperations::QuadToStereo(&frame_));
214 frame_.num_channels_ = 2;
215 EXPECT_EQ(-1, AudioFrameOperations::QuadToStereo(&frame_));
216 }
217
218 TEST_F(AudioFrameOperationsTest, QuadToStereoSucceeds) {
219 frame_.num_channels_ = 4;
220 SetFrameData(4, 2, 6, 8, &frame_);
221 EXPECT_EQ(0, AudioFrameOperations::QuadToStereo(&frame_));
222
223 AudioFrame stereo_frame;
224 stereo_frame.samples_per_channel_ = 320;
225 stereo_frame.num_channels_ = 2;
226 SetFrameData(&stereo_frame, 3, 7);
227 VerifyFramesAreEqual(stereo_frame, frame_);
228 }
229
230 TEST_F(AudioFrameOperationsTest, QuadToStereoBufferSucceeds) {
231 AudioFrame target_frame;
232 frame_.num_channels_ = 4;
233 SetFrameData(4, 2, 6, 8, &frame_);
234
235 target_frame.num_channels_ = 2;
236 target_frame.samples_per_channel_ = frame_.samples_per_channel_;
237
238 AudioFrameOperations::QuadToStereo(frame_.data_, frame_.samples_per_channel_,
239 target_frame.data_);
240 AudioFrame stereo_frame;
241 stereo_frame.samples_per_channel_ = 320;
242 stereo_frame.num_channels_ = 2;
243 SetFrameData(&stereo_frame, 3, 7);
244 VerifyFramesAreEqual(stereo_frame, target_frame);
245 }
246
247 TEST_F(AudioFrameOperationsTest, QuadToStereoDoesNotWrapAround) {
248 frame_.num_channels_ = 4;
249 SetFrameData(-32768, -32768, -32768, -32768, &frame_);
250 EXPECT_EQ(0, AudioFrameOperations::QuadToStereo(&frame_));
251
252 AudioFrame stereo_frame;
253 stereo_frame.samples_per_channel_ = 320;
254 stereo_frame.num_channels_ = 2;
255 SetFrameData(&stereo_frame, -32768, -32768);
256 VerifyFramesAreEqual(stereo_frame, frame_);
257 }
258
148 TEST_F(AudioFrameOperationsTest, SwapStereoChannelsSucceedsOnStereo) { 259 TEST_F(AudioFrameOperationsTest, SwapStereoChannelsSucceedsOnStereo) {
149 SetFrameData(&frame_, 0, 1); 260 SetFrameData(&frame_, 0, 1);
150 261
151 AudioFrame swapped_frame; 262 AudioFrame swapped_frame;
152 swapped_frame.samples_per_channel_ = 320; 263 swapped_frame.samples_per_channel_ = 320;
153 swapped_frame.num_channels_ = 2; 264 swapped_frame.num_channels_ = 2;
154 SetFrameData(&swapped_frame, 1, 0); 265 SetFrameData(&swapped_frame, 1, 0);
155 266
156 AudioFrameOperations::SwapStereoChannels(&frame_); 267 AudioFrameOperations::SwapStereoChannels(&frame_);
157 VerifyFramesAreEqual(swapped_frame, frame_); 268 VerifyFramesAreEqual(swapped_frame, frame_);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 frame_to_add_to.samples_per_channel_ = frame_.samples_per_channel_; 491 frame_to_add_to.samples_per_channel_ = frame_.samples_per_channel_;
381 frame_to_add_to.num_channels_ = frame_.num_channels_; 492 frame_to_add_to.num_channels_ = frame_.num_channels_;
382 SetFrameData(&frame_to_add_to, 1000); 493 SetFrameData(&frame_to_add_to, 1000);
383 494
384 AudioFrameOperations::Add(frame_, &frame_to_add_to); 495 AudioFrameOperations::Add(frame_, &frame_to_add_to);
385 SetFrameData(&frame_, frame_.data_[0] + 1000); 496 SetFrameData(&frame_, frame_.data_[0] + 1000);
386 VerifyFramesAreEqual(frame_, frame_to_add_to); 497 VerifyFramesAreEqual(frame_, frame_to_add_to);
387 } 498 }
388 } // namespace 499 } // namespace
389 } // namespace webrtc 500 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698