OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/base/audio_buffer.h" | 5 #include "media/base/audio_buffer.h" |
6 #include "media/base/audio_bus.h" | 6 #include "media/base/audio_bus.h" |
7 #include "media/base/test_helpers.h" | 7 #include "media/base/test_helpers.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 444 } |
445 | 445 |
446 TEST(AudioBufferTest, TrimRangePlanar) { | 446 TEST(AudioBufferTest, TrimRangePlanar) { |
447 TrimRangeTest(kSampleFormatPlanarF32); | 447 TrimRangeTest(kSampleFormatPlanarF32); |
448 } | 448 } |
449 | 449 |
450 TEST(AudioBufferTest, TrimRangeInterleaved) { | 450 TEST(AudioBufferTest, TrimRangeInterleaved) { |
451 TrimRangeTest(kSampleFormatF32); | 451 TrimRangeTest(kSampleFormatF32); |
452 } | 452 } |
453 | 453 |
| 454 static scoped_refptr<AudioBuffer> MakeReadFramesInterleavedTestBuffer( |
| 455 SampleFormat sample_format, |
| 456 int sample_rate, |
| 457 ChannelLayout channel_layout, |
| 458 int channel_count, |
| 459 int frames) { |
| 460 switch (sample_format) { |
| 461 case kSampleFormatS16: |
| 462 case kSampleFormatPlanarS16: |
| 463 return MakeAudioBuffer<int16>(sample_format, |
| 464 channel_layout, |
| 465 channel_count, |
| 466 sample_rate, |
| 467 0, |
| 468 1, |
| 469 frames, |
| 470 base::TimeDelta::FromSeconds(0)); |
| 471 case kSampleFormatS32: |
| 472 return MakeAudioBuffer<int32>(kSampleFormatS32, |
| 473 channel_layout, |
| 474 channel_count, |
| 475 sample_rate, |
| 476 0, |
| 477 65536, |
| 478 frames, |
| 479 base::TimeDelta::FromSeconds(0)); |
| 480 case kSampleFormatF32: |
| 481 case kSampleFormatPlanarF32: |
| 482 return MakeAudioBuffer<float>( |
| 483 sample_format, |
| 484 channel_layout, |
| 485 channel_count, |
| 486 sample_rate, |
| 487 0.0f, |
| 488 65536.0f / std::numeric_limits<int32>::max(), |
| 489 frames, |
| 490 base::TimeDelta::FromSeconds(0)); |
| 491 case kSampleFormatU8: |
| 492 case kUnknownSampleFormat: |
| 493 EXPECT_FALSE(true); |
| 494 break; |
| 495 } |
| 496 return AudioBuffer::CreateEOSBuffer(); |
| 497 } |
| 498 |
| 499 static void ReadFramesInterleavedS32Test(SampleFormat sample_format) { |
| 500 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; |
| 501 const int channels = ChannelLayoutToChannelCount(channel_layout); |
| 502 const int frames = kSampleRate / 10; |
| 503 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 504 scoped_refptr<AudioBuffer> buffer = MakeReadFramesInterleavedTestBuffer( |
| 505 sample_format, kSampleRate, channel_layout, channels, frames); |
| 506 EXPECT_EQ(frames, buffer->frame_count()); |
| 507 EXPECT_EQ(duration, buffer->duration()); |
| 508 |
| 509 int32* dest = new int32[frames * channels]; |
| 510 buffer->ReadFramesInterleavedS32(frames * channels, dest); |
| 511 |
| 512 int count = 0; |
| 513 for (int i = 0; i < frames; ++i) { |
| 514 for (int ch = 0; ch < channels; ++ch) { |
| 515 EXPECT_EQ(dest[count++], (frames * ch + i) << 16); |
| 516 } |
| 517 } |
| 518 delete[] dest; |
| 519 } |
| 520 |
| 521 TEST(AudioBufferTest, ReadFramesInterleavedS32FromS16) { |
| 522 ReadFramesInterleavedS32Test(kSampleFormatS16); |
| 523 } |
| 524 |
| 525 TEST(AudioBufferTest, ReadFramesInterleavedS32FromS32) { |
| 526 ReadFramesInterleavedS32Test(kSampleFormatS32); |
| 527 } |
| 528 |
| 529 TEST(AudioBufferTest, ReadFramesInterleavedS32FromF32) { |
| 530 ReadFramesInterleavedS32Test(kSampleFormatF32); |
| 531 } |
| 532 |
| 533 TEST(AudioBufferTest, ReadFramesInterleavedS32FromPlanarS16) { |
| 534 ReadFramesInterleavedS32Test(kSampleFormatPlanarS16); |
| 535 } |
| 536 |
| 537 TEST(AudioBufferTest, ReadFramesInterleavedS32FromPlanarF32) { |
| 538 ReadFramesInterleavedS32Test(kSampleFormatPlanarF32); |
| 539 } |
| 540 |
454 } // namespace media | 541 } // namespace media |
OLD | NEW |