| 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 // Modified from the Chromium original: | 11 // Modified from the Chromium original: |
| 12 // src/media/base/sinc_resampler_unittest.cc | 12 // src/media/base/sinc_resampler_unittest.cc |
| 13 | 13 |
| 14 // MSVC++ requires this to be set before any other includes to get M_PI. | 14 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 15 #define _USE_MATH_DEFINES | 15 #define _USE_MATH_DEFINES |
| 16 | 16 |
| 17 #include <math.h> | 17 #include <math.h> |
| 18 | 18 |
| 19 #include <memory> | 19 #include <memory> |
| 20 | 20 |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "webrtc/base/timeutils.h" |
| 23 #include "webrtc/common_audio/resampler/sinc_resampler.h" | 24 #include "webrtc/common_audio/resampler/sinc_resampler.h" |
| 24 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" | 25 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" |
| 25 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 26 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
| 26 #include "webrtc/system_wrappers/include/stringize_macros.h" | 27 #include "webrtc/system_wrappers/include/stringize_macros.h" |
| 27 #include "webrtc/system_wrappers/include/tick_util.h" | |
| 28 #include "webrtc/test/test_suite.h" | 28 #include "webrtc/test/test_suite.h" |
| 29 | 29 |
| 30 using testing::_; | 30 using testing::_; |
| 31 | 31 |
| 32 namespace webrtc { | 32 namespace webrtc { |
| 33 | 33 |
| 34 static const double kSampleRateRatio = 192000.0 / 44100.0; | 34 static const double kSampleRateRatio = 192000.0 / 44100.0; |
| 35 static const double kKernelInterpolationFactor = 0.5; | 35 static const double kKernelInterpolationFactor = 0.5; |
| 36 | 36 |
| 37 // Helper class to ensure ChunkedResample() functions properly. | 37 // Helper class to ensure ChunkedResample() functions properly. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 for (size_t i = 0; i < resampler.ChunkSize() / 2; ++i) | 100 for (size_t i = 0; i < resampler.ChunkSize() / 2; ++i) |
| 101 ASSERT_FLOAT_EQ(resampled_destination[i], 0); | 101 ASSERT_FLOAT_EQ(resampled_destination[i], 0); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Test flush resets the internal state properly. | 104 // Test flush resets the internal state properly. |
| 105 TEST(SincResamplerTest, DISABLED_SetRatioBench) { | 105 TEST(SincResamplerTest, DISABLED_SetRatioBench) { |
| 106 MockSource mock_source; | 106 MockSource mock_source; |
| 107 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, | 107 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, |
| 108 &mock_source); | 108 &mock_source); |
| 109 | 109 |
| 110 TickTime start = TickTime::Now(); | 110 int64_t start = rtc::TimeNanos(); |
| 111 for (int i = 1; i < 10000; ++i) | 111 for (int i = 1; i < 10000; ++i) |
| 112 resampler.SetRatio(1.0 / i); | 112 resampler.SetRatio(1.0 / i); |
| 113 double total_time_c_us = (TickTime::Now() - start).Microseconds(); | 113 double total_time_c_us = |
| 114 (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; |
| 114 printf("SetRatio() took %.2fms.\n", total_time_c_us / 1000); | 115 printf("SetRatio() took %.2fms.\n", total_time_c_us / 1000); |
| 115 } | 116 } |
| 116 | 117 |
| 117 | 118 |
| 118 // Define platform independent function name for Convolve* tests. | 119 // Define platform independent function name for Convolve* tests. |
| 119 #if defined(WEBRTC_ARCH_X86_FAMILY) | 120 #if defined(WEBRTC_ARCH_X86_FAMILY) |
| 120 #define CONVOLVE_FUNC Convolve_SSE | 121 #define CONVOLVE_FUNC Convolve_SSE |
| 121 #elif defined(WEBRTC_ARCH_ARM_V7) | 122 #elif defined(WEBRTC_ARCH_ARM_V7) |
| 122 #define CONVOLVE_FUNC Convolve_NEON | 123 #define CONVOLVE_FUNC Convolve_NEON |
| 123 #endif | 124 #endif |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, | 173 SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, |
| 173 &mock_source); | 174 &mock_source); |
| 174 | 175 |
| 175 // Retrieve benchmark iterations from command line. | 176 // Retrieve benchmark iterations from command line. |
| 176 // TODO(ajm): Reintroduce this as a command line option. | 177 // TODO(ajm): Reintroduce this as a command line option. |
| 177 const int kConvolveIterations = 1000000; | 178 const int kConvolveIterations = 1000000; |
| 178 | 179 |
| 179 printf("Benchmarking %d iterations:\n", kConvolveIterations); | 180 printf("Benchmarking %d iterations:\n", kConvolveIterations); |
| 180 | 181 |
| 181 // Benchmark Convolve_C(). | 182 // Benchmark Convolve_C(). |
| 182 TickTime start = TickTime::Now(); | 183 int64_t start = rtc::TimeNanos(); |
| 183 for (int i = 0; i < kConvolveIterations; ++i) { | 184 for (int i = 0; i < kConvolveIterations; ++i) { |
| 184 resampler.Convolve_C( | 185 resampler.Convolve_C( |
| 185 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), | 186 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
| 186 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | 187 resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| 187 } | 188 } |
| 188 double total_time_c_us = (TickTime::Now() - start).Microseconds(); | 189 double total_time_c_us = |
| 190 (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; |
| 189 printf("Convolve_C took %.2fms.\n", total_time_c_us / 1000); | 191 printf("Convolve_C took %.2fms.\n", total_time_c_us / 1000); |
| 190 | 192 |
| 191 #if defined(CONVOLVE_FUNC) | 193 #if defined(CONVOLVE_FUNC) |
| 192 #if defined(WEBRTC_ARCH_X86_FAMILY) | 194 #if defined(WEBRTC_ARCH_X86_FAMILY) |
| 193 ASSERT_TRUE(WebRtc_GetCPUInfo(kSSE2)); | 195 ASSERT_TRUE(WebRtc_GetCPUInfo(kSSE2)); |
| 194 #elif defined(WEBRTC_ARCH_ARM_V7) | 196 #elif defined(WEBRTC_ARCH_ARM_V7) |
| 195 ASSERT_TRUE(WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON); | 197 ASSERT_TRUE(WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON); |
| 196 #endif | 198 #endif |
| 197 | 199 |
| 198 // Benchmark with unaligned input pointer. | 200 // Benchmark with unaligned input pointer. |
| 199 start = TickTime::Now(); | 201 start = rtc::TimeNanos(); |
| 200 for (int j = 0; j < kConvolveIterations; ++j) { | 202 for (int j = 0; j < kConvolveIterations; ++j) { |
| 201 resampler.CONVOLVE_FUNC( | 203 resampler.CONVOLVE_FUNC( |
| 202 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), | 204 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), |
| 203 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | 205 resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| 204 } | 206 } |
| 205 double total_time_optimized_unaligned_us = | 207 double total_time_optimized_unaligned_us = |
| 206 (TickTime::Now() - start).Microseconds(); | 208 (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; |
| 207 printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx " | 209 printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx " |
| 208 "faster than Convolve_C.\n", total_time_optimized_unaligned_us / 1000, | 210 "faster than Convolve_C.\n", total_time_optimized_unaligned_us / 1000, |
| 209 total_time_c_us / total_time_optimized_unaligned_us); | 211 total_time_c_us / total_time_optimized_unaligned_us); |
| 210 | 212 |
| 211 // Benchmark with aligned input pointer. | 213 // Benchmark with aligned input pointer. |
| 212 start = TickTime::Now(); | 214 start = rtc::TimeNanos(); |
| 213 for (int j = 0; j < kConvolveIterations; ++j) { | 215 for (int j = 0; j < kConvolveIterations; ++j) { |
| 214 resampler.CONVOLVE_FUNC( | 216 resampler.CONVOLVE_FUNC( |
| 215 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), | 217 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
| 216 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | 218 resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| 217 } | 219 } |
| 218 double total_time_optimized_aligned_us = | 220 double total_time_optimized_aligned_us = |
| 219 (TickTime::Now() - start).Microseconds(); | 221 (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; |
| 220 printf(STRINGIZE(CONVOLVE_FUNC) " (aligned) took %.2fms; which is %.2fx " | 222 printf(STRINGIZE(CONVOLVE_FUNC) " (aligned) took %.2fms; which is %.2fx " |
| 221 "faster than Convolve_C and %.2fx faster than " | 223 "faster than Convolve_C and %.2fx faster than " |
| 222 STRINGIZE(CONVOLVE_FUNC) " (unaligned).\n", | 224 STRINGIZE(CONVOLVE_FUNC) " (unaligned).\n", |
| 223 total_time_optimized_aligned_us / 1000, | 225 total_time_optimized_aligned_us / 1000, |
| 224 total_time_c_us / total_time_optimized_aligned_us, | 226 total_time_c_us / total_time_optimized_aligned_us, |
| 225 total_time_optimized_unaligned_us / total_time_optimized_aligned_us); | 227 total_time_optimized_unaligned_us / total_time_optimized_aligned_us); |
| 226 #endif | 228 #endif |
| 227 } | 229 } |
| 228 | 230 |
| 229 #undef CONVOLVE_FUNC | 231 #undef CONVOLVE_FUNC |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), | 383 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), |
| 382 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), | 384 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), |
| 383 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), | 385 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), |
| 384 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), | 386 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), |
| 385 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), | 387 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), |
| 386 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), | 388 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), |
| 387 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), | 389 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), |
| 388 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); | 390 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); |
| 389 | 391 |
| 390 } // namespace webrtc | 392 } // namespace webrtc |
| OLD | NEW |