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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 base::Time::kMicrosecondsPerSecond / input_sample_rate); | 198 base::Time::kMicrosecondsPerSecond / input_sample_rate); |
199 | 199 |
200 int expected_last_delay_milliseconds = | 200 int expected_last_delay_milliseconds = |
201 fill_count * input_parameters.frames_per_buffer() * | 201 fill_count * input_parameters.frames_per_buffer() * |
202 input_frame_duration.InMillisecondsF(); | 202 input_frame_duration.InMillisecondsF(); |
203 | 203 |
204 EXPECT_EQ(expected_last_delay_milliseconds, | 204 EXPECT_EQ(expected_last_delay_milliseconds, |
205 callback.last_audio_delay_milliseconds()); | 205 callback.last_audio_delay_milliseconds()); |
206 } | 206 } |
207 | 207 |
208 // InputCallback that zero's out the provided AudioBus. Used for benchmarking. | |
209 class NullInputProvider : public AudioConverter::InputCallback { | |
210 public: | |
211 NullInputProvider() {} | |
212 virtual ~NullInputProvider() {} | |
213 | |
214 virtual double ProvideInput(AudioBus* audio_bus, | |
215 base::TimeDelta buffer_delay) OVERRIDE { | |
216 audio_bus->Zero(); | |
217 return 1; | |
218 } | |
219 }; | |
220 | |
208 // Benchmark for audio conversion. Original benchmarks were run with | 221 // Benchmark for audio conversion. Original benchmarks were run with |
209 // --audio-converter-iterations=50000. | 222 // --audio-converter-iterations=50000. |
210 TEST(AudioConverterTest, ConvertBenchmark) { | 223 TEST(AudioConverterTest, ConvertBenchmark) { |
211 int benchmark_iterations = kDefaultIterations; | 224 int benchmark_iterations = kDefaultIterations; |
212 std::string iterations(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 225 std::string iterations(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
213 kBenchmarkIterations)); | 226 kBenchmarkIterations)); |
214 base::StringToInt(iterations, &benchmark_iterations); | 227 base::StringToInt(iterations, &benchmark_iterations); |
215 if (benchmark_iterations < kDefaultIterations) | 228 if (benchmark_iterations < kDefaultIterations) |
216 benchmark_iterations = kDefaultIterations; | 229 benchmark_iterations = kDefaultIterations; |
217 | 230 |
218 // Create input and output parameters to convert between the two most common | 231 NullInputProvider fake_input1; |
219 // sets of parameters (as indicated via UMA data). | 232 NullInputProvider fake_input2; |
220 AudioParameters input_params( | 233 NullInputProvider fake_input3; |
221 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 48000, 16, 2048); | |
222 AudioParameters output_params( | |
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); | |
228 FakeAudioRenderCallback fake_input1(0.2); | |
DaleCurtis
2013/04/27 01:18:46
Turns out these are pretty slow and vary depending
| |
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 | 234 |
235 printf("Benchmarking %d iterations:\n", benchmark_iterations); | 235 printf("Benchmarking %d iterations:\n", benchmark_iterations); |
236 | 236 |
237 // Benchmark Convert() w/ FIFO. | 237 { |
238 base::TimeTicks start = base::TimeTicks::HighResNow(); | 238 // Create input and output parameters to convert between the two most common |
239 for (int i = 0; i < benchmark_iterations; ++i) { | 239 // sets of parameters (as indicated via UMA data). |
240 converter->Convert(output_bus.get()); | 240 AudioParameters input_params( |
241 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | |
242 48000, 16, 2048); | |
243 AudioParameters output_params( | |
244 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | |
245 44100, 16, 440); | |
246 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); | |
247 | |
248 scoped_ptr<AudioConverter> converter( | |
249 new AudioConverter(input_params, output_params, true)); | |
250 converter->AddInput(&fake_input1); | |
251 converter->AddInput(&fake_input2); | |
252 converter->AddInput(&fake_input3); | |
253 | |
254 // Benchmark Convert() w/ FIFO. | |
255 base::TimeTicks start = base::TimeTicks::HighResNow(); | |
256 for (int i = 0; i < benchmark_iterations; ++i) { | |
257 converter->Convert(output_bus.get()); | |
258 } | |
259 double total_time_ms = | |
260 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
261 printf("Convert() w/ Resampling took %.2fms.\n", total_time_ms); | |
241 } | 262 } |
242 double total_time_ms = | |
243 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
244 printf("Convert() w/ FIFO took %.2fms.\n", total_time_ms); | |
245 | 263 |
246 converter.reset(new AudioConverter(input_params, output_params, true)); | 264 // Create input and output parameters to convert between common buffer sizes |
247 converter->AddInput(&fake_input1); | 265 // without any resampling for the FIFO vs no FIFO benchmarks. |
248 converter->AddInput(&fake_input2); | 266 AudioParameters input_params( |
249 converter->AddInput(&fake_input3); | 267 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
268 44100, 16, 2048); | |
269 AudioParameters output_params( | |
270 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | |
271 44100, 16, 440); | |
272 scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_params); | |
250 | 273 |
251 // Benchmark Convert() w/o FIFO. | 274 { |
252 start = base::TimeTicks::HighResNow(); | 275 scoped_ptr<AudioConverter> converter( |
253 for (int i = 0; i < benchmark_iterations; ++i) { | 276 new AudioConverter(input_params, output_params, false)); |
254 converter->Convert(output_bus.get()); | 277 converter->AddInput(&fake_input1); |
278 converter->AddInput(&fake_input2); | |
279 converter->AddInput(&fake_input3); | |
280 | |
281 // Benchmark Convert() w/ FIFO. | |
282 base::TimeTicks start = base::TimeTicks::HighResNow(); | |
283 for (int i = 0; i < benchmark_iterations; ++i) { | |
284 converter->Convert(output_bus.get()); | |
285 } | |
286 double total_time_ms = | |
287 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
288 printf("Convert() w/ FIFO took %.2fms.\n", total_time_ms); | |
255 } | 289 } |
256 total_time_ms = | 290 |
257 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | 291 { |
258 printf("Convert() w/o FIFO took %.2fms.\n", total_time_ms); | 292 scoped_ptr<AudioConverter> converter( |
293 new AudioConverter(input_params, output_params, true)); | |
294 converter->AddInput(&fake_input1); | |
295 converter->AddInput(&fake_input2); | |
296 converter->AddInput(&fake_input3); | |
297 | |
298 // Benchmark Convert() w/o FIFO. | |
299 base::TimeTicks start = base::TimeTicks::HighResNow(); | |
300 for (int i = 0; i < benchmark_iterations; ++i) { | |
301 converter->Convert(output_bus.get()); | |
302 } | |
303 double total_time_ms = | |
304 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
305 printf("Convert() w/o FIFO took %.2fms.\n", total_time_ms); | |
306 } | |
259 } | 307 } |
260 | 308 |
261 TEST_P(AudioConverterTest, NoInputs) { | 309 TEST_P(AudioConverterTest, NoInputs) { |
262 FillAudioData(1.0f); | 310 FillAudioData(1.0f); |
263 EXPECT_TRUE(RenderAndValidateAudioData(0.0f)); | 311 EXPECT_TRUE(RenderAndValidateAudioData(0.0f)); |
264 } | 312 } |
265 | 313 |
266 TEST_P(AudioConverterTest, OneInput) { | 314 TEST_P(AudioConverterTest, OneInput) { |
267 RunTest(1); | 315 RunTest(1); |
268 } | 316 } |
269 | 317 |
270 TEST_P(AudioConverterTest, ManyInputs) { | 318 TEST_P(AudioConverterTest, ManyInputs) { |
271 RunTest(kConvertInputs); | 319 RunTest(kConvertInputs); |
272 } | 320 } |
273 | 321 |
274 INSTANTIATE_TEST_CASE_P( | 322 INSTANTIATE_TEST_CASE_P( |
275 // TODO(dalecurtis): Add test cases for channel transforms. | 323 // TODO(dalecurtis): Add test cases for channel transforms. |
276 AudioConverterTest, AudioConverterTest, testing::Values( | 324 AudioConverterTest, AudioConverterTest, testing::Values( |
277 // No resampling. | 325 // No resampling. |
278 std::tr1::make_tuple(44100, 44100, 0.00000048), | 326 std::tr1::make_tuple(44100, 44100, 0.00000048), |
279 | 327 |
280 // Upsampling. | 328 // Upsampling. |
281 std::tr1::make_tuple(44100, 48000, 0.033), | 329 std::tr1::make_tuple(44100, 48000, 0.033), |
282 | 330 |
283 // Downsampling. | 331 // Downsampling. |
284 std::tr1::make_tuple(48000, 41000, 0.042))); | 332 std::tr1::make_tuple(48000, 41000, 0.042))); |
285 | 333 |
286 } // namespace media | 334 } // namespace media |
OLD | NEW |