Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: media/base/sinc_resampler_unittest.cc

Issue 10960023: Add ARM NEON intrinsic optimizations for SincResampler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix NE issue for ARM. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/sinc_resampler.cc ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 13 #include "base/logging.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/stringize_macros.h"
15 #include "base/time.h" 16 #include "base/time.h"
17 #include "build/build_config.h"
16 #include "media/base/sinc_resampler.h" 18 #include "media/base/sinc_resampler.h"
17 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 21
20 using testing::_; 22 using testing::_;
21 23
22 namespace media { 24 namespace media {
23 25
24 static const double kSampleRateRatio = 192000.0 / 44100.0; 26 static const double kSampleRateRatio = 192000.0 / 44100.0;
25 static const double kKernelInterpolationFactor = 0.5; 27 static const double kKernelInterpolationFactor = 0.5;
26 28
27 // Command line switch for runtime adjustment of ConvolveBenchmark iterations. 29 // Command line switch for runtime adjustment of ConvolveBenchmark iterations.
28 static const char kConvolveIterations[] = "convolve-iterations"; 30 static const char kConvolveIterations[] = "convolve-iterations";
29 31
30 // Helper class to ensure ChunkedResample() functions properly. 32 // Helper class to ensure ChunkedResample() functions properly.
31 class MockSource { 33 class MockSource {
32 public: 34 public:
33 MOCK_METHOD2(ProvideInput, void(float* destination, int frames)); 35 MOCK_METHOD2(ProvideInput, void(float* destination, int frames));
34 }; 36 };
35 37
36 ACTION(ClearBuffer) { 38 ACTION(ClearBuffer) {
37 memset(arg0, 0, arg1 * sizeof(float)); 39 memset(arg0, 0, arg1 * sizeof(float));
38 } 40 }
39 41
40 ACTION(FillBuffer) { 42 ACTION(FillBuffer) {
41 memset(arg0, 1, arg1 * sizeof(float)); 43 // Value chosen arbitrarily such that SincResampler resamples it to something
44 // easily representable on all platforms; e.g., using kSampleRateRatio this
45 // becomes 1.81219.
46 memset(arg0, 64, arg1 * sizeof(float));
42 } 47 }
43 48
44 // Test requesting multiples of ChunkSize() frames results in the proper number 49 // Test requesting multiples of ChunkSize() frames results in the proper number
45 // of callbacks. 50 // of callbacks.
46 TEST(SincResamplerTest, ChunkedResample) { 51 TEST(SincResamplerTest, ChunkedResample) {
47 MockSource mock_source; 52 MockSource mock_source;
48 53
49 // Choose a high ratio of input to output samples which will result in quick 54 // Choose a high ratio of input to output samples which will result in quick
50 // exhaustion of SincResampler's internal buffers. 55 // exhaustion of SincResampler's internal buffers.
51 SincResampler resampler( 56 SincResampler resampler(
(...skipping 30 matching lines...) Expand all
82 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); 87 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2);
83 ASSERT_NE(resampled_destination[0], 0); 88 ASSERT_NE(resampled_destination[0], 0);
84 89
85 // Flush and request more data, which should all be zeros now. 90 // Flush and request more data, which should all be zeros now.
86 resampler.Flush(); 91 resampler.Flush();
87 testing::Mock::VerifyAndClear(&mock_source); 92 testing::Mock::VerifyAndClear(&mock_source);
88 EXPECT_CALL(mock_source, ProvideInput(_, _)) 93 EXPECT_CALL(mock_source, ProvideInput(_, _))
89 .Times(1).WillOnce(ClearBuffer()); 94 .Times(1).WillOnce(ClearBuffer());
90 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); 95 resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2);
91 for (int i = 0; i < resampler.ChunkSize() / 2; ++i) 96 for (int i = 0; i < resampler.ChunkSize() / 2; ++i)
92 ASSERT_EQ(resampled_destination[i], 0); 97 ASSERT_FLOAT_EQ(resampled_destination[i], 0);
93 } 98 }
94 99
100 // Define platform independent function name for Convolve* tests.
101 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
102 #define CONVOLVE_FUNC Convolve_SSE
103 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
104 #define CONVOLVE_FUNC Convolve_NEON
105 #endif
106
95 // Ensure various optimized Convolve() methods return the same value. Only run 107 // Ensure various optimized Convolve() methods return the same value. Only run
96 // this test if other optimized methods exist, otherwise the default Convolve() 108 // this test if other optimized methods exist, otherwise the default Convolve()
97 // will be tested by the parameterized SincResampler tests below. 109 // will be tested by the parameterized SincResampler tests below.
98 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) 110 #if defined(CONVOLVE_FUNC)
99 TEST(SincResamplerTest, Convolve) { 111 TEST(SincResamplerTest, Convolve) {
100 // Initialize a dummy resampler. 112 // Initialize a dummy resampler.
101 MockSource mock_source; 113 MockSource mock_source;
102 SincResampler resampler( 114 SincResampler resampler(
103 kSampleRateRatio, 115 kSampleRateRatio,
104 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); 116 base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source)));
105 117
106 // Convolve_SSE() is slightly more precise than Convolve_C(), so comparison 118 // The optimized Convolve methods are slightly more precise than Convolve_C(),
107 // must be done using an epsilon. 119 // so comparison must be done using an epsilon.
108 static const double kEpsilon = 0.00000005; 120 static const double kEpsilon = 0.00000005;
109 121
110 // Use a kernel from SincResampler as input and kernel data, this has the 122 // Use a kernel from SincResampler as input and kernel data, this has the
111 // benefit of already being properly sized and aligned for Convolve_SSE(). 123 // benefit of already being properly sized and aligned for Convolve_SSE().
112 double result = resampler.Convolve_C( 124 double result = resampler.Convolve_C(
113 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), 125 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(),
114 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 126 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
115 double result2 = resampler.Convolve_SSE( 127 double result2 = resampler.CONVOLVE_FUNC(
116 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), 128 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(),
117 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 129 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
118 EXPECT_NEAR(result2, result, kEpsilon); 130 EXPECT_NEAR(result2, result, kEpsilon);
119 131
120 // Test Convolve_SSE() w/ unaligned input pointer. 132 // Test Convolve() w/ unaligned input pointer.
121 result = resampler.Convolve_C( 133 result = resampler.Convolve_C(
122 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), 134 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(),
123 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 135 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
124 result2 = resampler.Convolve_SSE( 136 result2 = resampler.CONVOLVE_FUNC(
125 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), 137 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(),
126 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 138 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
127 EXPECT_NEAR(result2, result, kEpsilon); 139 EXPECT_NEAR(result2, result, kEpsilon);
128 } 140 }
129 #endif 141 #endif
130 142
131 // Benchmark for the various Convolve() methods. Make sure to build with 143 // Benchmark for the various Convolve() methods. Make sure to build with
132 // branding=Chrome so that DCHECKs are compiled out when benchmarking. Original 144 // branding=Chrome so that DCHECKs are compiled out when benchmarking. Original
133 // benchmarks were run with --convolve-iterations=50000000. 145 // benchmarks were run with --convolve-iterations=50000000.
134 TEST(SincResamplerTest, ConvolveBenchmark) { 146 TEST(SincResamplerTest, ConvolveBenchmark) {
(...skipping 16 matching lines...) Expand all
151 base::TimeTicks start = base::TimeTicks::HighResNow(); 163 base::TimeTicks start = base::TimeTicks::HighResNow();
152 for (int i = 0; i < convolve_iterations; ++i) { 164 for (int i = 0; i < convolve_iterations; ++i) {
153 resampler.Convolve_C( 165 resampler.Convolve_C(
154 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), 166 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(),
155 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 167 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
156 } 168 }
157 double total_time_c_ms = 169 double total_time_c_ms =
158 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); 170 (base::TimeTicks::HighResNow() - start).InMillisecondsF();
159 printf("Convolve_C took %.2fms.\n", total_time_c_ms); 171 printf("Convolve_C took %.2fms.\n", total_time_c_ms);
160 172
161 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) 173 #if defined(CONVOLVE_FUNC)
162 // Benchmark Convolve_SSE() with unaligned input pointer. 174 // Benchmark with unaligned input pointer.
163 start = base::TimeTicks::HighResNow(); 175 start = base::TimeTicks::HighResNow();
164 for (int j = 0; j < convolve_iterations; ++j) { 176 for (int j = 0; j < convolve_iterations; ++j) {
165 resampler.Convolve_SSE( 177 resampler.CONVOLVE_FUNC(
166 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), 178 resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(),
167 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 179 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
168 } 180 }
169 double total_time_sse_unaligned_ms = 181 double total_time_optimized_unaligned_ms =
170 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); 182 (base::TimeTicks::HighResNow() - start).InMillisecondsF();
171 printf("Convolve_SSE (unaligned) took %.2fms; which is %.2fx faster than" 183 printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx "
172 " Convolve_C.\n", total_time_sse_unaligned_ms, 184 "faster than Convolve_C.\n", total_time_optimized_unaligned_ms,
173 total_time_c_ms / total_time_sse_unaligned_ms); 185 total_time_c_ms / total_time_optimized_unaligned_ms);
174 186
175 // Benchmark Convolve_SSE() with aligned input pointer. 187 // Benchmark with aligned input pointer.
176 start = base::TimeTicks::HighResNow(); 188 start = base::TimeTicks::HighResNow();
177 for (int j = 0; j < convolve_iterations; ++j) { 189 for (int j = 0; j < convolve_iterations; ++j) {
178 resampler.Convolve_SSE( 190 resampler.CONVOLVE_FUNC(
179 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), 191 resampler.kernel_storage_.get(), resampler.kernel_storage_.get(),
180 resampler.kernel_storage_.get(), kKernelInterpolationFactor); 192 resampler.kernel_storage_.get(), kKernelInterpolationFactor);
181 } 193 }
182 double total_time_sse_aligned_ms = 194 double total_time_optimized_aligned_ms =
183 (base::TimeTicks::HighResNow() - start).InMillisecondsF(); 195 (base::TimeTicks::HighResNow() - start).InMillisecondsF();
184 printf("Convolve_SSE (aligned) took %.2fms; which is %.2fx faster than" 196 printf(STRINGIZE(CONVOLVE_FUNC) " (aligned) took %.2fms; which is %.2fx "
185 " Convolve_C and %.2fx faster than Convolve_SSE (unaligned).\n", 197 "faster than Convolve_C and %.2fx faster than "
186 total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, 198 STRINGIZE(CONVOLVE_FUNC) " (unaligned).\n",
187 total_time_sse_unaligned_ms / total_time_sse_aligned_ms); 199 total_time_optimized_aligned_ms,
200 total_time_c_ms / total_time_optimized_aligned_ms,
201 total_time_optimized_unaligned_ms / total_time_optimized_aligned_ms);
188 #endif 202 #endif
189 } 203 }
190 204
205 #undef CONVOLVE_FUNC
206
191 // Fake audio source for testing the resampler. Generates a sinusoidal linear 207 // Fake audio source for testing the resampler. Generates a sinusoidal linear
192 // chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the 208 // chirp (http://en.wikipedia.org/wiki/Chirp) which can be tuned to stress the
193 // resampler for the specific sample rate conversion being used. 209 // resampler for the specific sample rate conversion being used.
194 class SinusoidalLinearChirpSource { 210 class SinusoidalLinearChirpSource {
195 public: 211 public:
196 SinusoidalLinearChirpSource(int sample_rate, int samples, 212 SinusoidalLinearChirpSource(int sample_rate, int samples,
197 double max_frequency) 213 double max_frequency)
198 : sample_rate_(sample_rate), 214 : sample_rate_(sample_rate),
199 total_samples_(samples), 215 total_samples_(samples),
200 max_frequency_(max_frequency), 216 max_frequency_(max_frequency),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61), 396 std::tr1::make_tuple(11025, 192000, kResamplingRMSError, -62.61),
381 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14), 397 std::tr1::make_tuple(16000, 192000, kResamplingRMSError, -63.14),
382 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42), 398 std::tr1::make_tuple(22050, 192000, kResamplingRMSError, -62.42),
383 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38), 399 std::tr1::make_tuple(32000, 192000, kResamplingRMSError, -63.38),
384 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63), 400 std::tr1::make_tuple(44100, 192000, kResamplingRMSError, -62.63),
385 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44), 401 std::tr1::make_tuple(48000, 192000, kResamplingRMSError, -73.44),
386 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52), 402 std::tr1::make_tuple(96000, 192000, kResamplingRMSError, -73.52),
387 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52))); 403 std::tr1::make_tuple(192000, 192000, kResamplingRMSError, -73.52)));
388 404
389 } // namespace media 405 } // namespace media
OLDNEW
« no previous file with comments | « media/base/sinc_resampler.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698