OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "media/base/audio_bus.h" | 9 #include "media/base/audio_bus.h" |
10 #include "media/base/fake_audio_render_callback.h" | 10 #include "media/base/fake_audio_render_callback.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "testing/perf/perf_test.h" | 12 #include "testing/perf/perf_test.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 static const int kBenchmarkIterations = 20; | 16 static const int kBenchmarkIterations = 20; |
| 17 static const int kSampleRate = 48000; |
17 | 18 |
18 template <typename T> | 19 template <typename T> |
19 void RunInterleaveBench(AudioBus* bus, const std::string& trace_name) { | 20 void RunInterleaveBench(AudioBus* bus, const std::string& trace_name) { |
20 const int frame_size = bus->frames() * bus->channels(); | 21 const int frame_size = bus->frames() * bus->channels(); |
21 std::unique_ptr<T[]> interleaved(new T[frame_size]); | 22 std::unique_ptr<T[]> interleaved(new T[frame_size]); |
22 const int byte_size = sizeof(T); | 23 const int byte_size = sizeof(T); |
23 | 24 |
24 base::TimeTicks start = base::TimeTicks::Now(); | 25 base::TimeTicks start = base::TimeTicks::Now(); |
25 for (int i = 0; i < kBenchmarkIterations; ++i) { | 26 for (int i = 0; i < kBenchmarkIterations; ++i) { |
26 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); | 27 bus->ToInterleaved(bus->frames(), byte_size, interleaved.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
37 } | 38 } |
38 total_time_milliseconds = | 39 total_time_milliseconds = |
39 (base::TimeTicks::Now() - start).InMillisecondsF(); | 40 (base::TimeTicks::Now() - start).InMillisecondsF(); |
40 perf_test::PrintResult( | 41 perf_test::PrintResult( |
41 "audio_bus_from_interleaved", "", trace_name, | 42 "audio_bus_from_interleaved", "", trace_name, |
42 total_time_milliseconds / kBenchmarkIterations, "ms", true); | 43 total_time_milliseconds / kBenchmarkIterations, "ms", true); |
43 } | 44 } |
44 | 45 |
45 // Benchmark the FromInterleaved() and ToInterleaved() methods. | 46 // Benchmark the FromInterleaved() and ToInterleaved() methods. |
46 TEST(AudioBusPerfTest, Interleave) { | 47 TEST(AudioBusPerfTest, Interleave) { |
47 std::unique_ptr<AudioBus> bus = AudioBus::Create(2, 48000 * 120); | 48 std::unique_ptr<AudioBus> bus = AudioBus::Create(2, kSampleRate * 120); |
48 FakeAudioRenderCallback callback(0.2); | 49 FakeAudioRenderCallback callback(0.2, kSampleRate); |
49 callback.Render(base::TimeDelta(), base::TimeTicks::Now(), 0, bus.get()); | 50 callback.Render(base::TimeDelta(), base::TimeTicks::Now(), 0, bus.get()); |
50 | 51 |
51 RunInterleaveBench<int8_t>(bus.get(), "int8_t"); | 52 RunInterleaveBench<int8_t>(bus.get(), "int8_t"); |
52 RunInterleaveBench<int16_t>(bus.get(), "int16_t"); | 53 RunInterleaveBench<int16_t>(bus.get(), "int16_t"); |
53 RunInterleaveBench<int32_t>(bus.get(), "int32_t"); | 54 RunInterleaveBench<int32_t>(bus.get(), "int32_t"); |
54 } | 55 } |
55 | 56 |
56 } // namespace media | 57 } // namespace media |
OLD | NEW |