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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 350 } |
350 | 351 |
351 int16 test_array[arraysize(kTestVectorInt16)]; | 352 int16 test_array[arraysize(kTestVectorInt16)]; |
352 expected->ToInterleavedPartial( | 353 expected->ToInterleavedPartial( |
353 kPartialStart, kPartialFrames, sizeof(*kTestVectorInt16), test_array); | 354 kPartialStart, kPartialFrames, sizeof(*kTestVectorInt16), test_array); |
354 ASSERT_EQ(memcmp( | 355 ASSERT_EQ(memcmp( |
355 test_array, kTestVectorInt16 + kPartialStart * kTestVectorChannels, | 356 test_array, kTestVectorInt16 + kPartialStart * kTestVectorChannels, |
356 kPartialFrames * sizeof(*kTestVectorInt16) * kTestVectorChannels), 0); | 357 kPartialFrames * sizeof(*kTestVectorInt16) * kTestVectorChannels), 0); |
357 } | 358 } |
358 | 359 |
| 360 |
| 361 // Benchmark the FromInterleaved() and ToInterleaved() methods. |
| 362 TEST_F(AudioBusTest, DISABLED_InterleaveBench) { |
| 363 scoped_ptr<AudioBus> bus = AudioBus::Create(2, 48000 * 120); |
| 364 const int frame_size = bus->frames() * bus->channels(); |
| 365 FakeAudioRenderCallback callback(0.2); |
| 366 callback.Render(bus.get(), 0); |
| 367 { |
| 368 SCOPED_TRACE("uint8"); |
| 369 scoped_ptr<uint8> interleaved(new uint8[frame_size]); |
| 370 const int byte_size = sizeof(*interleaved); |
| 371 |
| 372 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 373 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
| 374 double total_time_ms = |
| 375 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 376 printf("ToInterleaved uint8 took %.2fms.\n", total_time_ms); |
| 377 |
| 378 start = base::TimeTicks::HighResNow(); |
| 379 bus->FromInterleaved(interleaved.get(), bus->frames(), byte_size); |
| 380 total_time_ms = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 381 printf("FromInterleaved uint8 took %.2fms.\n", total_time_ms); |
| 382 } |
| 383 { |
| 384 SCOPED_TRACE("int16"); |
| 385 scoped_ptr<int16> interleaved(new int16[frame_size]); |
| 386 const int byte_size = sizeof(*interleaved); |
| 387 |
| 388 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 389 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
| 390 double total_time_ms = |
| 391 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 392 printf("ToInterleaved int16 took %.2fms.\n", total_time_ms); |
| 393 |
| 394 start = base::TimeTicks::HighResNow(); |
| 395 bus->FromInterleaved(interleaved.get(), bus->frames(), byte_size); |
| 396 total_time_ms = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 397 printf("FromInterleaved int16 took %.2fms.\n", total_time_ms); |
| 398 } |
| 399 { |
| 400 SCOPED_TRACE("int32"); |
| 401 scoped_ptr<int32> interleaved(new int32[frame_size]); |
| 402 const int byte_size = sizeof(*interleaved); |
| 403 |
| 404 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 405 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
| 406 double total_time_ms = |
| 407 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 408 printf("ToInterleaved int32 took %.2fms.\n", total_time_ms); |
| 409 |
| 410 start = base::TimeTicks::HighResNow(); |
| 411 bus->FromInterleaved(interleaved.get(), bus->frames(), byte_size); |
| 412 total_time_ms = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 413 printf("FromInterleaved int32 took %.2fms.\n", total_time_ms); |
| 414 } |
| 415 } |
| 416 |
359 } // namespace media | 417 } // namespace media |
OLD | NEW |