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" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 // Flush and request more data, which should all be zeros now. | 91 // Flush and request more data, which should all be zeros now. |
92 resampler.Flush(); | 92 resampler.Flush(); |
93 testing::Mock::VerifyAndClear(&mock_source); | 93 testing::Mock::VerifyAndClear(&mock_source); |
94 EXPECT_CALL(mock_source, ProvideInput(_, _)) | 94 EXPECT_CALL(mock_source, ProvideInput(_, _)) |
95 .Times(1).WillOnce(ClearBuffer()); | 95 .Times(1).WillOnce(ClearBuffer()); |
96 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); | 96 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); |
97 for (int i = 0; i < resampler.ChunkSize() / 2; ++i) | 97 for (int i = 0; i < resampler.ChunkSize() / 2; ++i) |
98 ASSERT_FLOAT_EQ(resampled_destination[i], 0); | 98 ASSERT_FLOAT_EQ(resampled_destination[i], 0); |
99 } | 99 } |
100 | 100 |
101 // Test flush resets the internal state properly. | |
102 TEST(SincResamplerTest, DISABLED_SetRatioBench) { | |
103 MockSource mock_source; | |
104 SincResampler resampler( | |
105 kSampleRateRatio, | |
106 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); | |
107 | |
108 base::TimeTicks start = base::TimeTicks::HighResNow(); | |
109 for (int i = 1; i < 10000; ++i) | |
110 resampler.SetRatio(0.5); | |
Chris Rogers
2013/04/16 21:36:23
If you do optimization to return early if ratio is
DaleCurtis
2013/04/16 22:29:26
Done.
| |
111 double total_time_c_ms = | |
112 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); | |
113 printf("SetRatio() took %.2fms.\n", total_time_c_ms); | |
114 } | |
115 | |
116 | |
101 // Define platform independent function name for Convolve* tests. | 117 // Define platform independent function name for Convolve* tests. |
102 #if defined(ARCH_CPU_X86_FAMILY) | 118 #if defined(ARCH_CPU_X86_FAMILY) |
103 #define CONVOLVE_FUNC Convolve_SSE | 119 #define CONVOLVE_FUNC Convolve_SSE |
104 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | 120 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) |
105 #define CONVOLVE_FUNC Convolve_NEON | 121 #define CONVOLVE_FUNC Convolve_NEON |
106 #endif | 122 #endif |
107 | 123 |
108 // Ensure various optimized Convolve() methods return the same value. Only run | 124 // Ensure various optimized Convolve() methods return the same value. Only run |
109 // this test if other optimized methods exist, otherwise the default Convolve() | 125 // this test if other optimized methods exist, otherwise the default Convolve() |
110 // will be tested by the parameterized SincResampler tests below. | 126 // will be tested by the parameterized SincResampler tests below. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 int input_samples = kTestDurationSecs * input_rate_; | 308 int input_samples = kTestDurationSecs * input_rate_; |
293 int output_samples = kTestDurationSecs * output_rate_; | 309 int output_samples = kTestDurationSecs * output_rate_; |
294 | 310 |
295 // Nyquist frequency for the input sampling rate. | 311 // Nyquist frequency for the input sampling rate. |
296 double input_nyquist_freq = 0.5 * input_rate_; | 312 double input_nyquist_freq = 0.5 * input_rate_; |
297 | 313 |
298 // Source for data to be resampled. | 314 // Source for data to be resampled. |
299 SinusoidalLinearChirpSource resampler_source( | 315 SinusoidalLinearChirpSource resampler_source( |
300 input_rate_, input_samples, input_nyquist_freq); | 316 input_rate_, input_samples, input_nyquist_freq); |
301 | 317 |
318 const double io_ratio = input_rate_ / static_cast<double>(output_rate_); | |
302 SincResampler resampler( | 319 SincResampler resampler( |
303 input_rate_ / static_cast<double>(output_rate_), | 320 io_ratio, |
304 base::Bind(&SinusoidalLinearChirpSource::ProvideInput, | 321 base::Bind(&SinusoidalLinearChirpSource::ProvideInput, |
305 base::Unretained(&resampler_source))); | 322 base::Unretained(&resampler_source))); |
306 | 323 |
324 // Force an update to the sample rate ratio to ensure dyanmic sample rate | |
325 // changes are working correctly. | |
326 scoped_ptr<float> kernel(new float[SincResampler::kKernelStorageSize]); | |
327 memcpy(kernel.get(), resampler.get_kernel_for_testing(), | |
328 SincResampler::kKernelStorageSize); | |
329 resampler.SetRatio(M_PI); | |
330 ASSERT_NE(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(), | |
331 SincResampler::kKernelStorageSize)); | |
332 resampler.SetRatio(io_ratio); | |
333 ASSERT_EQ(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(), | |
334 SincResampler::kKernelStorageSize)); | |
335 | |
307 // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to | 336 // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to |
308 // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes. | 337 // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes. |
309 scoped_ptr<float[]> resampled_destination(new float[output_samples]); | 338 scoped_ptr<float[]> resampled_destination(new float[output_samples]); |
310 scoped_ptr<float[]> pure_destination(new float[output_samples]); | 339 scoped_ptr<float[]> pure_destination(new float[output_samples]); |
311 | 340 |
312 // Generate resampled signal. | 341 // Generate resampled signal. |
313 resampler.Resample(resampled_destination.get(), output_samples); | 342 resampler.Resample(resampled_destination.get(), output_samples); |
314 | 343 |
315 // Generate pure signal. | 344 // Generate pure signal. |
316 SinusoidalLinearChirpSource pure_source( | 345 SinusoidalLinearChirpSource pure_source( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), | 434 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), |
406 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), | 435 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), |
407 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), | 436 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), |
408 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), | 437 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), |
409 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), | 438 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), |
410 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), | 439 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), |
411 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), | 440 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), |
412 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); | 441 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); |
413 | 442 |
414 } // namespace media | 443 } // namespace media |
OLD | NEW |