OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <cmath> | 11 #include <cmath> |
12 #include <cstring> | 12 #include <cstring> |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/timeutils.h" |
17 #include "webrtc/common_audio/include/audio_util.h" | 18 #include "webrtc/common_audio/include/audio_util.h" |
18 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 19 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
19 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" | 20 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" |
20 #include "webrtc/system_wrappers/include/tick_util.h" | |
21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Almost all conversions have an RMS error of around -14 dbFS. | 26 // Almost all conversions have an RMS error of around -14 dbFS. |
27 const double kResamplingRMSError = -14.42; | 27 const double kResamplingRMSError = -14.42; |
28 | 28 |
29 // Used to convert errors to dbFS. | 29 // Used to convert errors to dbFS. |
30 template <typename T> | 30 template <typename T> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 resampler_source.Run(input_samples, source.get()); | 79 resampler_source.Run(input_samples, source.get()); |
80 for (size_t i = 0; i < input_samples; ++i) { | 80 for (size_t i = 0; i < input_samples; ++i) { |
81 source_int[i] = static_cast<int16_t>(floor(32767 * source[i] + 0.5)); | 81 source_int[i] = static_cast<int16_t>(floor(32767 * source[i] + 0.5)); |
82 } | 82 } |
83 | 83 |
84 printf("Benchmarking %d iterations of %d Hz -> %d Hz:\n", | 84 printf("Benchmarking %d iterations of %d Hz -> %d Hz:\n", |
85 kResampleIterations, input_rate_, output_rate_); | 85 kResampleIterations, input_rate_, output_rate_); |
86 const double io_ratio = input_rate_ / static_cast<double>(output_rate_); | 86 const double io_ratio = input_rate_ / static_cast<double>(output_rate_); |
87 SincResampler sinc_resampler(io_ratio, SincResampler::kDefaultRequestSize, | 87 SincResampler sinc_resampler(io_ratio, SincResampler::kDefaultRequestSize, |
88 &resampler_source); | 88 &resampler_source); |
89 TickTime start = TickTime::Now(); | 89 int64_t start = rtc::TimeNanos(); |
90 for (int i = 0; i < kResampleIterations; ++i) { | 90 for (int i = 0; i < kResampleIterations; ++i) { |
91 sinc_resampler.Resample(output_samples, resampled_destination.get()); | 91 sinc_resampler.Resample(output_samples, resampled_destination.get()); |
92 } | 92 } |
93 double total_time_sinc_us = (TickTime::Now() - start).Microseconds(); | 93 double total_time_sinc_us = |
| 94 (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; |
94 printf("SincResampler took %.2f us per frame.\n", | 95 printf("SincResampler took %.2f us per frame.\n", |
95 total_time_sinc_us / kResampleIterations); | 96 total_time_sinc_us / kResampleIterations); |
96 | 97 |
97 PushSincResampler resampler(input_samples, output_samples); | 98 PushSincResampler resampler(input_samples, output_samples); |
98 start = TickTime::Now(); | 99 start = rtc::TimeNanos(); |
99 if (int_format) { | 100 if (int_format) { |
100 for (int i = 0; i < kResampleIterations; ++i) { | 101 for (int i = 0; i < kResampleIterations; ++i) { |
101 EXPECT_EQ(output_samples, | 102 EXPECT_EQ(output_samples, |
102 resampler.Resample(source_int.get(), | 103 resampler.Resample(source_int.get(), |
103 input_samples, | 104 input_samples, |
104 destination_int.get(), | 105 destination_int.get(), |
105 output_samples)); | 106 output_samples)); |
106 } | 107 } |
107 } else { | 108 } else { |
108 for (int i = 0; i < kResampleIterations; ++i) { | 109 for (int i = 0; i < kResampleIterations; ++i) { |
109 EXPECT_EQ(output_samples, | 110 EXPECT_EQ(output_samples, |
110 resampler.Resample(source.get(), | 111 resampler.Resample(source.get(), |
111 input_samples, | 112 input_samples, |
112 resampled_destination.get(), | 113 resampled_destination.get(), |
113 output_samples)); | 114 output_samples)); |
114 } | 115 } |
115 } | 116 } |
116 double total_time_us = (TickTime::Now() - start).Microseconds(); | 117 double total_time_us = |
| 118 (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; |
117 printf("PushSincResampler took %.2f us per frame; which is a %.1f%% overhead " | 119 printf("PushSincResampler took %.2f us per frame; which is a %.1f%% overhead " |
118 "on SincResampler.\n\n", total_time_us / kResampleIterations, | 120 "on SincResampler.\n\n", total_time_us / kResampleIterations, |
119 (total_time_us - total_time_sinc_us) / total_time_sinc_us * 100); | 121 (total_time_us - total_time_sinc_us) / total_time_sinc_us * 100); |
120 } | 122 } |
121 | 123 |
122 // Disabled because it takes too long to run routinely. Use for performance | 124 // Disabled because it takes too long to run routinely. Use for performance |
123 // benchmarking when needed. | 125 // benchmarking when needed. |
124 TEST_P(PushSincResamplerTest, DISABLED_BenchmarkInt) { | 126 TEST_P(PushSincResamplerTest, DISABLED_BenchmarkInt) { |
125 ResampleBenchmarkTest(true); | 127 ResampleBenchmarkTest(true); |
126 } | 128 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // To 32 kHz | 328 // To 32 kHz |
327 ::testing::make_tuple(8000, 32000, kResamplingRMSError, -70.30), | 329 ::testing::make_tuple(8000, 32000, kResamplingRMSError, -70.30), |
328 ::testing::make_tuple(16000, 32000, kResamplingRMSError, -75.51), | 330 ::testing::make_tuple(16000, 32000, kResamplingRMSError, -75.51), |
329 ::testing::make_tuple(32000, 32000, kResamplingRMSError, -75.51), | 331 ::testing::make_tuple(32000, 32000, kResamplingRMSError, -75.51), |
330 ::testing::make_tuple(44100, 32000, -16.44, -51.10), | 332 ::testing::make_tuple(44100, 32000, -16.44, -51.10), |
331 ::testing::make_tuple(48000, 32000, -16.90, -44.03), | 333 ::testing::make_tuple(48000, 32000, -16.90, -44.03), |
332 ::testing::make_tuple(96000, 32000, -19.61, -18.04), | 334 ::testing::make_tuple(96000, 32000, -19.61, -18.04), |
333 ::testing::make_tuple(192000, 32000, -21.02, -10.94))); | 335 ::testing::make_tuple(192000, 32000, -21.02, -10.94))); |
334 | 336 |
335 } // namespace webrtc | 337 } // namespace webrtc |
OLD | NEW |