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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "media/base/audio_converter.h" | 8 #include "media/base/audio_converter.h" |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <cmath> | 12 #include <cmath> |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "media/base/audio_timestamp_helper.h" | 18 #include "media/base/audio_timestamp_helper.h" |
19 #include "media/base/fake_audio_render_callback.h" | 19 #include "media/base/fake_audio_render_callback.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace media { | 23 namespace media { |
24 | 24 |
25 // Parameters which control the many input case tests. | 25 // Parameters which control the many input case tests. |
26 static const int kConvertInputs = 8; | 26 static const int kConvertInputs = 8; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 // Creates |count| input callbacks to be used for conversion testing. | 66 // Creates |count| input callbacks to be used for conversion testing. |
67 void InitializeInputs(int count) { | 67 void InitializeInputs(int count) { |
68 // Setup FakeAudioRenderCallback step to compensate for resampling. | 68 // Setup FakeAudioRenderCallback step to compensate for resampling. |
69 double scale_factor = input_parameters_.sample_rate() / | 69 double scale_factor = input_parameters_.sample_rate() / |
70 static_cast<double>(output_parameters_.sample_rate()); | 70 static_cast<double>(output_parameters_.sample_rate()); |
71 double step = kSineCycles / (scale_factor * | 71 double step = kSineCycles / (scale_factor * |
72 static_cast<double>(output_parameters_.frames_per_buffer())); | 72 static_cast<double>(output_parameters_.frames_per_buffer())); |
73 | 73 |
74 for (int i = 0; i < count; ++i) { | 74 for (int i = 0; i < count; ++i) { |
75 fake_callbacks_.push_back(new FakeAudioRenderCallback(step, kSampleRate)); | 75 fake_callbacks_.push_back( |
76 converter_->AddInput(fake_callbacks_[i]); | 76 base::MakeUnique<FakeAudioRenderCallback>(step, kSampleRate)); |
| 77 converter_->AddInput(fake_callbacks_[i].get()); |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
80 // Resets all input callbacks to a pristine state. | 81 // Resets all input callbacks to a pristine state. |
81 void Reset() { | 82 void Reset() { |
82 converter_->Reset(); | 83 converter_->Reset(); |
83 for (size_t i = 0; i < fake_callbacks_.size(); ++i) | 84 for (size_t i = 0; i < fake_callbacks_.size(); ++i) |
84 fake_callbacks_[i]->reset(); | 85 fake_callbacks_[i]->reset(); |
85 expected_callback_->reset(); | 86 expected_callback_->reset(); |
86 } | 87 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 total_scale += volume; | 156 total_scale += volume; |
156 fake_callbacks_[i]->set_volume(volume); | 157 fake_callbacks_[i]->set_volume(volume); |
157 } | 158 } |
158 for (int i = 0; i < kConvertCycles; ++i) | 159 for (int i = 0; i < kConvertCycles; ++i) |
159 ASSERT_TRUE(RenderAndValidateAudioData(total_scale)); | 160 ASSERT_TRUE(RenderAndValidateAudioData(total_scale)); |
160 | 161 |
161 Reset(); | 162 Reset(); |
162 | 163 |
163 // Remove every other input. | 164 // Remove every other input. |
164 for (size_t i = 1; i < fake_callbacks_.size(); i += 2) | 165 for (size_t i = 1; i < fake_callbacks_.size(); i += 2) |
165 converter_->RemoveInput(fake_callbacks_[i]); | 166 converter_->RemoveInput(fake_callbacks_[i].get()); |
166 | 167 |
167 SetVolume(1); | 168 SetVolume(1); |
168 float scale = inputs > 1 ? inputs / 2.0f : inputs; | 169 float scale = inputs > 1 ? inputs / 2.0f : inputs; |
169 for (int i = 0; i < kConvertCycles; ++i) | 170 for (int i = 0; i < kConvertCycles; ++i) |
170 ASSERT_TRUE(RenderAndValidateAudioData(scale)); | 171 ASSERT_TRUE(RenderAndValidateAudioData(scale)); |
171 } | 172 } |
172 | 173 |
173 protected: | 174 protected: |
174 virtual ~AudioConverterTest() {} | 175 virtual ~AudioConverterTest() {} |
175 | 176 |
176 // Converter under test. | 177 // Converter under test. |
177 std::unique_ptr<AudioConverter> converter_; | 178 std::unique_ptr<AudioConverter> converter_; |
178 | 179 |
179 // Input and output parameters used for AudioConverter construction. | 180 // Input and output parameters used for AudioConverter construction. |
180 AudioParameters input_parameters_; | 181 AudioParameters input_parameters_; |
181 AudioParameters output_parameters_; | 182 AudioParameters output_parameters_; |
182 | 183 |
183 // Destination AudioBus for AudioConverter output. | 184 // Destination AudioBus for AudioConverter output. |
184 std::unique_ptr<AudioBus> audio_bus_; | 185 std::unique_ptr<AudioBus> audio_bus_; |
185 | 186 |
186 // AudioBus containing expected results for comparison with |audio_bus_|. | 187 // AudioBus containing expected results for comparison with |audio_bus_|. |
187 std::unique_ptr<AudioBus> expected_audio_bus_; | 188 std::unique_ptr<AudioBus> expected_audio_bus_; |
188 | 189 |
189 // Vector of all input callbacks used to drive AudioConverter::Convert(). | 190 // Vector of all input callbacks used to drive AudioConverter::Convert(). |
190 ScopedVector<FakeAudioRenderCallback> fake_callbacks_; | 191 std::vector<std::unique_ptr<FakeAudioRenderCallback>> fake_callbacks_; |
191 | 192 |
192 // Parallel input callback which generates the expected output. | 193 // Parallel input callback which generates the expected output. |
193 std::unique_ptr<FakeAudioRenderCallback> expected_callback_; | 194 std::unique_ptr<FakeAudioRenderCallback> expected_callback_; |
194 | 195 |
195 // Epsilon value with which to perform comparisons between |audio_bus_| and | 196 // Epsilon value with which to perform comparisons between |audio_bus_| and |
196 // |expected_audio_bus_|. | 197 // |expected_audio_bus_|. |
197 double epsilon_; | 198 double epsilon_; |
198 | 199 |
199 DISALLOW_COPY_AND_ASSIGN(AudioConverterTest); | 200 DISALLOW_COPY_AND_ASSIGN(AudioConverterTest); |
200 }; | 201 }; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // No resampling. No channel mixing. | 262 // No resampling. No channel mixing. |
262 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), | 263 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), |
263 | 264 |
264 // Upsampling. Channel upmixing. | 265 // Upsampling. Channel upmixing. |
265 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), | 266 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), |
266 | 267 |
267 // Downsampling. Channel downmixing. | 268 // Downsampling. Channel downmixing. |
268 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); | 269 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); |
269 | 270 |
270 } // namespace media | 271 } // namespace media |
OLD | NEW |