| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 kSampleRateRatio, SincResampler::kDefaultRequestSize, | 144 kSampleRateRatio, SincResampler::kDefaultRequestSize, |
| 145 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); | 145 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); |
| 146 | 146 |
| 147 base::TimeTicks start = base::TimeTicks::Now(); | 147 base::TimeTicks start = base::TimeTicks::Now(); |
| 148 for (int i = 1; i < 10000; ++i) | 148 for (int i = 1; i < 10000; ++i) |
| 149 resampler.SetRatio(1.0 / i); | 149 resampler.SetRatio(1.0 / i); |
| 150 double total_time_c_ms = (base::TimeTicks::Now() - start).InMillisecondsF(); | 150 double total_time_c_ms = (base::TimeTicks::Now() - start).InMillisecondsF(); |
| 151 printf("SetRatio() took %.2fms.\n", total_time_c_ms); | 151 printf("SetRatio() took %.2fms.\n", total_time_c_ms); |
| 152 } | 152 } |
| 153 | 153 |
| 154 | |
| 155 // Define platform independent function name for Convolve* tests. | |
| 156 #if defined(ARCH_CPU_X86_FAMILY) | |
| 157 #define CONVOLVE_FUNC Convolve_SSE | |
| 158 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | |
| 159 #define CONVOLVE_FUNC Convolve_NEON | |
| 160 #endif | |
| 161 | |
| 162 // Ensure various optimized Convolve() methods return the same value. Only run | |
| 163 // this test if other optimized methods exist, otherwise the default Convolve() | |
| 164 // will be tested by the parameterized SincResampler tests below. | |
| 165 #if defined(CONVOLVE_FUNC) | |
| 166 static const double kKernelInterpolationFactor = 0.5; | |
| 167 | |
| 168 TEST(SincResamplerTest, Convolve) { | |
| 169 // Initialize a dummy resampler. | |
| 170 MockSource mock_source; | |
| 171 SincResampler resampler( | |
| 172 kSampleRateRatio, SincResampler::kDefaultRequestSize, | |
| 173 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); | |
| 174 | |
| 175 // The optimized Convolve methods are slightly more precise than Convolve_C(), | |
| 176 // so comparison must be done using an epsilon. | |
| 177 static const double kEpsilon = 0.00000005; | |
| 178 | |
| 179 // Use a kernel from SincResampler as input and kernel data, this has the | |
| 180 // benefit of already being properly sized and aligned for Convolve_SSE(). | |
| 181 double result = resampler.Convolve_C( | |
| 182 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), | |
| 183 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | |
| 184 double result2 = resampler.CONVOLVE_FUNC( | |
| 185 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), | |
| 186 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | |
| 187 EXPECT_NEAR(result2, result, kEpsilon); | |
| 188 | |
| 189 // Test Convolve() w/ unaligned input pointer. | |
| 190 result = resampler.Convolve_C( | |
| 191 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), | |
| 192 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | |
| 193 result2 = resampler.CONVOLVE_FUNC( | |
| 194 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), | |
| 195 resampler.kernel_storage_.get(), kKernelInterpolationFactor); | |
| 196 EXPECT_NEAR(result2, result, kEpsilon); | |
| 197 } | |
| 198 #endif | |
| 199 | |
| 200 // Fake audio source for testing the resampler. Generates a sinusoidal linear | 154 // Fake audio source for testing the resampler. Generates a sinusoidal linear |
| 201 // chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the | 155 // chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the |
| 202 // resampler for the specific sample rate conversion being used. | 156 // resampler for the specific sample rate conversion being used. |
| 203 class SinusoidalLinearChirpSource { | 157 class SinusoidalLinearChirpSource { |
| 204 public: | 158 public: |
| 205 SinusoidalLinearChirpSource(int sample_rate, | 159 SinusoidalLinearChirpSource(int sample_rate, |
| 206 int samples, | 160 int samples, |
| 207 double max_frequency) | 161 double max_frequency) |
| 208 : sample_rate_(sample_rate), | 162 : sample_rate_(sample_rate), |
| 209 total_samples_(samples), | 163 total_samples_(samples), |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), | 357 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), |
| 404 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), | 358 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), |
| 405 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), | 359 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), |
| 406 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), | 360 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), |
| 407 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), | 361 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), |
| 408 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), | 362 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), |
| 409 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), | 363 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), |
| 410 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); | 364 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); |
| 411 | 365 |
| 412 } // namespace media | 366 } // namespace media |
| OLD | NEW |