| 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // Chosen arbitrarily based on what each resampler reported during testing. | 31 // Chosen arbitrarily based on what each resampler reported during testing. |
| 32 static const double kLowLatencyMaxRMSError = 0.0036; | 32 static const double kLowLatencyMaxRMSError = 0.0036; |
| 33 static const double kLowLatencyMaxError = 0.04; | 33 static const double kLowLatencyMaxError = 0.04; |
| 34 static const double kHighLatencyMaxRMSError = 0.0036; | 34 static const double kHighLatencyMaxRMSError = 0.0036; |
| 35 static const double kHighLatencyMaxError = 0.04; | 35 static const double kHighLatencyMaxError = 0.04; |
| 36 | 36 |
| 37 class MultiChannelResamplerTest | 37 class MultiChannelResamplerTest |
| 38 : public testing::TestWithParam<int> { | 38 : public testing::TestWithParam<int> { |
| 39 public: | 39 public: |
| 40 MultiChannelResamplerTest() {} | 40 MultiChannelResamplerTest() |
| 41 : last_frame_delay_(-1) { |
| 42 } |
| 41 virtual ~MultiChannelResamplerTest() {} | 43 virtual ~MultiChannelResamplerTest() {} |
| 42 | 44 |
| 43 void InitializeAudioData(int channels, int frames) { | 45 void InitializeAudioData(int channels, int frames) { |
| 44 frames_ = frames; | 46 frames_ = frames; |
| 45 audio_bus_ = AudioBus::Create(channels, frames); | 47 audio_bus_ = AudioBus::Create(channels, frames); |
| 46 } | 48 } |
| 47 | 49 |
| 48 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just | 50 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just |
| 49 // fills the provided audio_data with |kFillValue|. | 51 // fills the provided audio_data with |kFillValue|. |
| 50 virtual void ProvideInput(AudioBus* audio_bus) { | 52 virtual void ProvideInput(int frame_delay, AudioBus* audio_bus) { |
| 53 EXPECT_GT(frame_delay, last_frame_delay_); |
| 54 last_frame_delay_ = frame_delay; |
| 55 |
| 51 float fill_value = fill_junk_values_ ? (1 / kFillValue) : kFillValue; | 56 float fill_value = fill_junk_values_ ? (1 / kFillValue) : kFillValue; |
| 52 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); | 57 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); |
| 53 for (int i = 0; i < audio_bus->channels(); ++i) | 58 for (int i = 0; i < audio_bus->channels(); ++i) |
| 54 for (int j = 0; j < audio_bus->frames(); ++j) | 59 for (int j = 0; j < audio_bus->frames(); ++j) |
| 55 audio_bus->channel(i)[j] = fill_value; | 60 audio_bus->channel(i)[j] = fill_value; |
| 56 } | 61 } |
| 57 | 62 |
| 58 void MultiChannelTest(int channels, int frames, double expected_max_rms_error, | 63 void MultiChannelTest(int channels, int frames, double expected_max_rms_error, |
| 59 double expected_max_error) { | 64 double expected_max_error) { |
| 60 InitializeAudioData(channels, frames); | 65 InitializeAudioData(channels, frames); |
| 61 MultiChannelResampler resampler( | 66 MultiChannelResampler resampler(channels, kScaleFactor, base::Bind( |
| 62 channels, kScaleFactor, base::Bind( | 67 &MultiChannelResamplerTest::ProvideInput, base::Unretained(this))); |
| 63 &MultiChannelResamplerTest::ProvideInput, | 68 |
| 64 base::Unretained(this))); | |
| 65 // First prime the resampler with some junk data, so we can verify Flush(). | 69 // First prime the resampler with some junk data, so we can verify Flush(). |
| 66 fill_junk_values_ = true; | 70 fill_junk_values_ = true; |
| 67 resampler.Resample(audio_bus_.get(), 1); | 71 resampler.Resample(audio_bus_.get(), 1); |
| 68 resampler.Flush(); | 72 resampler.Flush(); |
| 69 fill_junk_values_ = false; | 73 fill_junk_values_ = false; |
| 74 |
| 75 // The last frame delay should be strictly less than the total frame count. |
| 76 EXPECT_LT(last_frame_delay_, audio_bus_->frames()); |
| 77 last_frame_delay_ = -1; |
| 78 |
| 70 // If Flush() didn't work, the rest of the tests will fail. | 79 // If Flush() didn't work, the rest of the tests will fail. |
| 71 resampler.Resample(audio_bus_.get(), frames); | 80 resampler.Resample(audio_bus_.get(), frames); |
| 72 TestValues(expected_max_rms_error, expected_max_error); | 81 TestValues(expected_max_rms_error, expected_max_error); |
| 73 } | 82 } |
| 74 | 83 |
| 75 void HighLatencyTest(int channels) { | 84 void HighLatencyTest(int channels) { |
| 76 MultiChannelTest(channels, kHighLatencySize, kHighLatencyMaxRMSError, | 85 MultiChannelTest(channels, kHighLatencySize, kHighLatencyMaxRMSError, |
| 77 kHighLatencyMaxError); | 86 kHighLatencyMaxError); |
| 78 } | 87 } |
| 79 | 88 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 101 sum_of_squares / (frames_ * audio_bus_->channels())); | 110 sum_of_squares / (frames_ * audio_bus_->channels())); |
| 102 | 111 |
| 103 EXPECT_LE(rms_error, expected_max_rms_error); | 112 EXPECT_LE(rms_error, expected_max_rms_error); |
| 104 EXPECT_LE(max_error, expected_max_error); | 113 EXPECT_LE(max_error, expected_max_error); |
| 105 } | 114 } |
| 106 | 115 |
| 107 protected: | 116 protected: |
| 108 int frames_; | 117 int frames_; |
| 109 bool fill_junk_values_; | 118 bool fill_junk_values_; |
| 110 scoped_ptr<AudioBus> audio_bus_; | 119 scoped_ptr<AudioBus> audio_bus_; |
| 120 int last_frame_delay_; |
| 111 | 121 |
| 112 DISALLOW_COPY_AND_ASSIGN(MultiChannelResamplerTest); | 122 DISALLOW_COPY_AND_ASSIGN(MultiChannelResamplerTest); |
| 113 }; | 123 }; |
| 114 | 124 |
| 115 TEST_P(MultiChannelResamplerTest, HighLatency) { | 125 TEST_P(MultiChannelResamplerTest, HighLatency) { |
| 116 HighLatencyTest(GetParam()); | 126 HighLatencyTest(GetParam()); |
| 117 } | 127 } |
| 118 | 128 |
| 119 TEST_P(MultiChannelResamplerTest, LowLatency) { | 129 TEST_P(MultiChannelResamplerTest, LowLatency) { |
| 120 LowLatencyTest(GetParam()); | 130 LowLatencyTest(GetParam()); |
| 121 } | 131 } |
| 122 | 132 |
| 123 // Test common channel layouts: mono, stereo, 5.1, 7.1. | 133 // Test common channel layouts: mono, stereo, 5.1, 7.1. |
| 124 INSTANTIATE_TEST_CASE_P( | 134 INSTANTIATE_TEST_CASE_P( |
| 125 MultiChannelResamplerTest, MultiChannelResamplerTest, | 135 MultiChannelResamplerTest, MultiChannelResamplerTest, |
| 126 testing::Values(1, 2, 6, 8)); | 136 testing::Values(1, 2, 6, 8)); |
| 127 | 137 |
| 128 } // namespace media | 138 } // namespace media |
| OLD | NEW |