Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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] = { | |
| 269 -1.0, 0.0, 1.0, -1.0, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0}; | |
| 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 Loading... | |
| 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 // Verify ToInterleavedFloat interleaves |AudioBus| channels of float | |
| 382 // into a single linear output buffer correctly | |
|
mcasas
2016/04/11 23:47:08
s/ToInterleavedFloat/ToInterleavedFloat()/
Classe
| |
| 383 TEST_F(AudioBusTest, ToInterleavedFloat) { | |
| 384 SCOPED_TRACE("float"); | |
| 385 scoped_ptr<AudioBus> bus = | |
| 386 AudioBus::Create(kTestVectorChannels, kTestVectorFrames); | |
| 387 for (int ch = 0; ch < bus->channels(); ++ch) { | |
| 388 memcpy(bus->channel(ch), kTestVectorResult[ch], | |
| 389 kTestVectorFrames * sizeof(*bus->channel(ch))); | |
| 390 } | |
| 391 | |
| 392 float test_array[arraysize(kTestVectorFloat)]; | |
| 393 bus->ToInterleavedFloat(0, 0, bus->frames(), test_array); | |
| 394 ASSERT_EQ(memcmp(test_array, kTestVectorFloat, | |
|
eklavyamirani
2016/04/04 08:11:58
Fixed the formatting on this in my local commit. A
mcasas
2016/04/11 23:47:08
Sorry, yes, when you have addressed the
reviewers'
| |
| 395 kTestVectorFrames * sizeof(*kTestVectorFloat)), | |
| 396 0); | |
| 397 } | |
| 398 | |
| 378 // Verify ToInterleavedPartial() interleaves audio correctly. | 399 // Verify ToInterleavedPartial() interleaves audio correctly. |
| 379 TEST_F(AudioBusTest, ToInterleavedPartial) { | 400 TEST_F(AudioBusTest, ToInterleavedPartial) { |
| 380 // Only interleave the middle two frames in each channel. | 401 // Only interleave the middle two frames in each channel. |
| 381 static const int kPartialStart = 1; | 402 static const int kPartialStart = 1; |
| 382 static const int kPartialFrames = 2; | 403 static const int kPartialFrames = 2; |
| 383 ASSERT_LE(kPartialStart + kPartialFrames, kTestVectorFrames); | 404 ASSERT_LE(kPartialStart + kPartialFrames, kTestVectorFrames); |
| 384 | 405 |
| 385 scoped_ptr<AudioBus> expected = AudioBus::Create( | 406 scoped_ptr<AudioBus> expected = AudioBus::Create( |
| 386 kTestVectorChannels, kTestVectorFrames); | 407 kTestVectorChannels, kTestVectorFrames); |
| 387 for (int ch = 0; ch < kTestVectorChannels; ++ch) { | 408 for (int ch = 0; ch < kTestVectorChannels; ++ch) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 | 443 |
| 423 // Verify zero volume case. | 444 // Verify zero volume case. |
| 424 bus->Scale(0); | 445 bus->Scale(0); |
| 425 for (int i = 0; i < bus->channels(); ++i) { | 446 for (int i = 0; i < bus->channels(); ++i) { |
| 426 SCOPED_TRACE("Zero Scale"); | 447 SCOPED_TRACE("Zero Scale"); |
| 427 VerifyValue(bus->channel(i), bus->frames(), 0); | 448 VerifyValue(bus->channel(i), bus->frames(), 0); |
| 428 } | 449 } |
| 429 } | 450 } |
| 430 | 451 |
| 431 } // namespace media | 452 } // namespace media |
| OLD | NEW |