| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 base::StringToInt(iterations, &benchmark_iterations); | 214 base::StringToInt(iterations, &benchmark_iterations); |
| 215 if (benchmark_iterations < kDefaultIterations) | 215 if (benchmark_iterations < kDefaultIterations) |
| 216 benchmark_iterations = kDefaultIterations; | 216 benchmark_iterations = kDefaultIterations; |
| 217 | 217 |
| 218 // Create input and output parameters to convert between the two most common | 218 // Create input and output parameters to convert between the two most common |
| 219 // sets of parameters (as indicated via UMA data). | 219 // sets of parameters (as indicated via UMA data). |
| 220 AudioParameters input_params( | 220 AudioParameters input_params( |
| 221 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 48000, 16, 2048); | 221 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 48000, 16, 2048); |
| 222 AudioParameters output_params( | 222 AudioParameters output_params( |
| 223 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 44100, 16, 440); | 223 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 44100, 16, 440); |
| 224 scoped_ptr<AudioConverter> converter( | |
| 225 new AudioConverter(input_params, output_params, false)); | |
| 226 | |
| 227 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); | 224 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); |
| 228 FakeAudioRenderCallback fake_input1(0.2); | |
| 229 FakeAudioRenderCallback fake_input2(0.4); | |
| 230 FakeAudioRenderCallback fake_input3(0.6); | |
| 231 converter->AddInput(&fake_input1); | |
| 232 converter->AddInput(&fake_input2); | |
| 233 converter->AddInput(&fake_input3); | |
| 234 | 225 |
| 235 printf("Benchmarking %d iterations:\n", benchmark_iterations); | 226 printf("Benchmarking %d iterations:\n", benchmark_iterations); |
| 236 | 227 |
| 237 // Benchmark Convert() w/ FIFO. | 228 // Benchmark Convert() w/ FIFO. |
| 238 base::TimeTicks start = base::TimeTicks::HighResNow(); | 229 { |
| 239 for (int i = 0; i < benchmark_iterations; ++i) { | 230 scoped_ptr<AudioConverter> converter( |
| 240 converter->Convert(output_bus.get()); | 231 new AudioConverter(input_params, output_params, false)); |
| 232 |
| 233 FakeAudioRenderCallback fake_input1(0.2); |
| 234 FakeAudioRenderCallback fake_input2(0.4); |
| 235 FakeAudioRenderCallback fake_input3(0.6); |
| 236 converter->AddInput(&fake_input1); |
| 237 converter->AddInput(&fake_input2); |
| 238 converter->AddInput(&fake_input3); |
| 239 |
| 240 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 241 for (int i = 0; i < benchmark_iterations; ++i) { |
| 242 converter->Convert(output_bus.get()); |
| 243 } |
| 244 double total_time_ms = |
| 245 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 246 printf("Convert() w/ FIFO took %.2fms.\n", total_time_ms); |
| 241 } | 247 } |
| 242 double total_time_ms = | |
| 243 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
| 244 printf("Convert() w/ FIFO took %.2fms.\n", total_time_ms); | |
| 245 | 248 |
| 246 converter.reset(new AudioConverter(input_params, output_params, true)); | 249 { |
| 247 converter->AddInput(&fake_input1); | 250 scoped_ptr<AudioConverter> converter( |
| 248 converter->AddInput(&fake_input2); | 251 new AudioConverter(input_params, output_params, true)); |
| 249 converter->AddInput(&fake_input3); | |
| 250 | 252 |
| 251 // Benchmark Convert() w/o FIFO. | 253 FakeAudioRenderCallback fake_input1(0.2); |
| 252 start = base::TimeTicks::HighResNow(); | 254 FakeAudioRenderCallback fake_input2(0.4); |
| 253 for (int i = 0; i < benchmark_iterations; ++i) { | 255 FakeAudioRenderCallback fake_input3(0.6); |
| 254 converter->Convert(output_bus.get()); | 256 converter->AddInput(&fake_input1); |
| 257 converter->AddInput(&fake_input2); |
| 258 converter->AddInput(&fake_input3); |
| 259 |
| 260 // Benchmark Convert() w/o FIFO. |
| 261 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 262 for (int i = 0; i < benchmark_iterations; ++i) { |
| 263 converter->Convert(output_bus.get()); |
| 264 } |
| 265 double total_time_ms = |
| 266 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 267 printf("Convert() w/o FIFO took %.2fms.\n", total_time_ms); |
| 255 } | 268 } |
| 256 total_time_ms = | |
| 257 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
| 258 printf("Convert() w/o FIFO took %.2fms.\n", total_time_ms); | |
| 259 } | 269 } |
| 260 | 270 |
| 261 TEST_P(AudioConverterTest, NoInputs) { | 271 TEST_P(AudioConverterTest, NoInputs) { |
| 262 FillAudioData(1.0f); | 272 FillAudioData(1.0f); |
| 263 EXPECT_TRUE(RenderAndValidateAudioData(0.0f)); | 273 EXPECT_TRUE(RenderAndValidateAudioData(0.0f)); |
| 264 } | 274 } |
| 265 | 275 |
| 266 TEST_P(AudioConverterTest, OneInput) { | 276 TEST_P(AudioConverterTest, OneInput) { |
| 267 RunTest(1); | 277 RunTest(1); |
| 268 } | 278 } |
| 269 | 279 |
| 270 TEST_P(AudioConverterTest, ManyInputs) { | 280 TEST_P(AudioConverterTest, ManyInputs) { |
| 271 RunTest(kConvertInputs); | 281 RunTest(kConvertInputs); |
| 272 } | 282 } |
| 273 | 283 |
| 274 INSTANTIATE_TEST_CASE_P( | 284 INSTANTIATE_TEST_CASE_P( |
| 275 // TODO(dalecurtis): Add test cases for channel transforms. | 285 // TODO(dalecurtis): Add test cases for channel transforms. |
| 276 AudioConverterTest, AudioConverterTest, testing::Values( | 286 AudioConverterTest, AudioConverterTest, testing::Values( |
| 277 // No resampling. | 287 // No resampling. |
| 278 std::tr1::make_tuple(44100, 44100, 0.00000048), | 288 std::tr1::make_tuple(44100, 44100, 0.00000048), |
| 279 | 289 |
| 280 // Upsampling. | 290 // Upsampling. |
| 281 std::tr1::make_tuple(44100, 48000, 0.033), | 291 std::tr1::make_tuple(44100, 48000, 0.033), |
| 282 | 292 |
| 283 // Downsampling. | 293 // Downsampling. |
| 284 std::tr1::make_tuple(48000, 41000, 0.042))); | 294 std::tr1::make_tuple(48000, 41000, 0.042))); |
| 285 | 295 |
| 286 } // namespace media | 296 } // namespace media |
| OLD | NEW |