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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/cpu.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
15 #include "base/strings/stringize_macros.h" | 16 #include "base/strings/stringize_macros.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "media/base/sinc_resampler.h" | 19 #include "media/base/sinc_resampler.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using testing::_; | 23 using testing::_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 resampler.Flush(); | 92 resampler.Flush(); |
92 testing::Mock::VerifyAndClear(&mock_source); | 93 testing::Mock::VerifyAndClear(&mock_source); |
93 EXPECT_CALL(mock_source, ProvideInput(_, _)) | 94 EXPECT_CALL(mock_source, ProvideInput(_, _)) |
94 .Times(1).WillOnce(ClearBuffer()); | 95 .Times(1).WillOnce(ClearBuffer()); |
95 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); | 96 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); |
96 for (int i = 0; i < resampler.ChunkSize() / 2; ++i) | 97 for (int i = 0; i < resampler.ChunkSize() / 2; ++i) |
97 ASSERT_FLOAT_EQ(resampled_destination[i], 0); | 98 ASSERT_FLOAT_EQ(resampled_destination[i], 0); |
98 } | 99 } |
99 | 100 |
100 // Define platform independent function name for Convolve* tests. | 101 // Define platform independent function name for Convolve* tests. |
101 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) | 102 #if defined(ARCH_CPU_X86_FAMILY) |
102 #define CONVOLVE_FUNC Convolve_SSE | 103 #define CONVOLVE_FUNC Convolve_SSE |
103 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | 104 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) |
104 #define CONVOLVE_FUNC Convolve_NEON | 105 #define CONVOLVE_FUNC Convolve_NEON |
105 #endif | 106 #endif |
106 | 107 |
107 // Ensure various optimized Convolve() methods return the same value. Only run | 108 // Ensure various optimized Convolve() methods return the same value. Only run |
108 // this test if other optimized methods exist, otherwise the default Convolve() | 109 // this test if other optimized methods exist, otherwise the default Convolve() |
109 // will be tested by the parameterized SincResampler tests below. | 110 // will be tested by the parameterized SincResampler tests below. |
110 #if defined(CONVOLVE_FUNC) | 111 #if defined(CONVOLVE_FUNC) |
111 TEST(SincResamplerTest, Convolve) { | 112 TEST(SincResamplerTest, Convolve) { |
| 113 #if defined(ARCH_CPU_X86_FAMILY) |
| 114 ASSERT_TRUE(base::CPU().has_sse()); |
| 115 #endif |
| 116 |
112 // Initialize a dummy resampler. | 117 // Initialize a dummy resampler. |
113 MockSource mock_source; | 118 MockSource mock_source; |
114 SincResampler resampler( | 119 SincResampler resampler( |
115 kSampleRateRatio, | 120 kSampleRateRatio, |
116 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); | 121 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); |
117 | 122 |
118 // The optimized Convolve methods are slightly more precise than Convolve_C(), | 123 // The optimized Convolve methods are slightly more precise than Convolve_C(), |
119 // so comparison must be done using an epsilon. | 124 // so comparison must be done using an epsilon. |
120 static const double kEpsilon = 0.00000005; | 125 static const double kEpsilon = 0.00000005; |
121 | 126 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 for (int i = 0; i < convolve_iterations; ++i) { | 169 for (int i = 0; i < convolve_iterations; ++i) { |
165 resampler.Convolve_C( | 170 resampler.Convolve_C( |
166 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), | 171 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
167 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | 172 resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
168 } | 173 } |
169 double total_time_c_ms = | 174 double total_time_c_ms = |
170 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | 175 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
171 printf("Convolve_C took %.2fms.\n", total_time_c_ms); | 176 printf("Convolve_C took %.2fms.\n", total_time_c_ms); |
172 | 177 |
173 #if defined(CONVOLVE_FUNC) | 178 #if defined(CONVOLVE_FUNC) |
| 179 #if defined(ARCH_CPU_X86_FAMILY) |
| 180 ASSERT_TRUE(base::CPU().has_sse()); |
| 181 #endif |
| 182 |
174 // Benchmark with unaligned input pointer. | 183 // Benchmark with unaligned input pointer. |
175 start = base::TimeTicks::HighResNow(); | 184 start = base::TimeTicks::HighResNow(); |
176 for (int j = 0; j < convolve_iterations; ++j) { | 185 for (int j = 0; j < convolve_iterations; ++j) { |
177 resampler.CONVOLVE_FUNC( | 186 resampler.CONVOLVE_FUNC( |
178 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), | 187 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), |
179 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | 188 resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
180 } | 189 } |
181 double total_time_optimized_unaligned_ms = | 190 double total_time_optimized_unaligned_ms = |
182 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | 191 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
183 printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx " | 192 printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx " |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), | 405 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), |
397 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), | 406 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), |
398 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), | 407 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), |
399 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), | 408 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), |
400 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), | 409 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), |
401 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), | 410 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), |
402 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), | 411 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), |
403 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); | 412 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); |
404 | 413 |
405 } // namespace media | 414 } // namespace media |
OLD | NEW |