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

Side by Side Diff: media/base/audio_bus_unittest.cc

Issue 1769373003: AudioBus: Add a ToInterleavedFloat() method to AudioBus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 0, INT8_MAX / 2 + 128, INT8_MIN / 2 + 128, 258 0, INT8_MAX / 2 + 128, INT8_MIN / 2 + 128,
259 -INT8_MIN, UINT8_MAX, -INT8_MIN, 259 -INT8_MIN, UINT8_MAX, -INT8_MIN,
260 -INT8_MIN}; 260 -INT8_MIN};
261 static const int16_t kTestVectorInt16[kTestVectorSize] = { 261 static const int16_t kTestVectorInt16[kTestVectorSize] = {
262 INT16_MIN, 0, INT16_MAX, INT16_MIN, INT16_MAX / 2, 262 INT16_MIN, 0, INT16_MAX, INT16_MIN, INT16_MAX / 2,
263 INT16_MIN / 2, 0, INT16_MAX, 0, 0}; 263 INT16_MIN / 2, 0, INT16_MAX, 0, 0};
264 static const int32_t kTestVectorInt32[kTestVectorSize] = { 264 static const int32_t kTestVectorInt32[kTestVectorSize] = {
265 INT32_MIN, 0, INT32_MAX, INT32_MIN, INT32_MAX / 2, 265 INT32_MIN, 0, INT32_MAX, INT32_MIN, INT32_MAX / 2,
266 INT32_MIN / 2, 0, INT32_MAX, 0, 0}; 266 INT32_MIN / 2, 0, INT32_MAX, 0, 0};
267 267
268 static const float kTestVectorFloat[kTestVectorSize] = {-1.0, 0, 1.0, -1.0, 0.5,
269 -0.5, 0, 1.0, 0, 0};
mcasas 2016/03/09 00:24:18 This needs formatting, use git cl format before up
eklavyamirani 2016/03/15 03:48:13 Done.
270
268 // Expected results. 271 // Expected results.
269 static const int kTestVectorFrames = kTestVectorSize / 2; 272 static const int kTestVectorFrames = kTestVectorSize / 2;
270 static const float kTestVectorResult[][kTestVectorFrames] = { 273 static const float kTestVectorResult[][kTestVectorFrames] = {
271 { -1, 1, 0.5, 0, 0 }, { 0, -1, -0.5, 1, 0 }}; 274 { -1, 1, 0.5, 0, 0 }, { 0, -1, -0.5, 1, 0 }};
272 static const int kTestVectorChannels = arraysize(kTestVectorResult); 275 static const int kTestVectorChannels = arraysize(kTestVectorResult);
273 276
274 // Verify FromInterleaved() deinterleaves audio in supported formats correctly. 277 // Verify FromInterleaved() deinterleaves audio in supported formats correctly.
275 TEST_F(AudioBusTest, FromInterleaved) { 278 TEST_F(AudioBusTest, FromInterleaved) {
276 scoped_ptr<AudioBus> bus = AudioBus::Create( 279 scoped_ptr<AudioBus> bus = AudioBus::Create(
277 kTestVectorChannels, kTestVectorFrames); 280 kTestVectorChannels, kTestVectorFrames);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 memcpy(fixed_test_array, kTestVectorInt32, sizeof(kTestVectorInt32)); 371 memcpy(fixed_test_array, kTestVectorInt32, sizeof(kTestVectorInt32));
369 ASSERT_EQ(fixed_test_array[4], std::numeric_limits<int32_t>::max() / 2); 372 ASSERT_EQ(fixed_test_array[4], std::numeric_limits<int32_t>::max() / 2);
370 fixed_test_array[4]++; 373 fixed_test_array[4]++;
371 374
372 ASSERT_TRUE( 375 ASSERT_TRUE(
373 memcmp(test_array, kTestVectorInt32, sizeof(kTestVectorInt32)) == 0 || 376 memcmp(test_array, kTestVectorInt32, sizeof(kTestVectorInt32)) == 0 ||
374 memcmp(test_array, fixed_test_array, sizeof(fixed_test_array)) == 0); 377 memcmp(test_array, fixed_test_array, sizeof(fixed_test_array)) == 0);
375 } 378 }
376 } 379 }
377 380
381 TEST_F(AudioBusTest, ToInterleavedFloat) {
mcasas 2016/03/09 00:24:18 Add a comment like in l.341
eklavyamirani 2016/03/15 03:48:13 Done.
382 scoped_ptr<AudioBus> bus =
383 AudioBus::Create(kTestVectorChannels, kTestVectorFrames);
384 for (int ch = 0; ch < bus->channels(); ++ch) {
385 memcpy(bus->channel(ch), kTestVectorResult[ch],
386 kTestVectorFrames * sizeof(*bus->channel(ch)));
387 }
388
389 float test_array[arraysize(kTestVectorFloat)];
mcasas 2016/03/09 00:24:18 You might want to add a SCOPED_TRACE("float"); fo
eklavyamirani 2016/03/15 03:48:13 Done. Is this to output information when the test
mcasas 2016/04/11 23:47:07 Yes.
390 bus->ToInterleavedFloat(0, 0, bus->frames(), bus->channels(), test_array);
391 ASSERT_EQ(memcmp(test_array, kTestVectorFloat,
392 kTestVectorFrames * sizeof(*kTestVectorFloat)),
393 0);
394 }
395
378 // Verify ToInterleavedPartial() interleaves audio correctly. 396 // Verify ToInterleavedPartial() interleaves audio correctly.
379 TEST_F(AudioBusTest, ToInterleavedPartial) { 397 TEST_F(AudioBusTest, ToInterleavedPartial) {
380 // Only interleave the middle two frames in each channel. 398 // Only interleave the middle two frames in each channel.
381 static const int kPartialStart = 1; 399 static const int kPartialStart = 1;
382 static const int kPartialFrames = 2; 400 static const int kPartialFrames = 2;
383 ASSERT_LE(kPartialStart + kPartialFrames, kTestVectorFrames); 401 ASSERT_LE(kPartialStart + kPartialFrames, kTestVectorFrames);
384 402
385 scoped_ptr<AudioBus> expected = AudioBus::Create( 403 scoped_ptr<AudioBus> expected = AudioBus::Create(
386 kTestVectorChannels, kTestVectorFrames); 404 kTestVectorChannels, kTestVectorFrames);
387 for (int ch = 0; ch < kTestVectorChannels; ++ch) { 405 for (int ch = 0; ch < kTestVectorChannels; ++ch) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 440
423 // Verify zero volume case. 441 // Verify zero volume case.
424 bus->Scale(0); 442 bus->Scale(0);
425 for (int i = 0; i < bus->channels(); ++i) { 443 for (int i = 0; i < bus->channels(); ++i) {
426 SCOPED_TRACE("Zero Scale"); 444 SCOPED_TRACE("Zero Scale");
427 VerifyValue(bus->channel(i), bus->frames(), 0); 445 VerifyValue(bus->channel(i), bus->frames(), 0);
428 } 446 }
429 } 447 }
430 448
431 } // namespace media 449 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698