| 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
| 10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| 11 #include "media/base/channel_layout.h" | 11 #include "media/base/channel_layout.h" |
| 12 #include "media/base/fake_audio_render_callback.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 | 16 |
| 16 static const int kChannels = 6; | 17 static const int kChannels = 6; |
| 17 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_5_1; | 18 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_5_1; |
| 18 // Use a buffer size which is intentionally not a multiple of kChannelAlignment. | 19 // Use a buffer size which is intentionally not a multiple of kChannelAlignment. |
| 19 static const int kFrameCount = media::AudioBus::kChannelAlignment * 32 - 1; | 20 static const int kFrameCount = media::AudioBus::kChannelAlignment * 32 - 1; |
| 20 static const int kSampleRate = 48000; | 21 static const int kSampleRate = 48000; |
| 21 | 22 |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } | 381 } |
| 381 | 382 |
| 382 // Verify zero volume case. | 383 // Verify zero volume case. |
| 383 bus->Scale(0); | 384 bus->Scale(0); |
| 384 for (int i = 0; i < bus->channels(); ++i) { | 385 for (int i = 0; i < bus->channels(); ++i) { |
| 385 SCOPED_TRACE("Zero Scale"); | 386 SCOPED_TRACE("Zero Scale"); |
| 386 VerifyValue(bus->channel(i), bus->frames(), 0); | 387 VerifyValue(bus->channel(i), bus->frames(), 0); |
| 387 } | 388 } |
| 388 } | 389 } |
| 389 | 390 |
| 391 // Benchmark the FromInterleaved() and ToInterleaved() methods. |
| 392 TEST_F(AudioBusTest, DISABLED_InterleaveBench) { |
| 393 scoped_ptr<AudioBus> bus = AudioBus::Create(2, 48000 * 120); |
| 394 const int frame_size = bus->frames() * bus->channels(); |
| 395 FakeAudioRenderCallback callback(0.2); |
| 396 callback.Render(bus.get(), 0); |
| 397 { |
| 398 SCOPED_TRACE("uint8"); |
| 399 scoped_ptr<uint8> interleaved(new uint8[frame_size]); |
| 400 const int byte_size = sizeof(*interleaved); |
| 401 |
| 402 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 403 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
| 404 double total_time_ms = |
| 405 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 406 printf("ToInterleaved uint8 took %.2fms.\n", total_time_ms); |
| 407 |
| 408 start = base::TimeTicks::HighResNow(); |
| 409 bus->FromInterleaved(interleaved.get(), bus->frames(), byte_size); |
| 410 total_time_ms = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 411 printf("FromInterleaved uint8 took %.2fms.\n", total_time_ms); |
| 412 } |
| 413 { |
| 414 SCOPED_TRACE("int16"); |
| 415 scoped_ptr<int16> interleaved(new int16[frame_size]); |
| 416 const int byte_size = sizeof(*interleaved); |
| 417 |
| 418 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 419 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
| 420 double total_time_ms = |
| 421 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 422 printf("ToInterleaved int16 took %.2fms.\n", total_time_ms); |
| 423 |
| 424 start = base::TimeTicks::HighResNow(); |
| 425 bus->FromInterleaved(interleaved.get(), bus->frames(), byte_size); |
| 426 total_time_ms = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 427 printf("FromInterleaved int16 took %.2fms.\n", total_time_ms); |
| 428 } |
| 429 { |
| 430 SCOPED_TRACE("int32"); |
| 431 scoped_ptr<int32> interleaved(new int32[frame_size]); |
| 432 const int byte_size = sizeof(*interleaved); |
| 433 |
| 434 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 435 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
| 436 double total_time_ms = |
| 437 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 438 printf("ToInterleaved int32 took %.2fms.\n", total_time_ms); |
| 439 |
| 440 start = base::TimeTicks::HighResNow(); |
| 441 bus->FromInterleaved(interleaved.get(), bus->frames(), byte_size); |
| 442 total_time_ms = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 443 printf("FromInterleaved int32 took %.2fms.\n", total_time_ms); |
| 444 } |
| 445 } |
| 446 |
| 390 } // namespace media | 447 } // namespace media |
| OLD | NEW |