| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 virtual ~MultiChannelResamplerTest() {} | 43 virtual ~MultiChannelResamplerTest() {} |
| 44 | 44 |
| 45 void InitializeAudioData(int channels, int frames) { | 45 void InitializeAudioData(int channels, int frames) { |
| 46 frames_ = frames; | 46 frames_ = frames; |
| 47 audio_bus_ = AudioBus::Create(channels, frames); | 47 audio_bus_ = AudioBus::Create(channels, frames); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just | 50 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation, just |
| 51 // fills the provided audio_data with |kFillValue|. | 51 // fills the provided audio_data with |kFillValue|. |
| 52 virtual void ProvideInput(int frame_delay, AudioBus* audio_bus) { | 52 virtual void ProvideInput(int frame_delay, AudioBus* audio_bus) { |
| 53 EXPECT_GT(frame_delay, last_frame_delay_); | 53 EXPECT_GE(frame_delay, last_frame_delay_); |
| 54 last_frame_delay_ = frame_delay; | 54 last_frame_delay_ = frame_delay; |
| 55 | 55 |
| 56 float fill_value = fill_junk_values_ ? (1 / kFillValue) : kFillValue; | 56 float fill_value = fill_junk_values_ ? (1 / kFillValue) : kFillValue; |
| 57 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); | 57 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels()); |
| 58 for (int i = 0; i < audio_bus->channels(); ++i) | 58 for (int i = 0; i < audio_bus->channels(); ++i) |
| 59 for (int j = 0; j < audio_bus->frames(); ++j) | 59 for (int j = 0; j < audio_bus->frames(); ++j) |
| 60 audio_bus->channel(i)[j] = fill_value; | 60 audio_bus->channel(i)[j] = fill_value; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void MultiChannelTest(int channels, int frames, double expected_max_rms_error, | 63 void MultiChannelTest(int channels, int frames, double expected_max_rms_error, |
| 64 double expected_max_error) { | 64 double expected_max_error) { |
| 65 InitializeAudioData(channels, frames); | 65 InitializeAudioData(channels, frames); |
| 66 MultiChannelResampler resampler(channels, kScaleFactor, base::Bind( | 66 MultiChannelResampler resampler( |
| 67 &MultiChannelResamplerTest::ProvideInput, base::Unretained(this))); | 67 channels, kScaleFactor, SincResampler::kDefaultBlockSize, base::Bind( |
| 68 &MultiChannelResamplerTest::ProvideInput, base::Unretained(this))); |
| 68 | 69 |
| 69 // First prime the resampler with some junk data, so we can verify Flush(). | 70 // First prime the resampler with some junk data, so we can verify Flush(). |
| 70 fill_junk_values_ = true; | 71 fill_junk_values_ = true; |
| 71 resampler.Resample(audio_bus_.get(), 1); | 72 resampler.Resample(audio_bus_.get(), 1); |
| 72 resampler.Flush(); | 73 resampler.Flush(); |
| 73 fill_junk_values_ = false; | 74 fill_junk_values_ = false; |
| 74 | 75 |
| 75 // The last frame delay should be strictly less than the total frame count. | 76 // The last frame delay should be strictly less than the total frame count. |
| 76 EXPECT_LT(last_frame_delay_, audio_bus_->frames()); | 77 EXPECT_LT(last_frame_delay_, audio_bus_->frames()); |
| 77 last_frame_delay_ = -1; | 78 last_frame_delay_ = -1; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 TEST_P(MultiChannelResamplerTest, LowLatency) { | 130 TEST_P(MultiChannelResamplerTest, LowLatency) { |
| 130 LowLatencyTest(GetParam()); | 131 LowLatencyTest(GetParam()); |
| 131 } | 132 } |
| 132 | 133 |
| 133 // Test common channel layouts: mono, stereo, 5.1, 7.1. | 134 // Test common channel layouts: mono, stereo, 5.1, 7.1. |
| 134 INSTANTIATE_TEST_CASE_P( | 135 INSTANTIATE_TEST_CASE_P( |
| 135 MultiChannelResamplerTest, MultiChannelResamplerTest, | 136 MultiChannelResamplerTest, MultiChannelResamplerTest, |
| 136 testing::Values(1, 2, 6, 8)); | 137 testing::Values(1, 2, 6, 8)); |
| 137 | 138 |
| 138 } // namespace media | 139 } // namespace media |
| OLD | NEW |