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 <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 base::Time::kMicrosecondsPerSecond / input_sample_rate); | 227 base::Time::kMicrosecondsPerSecond / input_sample_rate); |
228 | 228 |
229 int expected_last_delay_milliseconds = | 229 int expected_last_delay_milliseconds = |
230 fill_count * input_parameters.frames_per_buffer() * | 230 fill_count * input_parameters.frames_per_buffer() * |
231 input_frame_duration.InMillisecondsF(); | 231 input_frame_duration.InMillisecondsF(); |
232 | 232 |
233 EXPECT_EQ(expected_last_delay_milliseconds, | 233 EXPECT_EQ(expected_last_delay_milliseconds, |
234 callback.last_audio_delay_milliseconds()); | 234 callback.last_audio_delay_milliseconds()); |
235 } | 235 } |
236 | 236 |
| 237 // InputCallback that zero's out the provided AudioBus. Used for benchmarking. |
| 238 class NullInputProvider : public AudioConverter::InputCallback { |
| 239 public: |
| 240 NullInputProvider() {} |
| 241 virtual ~NullInputProvider() {} |
| 242 |
| 243 virtual double ProvideInput(AudioBus* audio_bus, |
| 244 base::TimeDelta buffer_delay) OVERRIDE { |
| 245 audio_bus->Zero(); |
| 246 return 1; |
| 247 } |
| 248 }; |
| 249 |
237 // Benchmark for audio conversion. Original benchmarks were run with | 250 // Benchmark for audio conversion. Original benchmarks were run with |
238 // --audio-converter-iterations=50000. | 251 // --audio-converter-iterations=50000. |
239 TEST(AudioConverterTest, ConvertBenchmark) { | 252 TEST(AudioConverterTest, ConvertBenchmark) { |
240 int benchmark_iterations = kDefaultIterations; | 253 int benchmark_iterations = kDefaultIterations; |
241 std::string iterations(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 254 std::string iterations(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
242 kBenchmarkIterations)); | 255 kBenchmarkIterations)); |
243 base::StringToInt(iterations, &benchmark_iterations); | 256 base::StringToInt(iterations, &benchmark_iterations); |
244 if (benchmark_iterations < kDefaultIterations) | 257 if (benchmark_iterations < kDefaultIterations) |
245 benchmark_iterations = kDefaultIterations; | 258 benchmark_iterations = kDefaultIterations; |
246 | 259 |
247 // Create input and output parameters to convert between the two most common | 260 NullInputProvider fake_input1; |
248 // sets of parameters (as indicated via UMA data). | 261 NullInputProvider fake_input2; |
249 AudioParameters input_params( | 262 NullInputProvider fake_input3; |
250 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 48000, 16, 2048); | |
251 AudioParameters output_params( | |
252 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 44100, 16, 440); | |
253 scoped_ptr<AudioConverter> converter( | |
254 new AudioConverter(input_params, output_params, false)); | |
255 | |
256 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); | |
257 FakeAudioRenderCallback fake_input1(0.2); | |
258 FakeAudioRenderCallback fake_input2(0.4); | |
259 FakeAudioRenderCallback fake_input3(0.6); | |
260 converter->AddInput(&fake_input1); | |
261 converter->AddInput(&fake_input2); | |
262 converter->AddInput(&fake_input3); | |
263 | 263 |
264 printf("Benchmarking %d iterations:\n", benchmark_iterations); | 264 printf("Benchmarking %d iterations:\n", benchmark_iterations); |
265 | 265 |
266 // Benchmark Convert() w/ FIFO. | 266 { |
267 base::TimeTicks start = base::TimeTicks::HighResNow(); | 267 // Create input and output parameters to convert between the two most common |
268 for (int i = 0; i < benchmark_iterations; ++i) { | 268 // sets of parameters (as indicated via UMA data). |
269 converter->Convert(output_bus.get()); | 269 AudioParameters input_params( |
| 270 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 271 48000, 16, 2048); |
| 272 AudioParameters output_params( |
| 273 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 274 44100, 16, 440); |
| 275 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); |
| 276 |
| 277 scoped_ptr<AudioConverter> converter( |
| 278 new AudioConverter(input_params, output_params, true)); |
| 279 converter->AddInput(&fake_input1); |
| 280 converter->AddInput(&fake_input2); |
| 281 converter->AddInput(&fake_input3); |
| 282 |
| 283 // Benchmark Convert() w/ FIFO. |
| 284 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 285 for (int i = 0; i < benchmark_iterations; ++i) { |
| 286 converter->Convert(output_bus.get()); |
| 287 } |
| 288 double total_time_ms = |
| 289 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 290 printf("Convert() w/ Resampling took %.2fms.\n", total_time_ms); |
270 } | 291 } |
271 double total_time_ms = | |
272 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
273 printf("Convert() w/ FIFO took %.2fms.\n", total_time_ms); | |
274 | 292 |
275 converter.reset(new AudioConverter(input_params, output_params, true)); | 293 // Create input and output parameters to convert between common buffer sizes |
276 converter->AddInput(&fake_input1); | 294 // without any resampling for the FIFO vs no FIFO benchmarks. |
277 converter->AddInput(&fake_input2); | 295 AudioParameters input_params( |
278 converter->AddInput(&fake_input3); | 296 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 297 44100, 16, 2048); |
| 298 AudioParameters output_params( |
| 299 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 300 44100, 16, 440); |
| 301 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); |
279 | 302 |
280 // Benchmark Convert() w/o FIFO. | 303 { |
281 start = base::TimeTicks::HighResNow(); | 304 scoped_ptr<AudioConverter> converter( |
282 for (int i = 0; i < benchmark_iterations; ++i) { | 305 new AudioConverter(input_params, output_params, false)); |
283 converter->Convert(output_bus.get()); | 306 converter->AddInput(&fake_input1); |
| 307 converter->AddInput(&fake_input2); |
| 308 converter->AddInput(&fake_input3); |
| 309 |
| 310 // Benchmark Convert() w/ FIFO. |
| 311 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 312 for (int i = 0; i < benchmark_iterations; ++i) { |
| 313 converter->Convert(output_bus.get()); |
| 314 } |
| 315 double total_time_ms = |
| 316 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 317 printf("Convert() w/ FIFO took %.2fms.\n", total_time_ms); |
284 } | 318 } |
285 total_time_ms = | 319 |
286 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | 320 { |
287 printf("Convert() w/o FIFO took %.2fms.\n", total_time_ms); | 321 scoped_ptr<AudioConverter> converter( |
| 322 new AudioConverter(input_params, output_params, true)); |
| 323 converter->AddInput(&fake_input1); |
| 324 converter->AddInput(&fake_input2); |
| 325 converter->AddInput(&fake_input3); |
| 326 |
| 327 // Benchmark Convert() w/o FIFO. |
| 328 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 329 for (int i = 0; i < benchmark_iterations; ++i) { |
| 330 converter->Convert(output_bus.get()); |
| 331 } |
| 332 double total_time_ms = |
| 333 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 334 printf("Convert() w/o FIFO took %.2fms.\n", total_time_ms); |
| 335 } |
288 } | 336 } |
289 | 337 |
290 TEST_P(AudioConverterTest, NoInputs) { | 338 TEST_P(AudioConverterTest, NoInputs) { |
291 FillAudioData(1.0f); | 339 FillAudioData(1.0f); |
292 EXPECT_TRUE(RenderAndValidateAudioData(0.0f)); | 340 EXPECT_TRUE(RenderAndValidateAudioData(0.0f)); |
293 } | 341 } |
294 | 342 |
295 TEST_P(AudioConverterTest, OneInput) { | 343 TEST_P(AudioConverterTest, OneInput) { |
296 RunTest(1); | 344 RunTest(1); |
297 } | 345 } |
298 | 346 |
299 TEST_P(AudioConverterTest, ManyInputs) { | 347 TEST_P(AudioConverterTest, ManyInputs) { |
300 RunTest(kConvertInputs); | 348 RunTest(kConvertInputs); |
301 } | 349 } |
302 | 350 |
303 INSTANTIATE_TEST_CASE_P( | 351 INSTANTIATE_TEST_CASE_P( |
304 AudioConverterTest, AudioConverterTest, testing::Values( | 352 AudioConverterTest, AudioConverterTest, testing::Values( |
305 // No resampling. No channel mixing. | 353 // No resampling. No channel mixing. |
306 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), | 354 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), |
307 | 355 |
308 // Upsampling. Channel upmixing. | 356 // Upsampling. Channel upmixing. |
309 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), | 357 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), |
310 | 358 |
311 // Downsampling. Channel downmixing. | 359 // Downsampling. Channel downmixing. |
312 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); | 360 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); |
313 | 361 |
314 } // namespace media | 362 } // namespace media |
OLD | NEW |