| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 static constexpr int kInterleavedFrameCount = 3; | 537 static constexpr int kInterleavedFrameCount = 3; |
| 538 | 538 |
| 539 std::unique_ptr<AudioBus> bus_under_test; | 539 std::unique_ptr<AudioBus> bus_under_test; |
| 540 std::vector<float> interleaved_dummy_frames; | 540 std::vector<float> interleaved_dummy_frames; |
| 541 | 541 |
| 542 ZeroingOutTestData() { | 542 ZeroingOutTestData() { |
| 543 // Create a bus and fill each channel with a test pattern of form | 543 // Create a bus and fill each channel with a test pattern of form |
| 544 // [1.0, 2.0, 3.0, ...] | 544 // [1.0, 2.0, 3.0, ...] |
| 545 bus_under_test = AudioBus::Create(kChannelCount, kFrameCount); | 545 bus_under_test = AudioBus::Create(kChannelCount, kFrameCount); |
| 546 for (int ch = 0; ch < kChannelCount; ++ch) { | 546 for (int ch = 0; ch < kChannelCount; ++ch) { |
| 547 auto sample_array_for_current_channel = bus_under_test->channel(ch); | 547 auto* sample_array_for_current_channel = bus_under_test->channel(ch); |
| 548 for (int frame_index = 0; frame_index < kFrameCount; frame_index++) { | 548 for (int frame_index = 0; frame_index < kFrameCount; frame_index++) { |
| 549 sample_array_for_current_channel[frame_index] = | 549 sample_array_for_current_channel[frame_index] = |
| 550 static_cast<float>(frame_index + 1); | 550 static_cast<float>(frame_index + 1); |
| 551 } | 551 } |
| 552 } | 552 } |
| 553 | 553 |
| 554 // Create a vector containing dummy interleaved samples. | 554 // Create a vector containing dummy interleaved samples. |
| 555 static const float kDummySampleValue = 0.123f; | 555 static const float kDummySampleValue = 0.123f; |
| 556 interleaved_dummy_frames.resize(kChannelCount * kInterleavedFrameCount); | 556 interleaved_dummy_frames.resize(kChannelCount * kInterleavedFrameCount); |
| 557 std::fill(interleaved_dummy_frames.begin(), interleaved_dummy_frames.end(), | 557 std::fill(interleaved_dummy_frames.begin(), interleaved_dummy_frames.end(), |
| 558 kDummySampleValue); | 558 kDummySampleValue); |
| 559 } | 559 } |
| 560 }; | 560 }; |
| 561 | 561 |
| 562 TEST_F(AudioBusTest, FromInterleavedZerosOutUntouchedFrames) { | 562 TEST_F(AudioBusTest, FromInterleavedZerosOutUntouchedFrames) { |
| 563 ZeroingOutTestData test_data; | 563 ZeroingOutTestData test_data; |
| 564 | 564 |
| 565 // Exercise | 565 // Exercise |
| 566 test_data.bus_under_test->FromInterleaved<Float32SampleTypeTraits>( | 566 test_data.bus_under_test->FromInterleaved<Float32SampleTypeTraits>( |
| 567 &test_data.interleaved_dummy_frames[0], test_data.kInterleavedFrameCount); | 567 &test_data.interleaved_dummy_frames[0], test_data.kInterleavedFrameCount); |
| 568 | 568 |
| 569 // Verification | 569 // Verification |
| 570 for (int ch = 0; ch < test_data.kChannelCount; ++ch) { | 570 for (int ch = 0; ch < test_data.kChannelCount; ++ch) { |
| 571 auto sample_array_for_current_channel = | 571 auto* sample_array_for_current_channel = |
| 572 test_data.bus_under_test->channel(ch); | 572 test_data.bus_under_test->channel(ch); |
| 573 for (int frame_index = test_data.kInterleavedFrameCount; | 573 for (int frame_index = test_data.kInterleavedFrameCount; |
| 574 frame_index < test_data.kFrameCount; frame_index++) { | 574 frame_index < test_data.kFrameCount; frame_index++) { |
| 575 ASSERT_EQ(0.0f, sample_array_for_current_channel[frame_index]); | 575 ASSERT_EQ(0.0f, sample_array_for_current_channel[frame_index]); |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 | 579 |
| 580 TEST_F(AudioBusTest, FromInterleavedPartialDoesNotZeroOutUntouchedFrames) { | 580 TEST_F(AudioBusTest, FromInterleavedPartialDoesNotZeroOutUntouchedFrames) { |
| 581 { | 581 { |
| 582 SCOPED_TRACE("Zero write offset"); | 582 SCOPED_TRACE("Zero write offset"); |
| 583 | 583 |
| 584 ZeroingOutTestData test_data; | 584 ZeroingOutTestData test_data; |
| 585 static const int kWriteOffsetInFrames = 0; | 585 static const int kWriteOffsetInFrames = 0; |
| 586 | 586 |
| 587 // Exercise | 587 // Exercise |
| 588 test_data.bus_under_test->FromInterleavedPartial<Float32SampleTypeTraits>( | 588 test_data.bus_under_test->FromInterleavedPartial<Float32SampleTypeTraits>( |
| 589 &test_data.interleaved_dummy_frames[0], kWriteOffsetInFrames, | 589 &test_data.interleaved_dummy_frames[0], kWriteOffsetInFrames, |
| 590 test_data.kInterleavedFrameCount); | 590 test_data.kInterleavedFrameCount); |
| 591 | 591 |
| 592 // Verification | 592 // Verification |
| 593 for (int ch = 0; ch < test_data.kChannelCount; ++ch) { | 593 for (int ch = 0; ch < test_data.kChannelCount; ++ch) { |
| 594 auto sample_array_for_current_channel = | 594 auto* sample_array_for_current_channel = |
| 595 test_data.bus_under_test->channel(ch); | 595 test_data.bus_under_test->channel(ch); |
| 596 for (int frame_index = | 596 for (int frame_index = |
| 597 test_data.kInterleavedFrameCount + kWriteOffsetInFrames; | 597 test_data.kInterleavedFrameCount + kWriteOffsetInFrames; |
| 598 frame_index < test_data.kFrameCount; frame_index++) { | 598 frame_index < test_data.kFrameCount; frame_index++) { |
| 599 ASSERT_EQ(frame_index + 1, | 599 ASSERT_EQ(frame_index + 1, |
| 600 sample_array_for_current_channel[frame_index]); | 600 sample_array_for_current_channel[frame_index]); |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 } | 603 } |
| 604 { | 604 { |
| 605 SCOPED_TRACE("Positive write offset"); | 605 SCOPED_TRACE("Positive write offset"); |
| 606 | 606 |
| 607 ZeroingOutTestData test_data; | 607 ZeroingOutTestData test_data; |
| 608 static const int kWriteOffsetInFrames = 2; | 608 static const int kWriteOffsetInFrames = 2; |
| 609 | 609 |
| 610 // Exercise | 610 // Exercise |
| 611 test_data.bus_under_test->FromInterleavedPartial<Float32SampleTypeTraits>( | 611 test_data.bus_under_test->FromInterleavedPartial<Float32SampleTypeTraits>( |
| 612 &test_data.interleaved_dummy_frames[0], kWriteOffsetInFrames, | 612 &test_data.interleaved_dummy_frames[0], kWriteOffsetInFrames, |
| 613 test_data.kInterleavedFrameCount); | 613 test_data.kInterleavedFrameCount); |
| 614 | 614 |
| 615 // Verification | 615 // Verification |
| 616 for (int ch = 0; ch < test_data.kChannelCount; ++ch) { | 616 for (int ch = 0; ch < test_data.kChannelCount; ++ch) { |
| 617 auto sample_array_for_current_channel = | 617 auto* sample_array_for_current_channel = |
| 618 test_data.bus_under_test->channel(ch); | 618 test_data.bus_under_test->channel(ch); |
| 619 // Check untouched frames before write offset | 619 // Check untouched frames before write offset |
| 620 for (int frame_index = 0; frame_index < kWriteOffsetInFrames; | 620 for (int frame_index = 0; frame_index < kWriteOffsetInFrames; |
| 621 frame_index++) { | 621 frame_index++) { |
| 622 ASSERT_EQ(frame_index + 1, | 622 ASSERT_EQ(frame_index + 1, |
| 623 sample_array_for_current_channel[frame_index]); | 623 sample_array_for_current_channel[frame_index]); |
| 624 } | 624 } |
| 625 // Check untouched frames after write | 625 // Check untouched frames after write |
| 626 for (int frame_index = | 626 for (int frame_index = |
| 627 test_data.kInterleavedFrameCount + kWriteOffsetInFrames; | 627 test_data.kInterleavedFrameCount + kWriteOffsetInFrames; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 | 659 |
| 660 // Verify zero volume case. | 660 // Verify zero volume case. |
| 661 bus->Scale(0); | 661 bus->Scale(0); |
| 662 for (int i = 0; i < bus->channels(); ++i) { | 662 for (int i = 0; i < bus->channels(); ++i) { |
| 663 SCOPED_TRACE("Zero Scale"); | 663 SCOPED_TRACE("Zero Scale"); |
| 664 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), 0); | 664 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), 0); |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| 668 } // namespace media | 668 } // namespace media |
| OLD | NEW |