| 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 30 matching lines...) Expand all Loading... |
| 41 virtual ~MultiChannelResamplerTest() {} | 41 virtual ~MultiChannelResamplerTest() {} |
| 42 | 42 |
| 43 void InitializeAudioData(int channels, int frames) { | 43 void InitializeAudioData(int channels, int frames) { |
| 44 frames_ = frames; | 44 frames_ = frames; |
| 45 audio_bus_ = AudioBus::Create(channels, frames); | 45 audio_bus_ = AudioBus::Create(channels, frames); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just | 48 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just |
| 49 // fills the provided audio_data with |kFillValue|. | 49 // fills the provided audio_data with |kFillValue|. |
| 50 virtual void ProvideInput(AudioBus* audio_bus) { | 50 virtual void ProvideInput(AudioBus* audio_bus) { |
| 51 float fill_value = fill_junk_values_ ? (1 / kFillValue) : kFillValue; |
| 51 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); | 52 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); |
| 52 for (int i = 0; i < audio_bus->channels(); ++i) | 53 for (int i = 0; i < audio_bus->channels(); ++i) |
| 53 for (int j = 0; j < audio_bus->frames(); ++j) | 54 for (int j = 0; j < audio_bus->frames(); ++j) |
| 54 audio_bus->channel(i)[j] = kFillValue; | 55 audio_bus->channel(i)[j] = fill_value; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void MultiChannelTest(int channels, int frames, double expected_max_rms_error, | 58 void MultiChannelTest(int channels, int frames, double expected_max_rms_error, |
| 58 double expected_max_error) { | 59 double expected_max_error) { |
| 59 InitializeAudioData(channels, frames); | 60 InitializeAudioData(channels, frames); |
| 60 MultiChannelResampler resampler( | 61 MultiChannelResampler resampler( |
| 61 channels, kScaleFactor, base::Bind( | 62 channels, kScaleFactor, base::Bind( |
| 62 &MultiChannelResamplerTest::ProvideInput, | 63 &MultiChannelResamplerTest::ProvideInput, |
| 63 base::Unretained(this))); | 64 base::Unretained(this))); |
| 65 // First prime the resampler with some junk data, so we can verify Flush(). |
| 66 fill_junk_values_ = true; |
| 67 resampler.Resample(audio_bus_.get(), 1); |
| 68 resampler.Flush(); |
| 69 fill_junk_values_ = false; |
| 70 // If Flush() didn't work, the rest of the tests will fail. |
| 64 resampler.Resample(audio_bus_.get(), frames); | 71 resampler.Resample(audio_bus_.get(), frames); |
| 65 TestValues(expected_max_rms_error, expected_max_error); | 72 TestValues(expected_max_rms_error, expected_max_error); |
| 66 } | 73 } |
| 67 | 74 |
| 68 void HighLatencyTest(int channels) { | 75 void HighLatencyTest(int channels) { |
| 69 MultiChannelTest(channels, kHighLatencySize, kHighLatencyMaxRMSError, | 76 MultiChannelTest(channels, kHighLatencySize, kHighLatencyMaxRMSError, |
| 70 kHighLatencyMaxError); | 77 kHighLatencyMaxError); |
| 71 } | 78 } |
| 72 | 79 |
| 73 void LowLatencyTest(int channels) { | 80 void LowLatencyTest(int channels) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 | 99 |
| 93 double rms_error = sqrt( | 100 double rms_error = sqrt( |
| 94 sum_of_squares / (frames_ * audio_bus_->channels())); | 101 sum_of_squares / (frames_ * audio_bus_->channels())); |
| 95 | 102 |
| 96 EXPECT_LE(rms_error, expected_max_rms_error); | 103 EXPECT_LE(rms_error, expected_max_rms_error); |
| 97 EXPECT_LE(max_error, expected_max_error); | 104 EXPECT_LE(max_error, expected_max_error); |
| 98 } | 105 } |
| 99 | 106 |
| 100 protected: | 107 protected: |
| 101 int frames_; | 108 int frames_; |
| 109 bool fill_junk_values_; |
| 102 scoped_ptr<AudioBus> audio_bus_; | 110 scoped_ptr<AudioBus> audio_bus_; |
| 103 | 111 |
| 104 DISALLOW_COPY_AND_ASSIGN(MultiChannelResamplerTest); | 112 DISALLOW_COPY_AND_ASSIGN(MultiChannelResamplerTest); |
| 105 }; | 113 }; |
| 106 | 114 |
| 107 TEST_P(MultiChannelResamplerTest, HighLatency) { | 115 TEST_P(MultiChannelResamplerTest, HighLatency) { |
| 108 HighLatencyTest(GetParam()); | 116 HighLatencyTest(GetParam()); |
| 109 } | 117 } |
| 110 | 118 |
| 111 TEST_P(MultiChannelResamplerTest, LowLatency) { | 119 TEST_P(MultiChannelResamplerTest, LowLatency) { |
| 112 LowLatencyTest(GetParam()); | 120 LowLatencyTest(GetParam()); |
| 113 } | 121 } |
| 114 | 122 |
| 115 // Test common channel layouts: mono, stereo, 5.1, 7.1. | 123 // Test common channel layouts: mono, stereo, 5.1, 7.1. |
| 116 INSTANTIATE_TEST_CASE_P( | 124 INSTANTIATE_TEST_CASE_P( |
| 117 MultiChannelResamplerTest, MultiChannelResamplerTest, | 125 MultiChannelResamplerTest, MultiChannelResamplerTest, |
| 118 testing::Values(1, 2, 6, 8)); | 126 testing::Values(1, 2, 6, 8)); |
| 119 | 127 |
| 120 } // namespace media | 128 } // namespace media |
| OLD | NEW |