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

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

Issue 156783003: Enhance AudioSplicer to crossfade marked splice frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 years, 9 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/vector_math.cc ('k') | no next file » | 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 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/cpu.h" 9 #include "base/cpu.h"
10 #include "base/memory/aligned_memory.h" 10 #include "base/memory/aligned_memory.h"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 void FillTestVectors(float input, float output) { 39 void FillTestVectors(float input, float output) {
40 // Setup input and output vectors. 40 // Setup input and output vectors.
41 fill(input_vector_.get(), input_vector_.get() + kVectorSize, input); 41 fill(input_vector_.get(), input_vector_.get() + kVectorSize, input);
42 fill(output_vector_.get(), output_vector_.get() + kVectorSize, output); 42 fill(output_vector_.get(), output_vector_.get() + kVectorSize, output);
43 } 43 }
44 44
45 void VerifyOutput(float value) { 45 void VerifyOutput(float value) {
46 for (int i = 0; i < kVectorSize; ++i) 46 for (int i = 0; i < kVectorSize; ++i)
47 ASSERT_FLOAT_EQ(output_vector_.get()[i], value); 47 ASSERT_FLOAT_EQ(output_vector_[i], value);
48 } 48 }
49 49
50 protected: 50 protected:
51 scoped_ptr<float, base::AlignedFreeDeleter> input_vector_; 51 scoped_ptr<float[], base::AlignedFreeDeleter> input_vector_;
52 scoped_ptr<float, base::AlignedFreeDeleter> output_vector_; 52 scoped_ptr<float[], base::AlignedFreeDeleter> output_vector_;
53 53
54 DISALLOW_COPY_AND_ASSIGN(VectorMathTest); 54 DISALLOW_COPY_AND_ASSIGN(VectorMathTest);
55 }; 55 };
56 56
57 // Ensure each optimized vector_math::FMAC() method returns the same value. 57 // Ensure each optimized vector_math::FMAC() method returns the same value.
58 TEST_F(VectorMathTest, FMAC) { 58 TEST_F(VectorMathTest, FMAC) {
59 static const float kResult = kInputFillValue * kScale + kOutputFillValue; 59 static const float kResult = kInputFillValue * kScale + kOutputFillValue;
60 60
61 { 61 {
62 SCOPED_TRACE("FMAC"); 62 SCOPED_TRACE("FMAC");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 { 131 {
132 SCOPED_TRACE("FMUL_NEON"); 132 SCOPED_TRACE("FMUL_NEON");
133 FillTestVectors(kInputFillValue, kOutputFillValue); 133 FillTestVectors(kInputFillValue, kOutputFillValue);
134 vector_math::FMUL_NEON( 134 vector_math::FMUL_NEON(
135 input_vector_.get(), kScale, kVectorSize, output_vector_.get()); 135 input_vector_.get(), kScale, kVectorSize, output_vector_.get());
136 VerifyOutput(kResult); 136 VerifyOutput(kResult);
137 } 137 }
138 #endif 138 #endif
139 } 139 }
140 140
141 namespace { 141 TEST_F(VectorMathTest, Crossfade) {
142 FillTestVectors(0, 1);
143 vector_math::Crossfade(
144 input_vector_.get(), kVectorSize, output_vector_.get());
145 for (int i = 0; i < kVectorSize; ++i) {
146 ASSERT_FLOAT_EQ(i / static_cast<float>(kVectorSize), output_vector_[i])
147 << "i=" << i;
148 }
149 }
142 150
143 class EWMATestScenario { 151 class EWMATestScenario {
144 public: 152 public:
145 EWMATestScenario(float initial_value, const float src[], int len, 153 EWMATestScenario(float initial_value, const float src[], int len,
146 float smoothing_factor) 154 float smoothing_factor)
147 : initial_value_(initial_value), 155 : initial_value_(initial_value),
148 data_(static_cast<float*>( 156 data_(static_cast<float*>(
149 len == 0 ? NULL : 157 len == 0 ? NULL :
150 base::AlignedAlloc(len * sizeof(float), 158 base::AlignedAlloc(len * sizeof(float),
151 vector_math::kRequiredAlignment))), 159 vector_math::kRequiredAlignment))),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 249
242 private: 250 private:
243 float initial_value_; 251 float initial_value_;
244 scoped_ptr<float, base::AlignedFreeDeleter> data_; 252 scoped_ptr<float, base::AlignedFreeDeleter> data_;
245 int data_len_; 253 int data_len_;
246 float smoothing_factor_; 254 float smoothing_factor_;
247 float expected_final_avg_; 255 float expected_final_avg_;
248 float expected_max_; 256 float expected_max_;
249 }; 257 };
250 258
251 } // namespace
252
253 typedef testing::TestWithParam<EWMATestScenario> VectorMathEWMAAndMaxPowerTest; 259 typedef testing::TestWithParam<EWMATestScenario> VectorMathEWMAAndMaxPowerTest;
254 260
255 TEST_P(VectorMathEWMAAndMaxPowerTest, Correctness) { 261 TEST_P(VectorMathEWMAAndMaxPowerTest, Correctness) {
256 GetParam().RunTest(); 262 GetParam().RunTest();
257 } 263 }
258 264
259 static const float kZeros[] = { // 32 zeros 265 static const float kZeros[] = { // 32 zeros
260 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 266 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
261 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 267 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
262 }; 268 };
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 .HasExpectedResult(0.00017858f, 4.0f), 382 .HasExpectedResult(0.00017858f, 4.0f),
377 EWMATestScenario(0.0f, kZeros, 32, 0.25f) 383 EWMATestScenario(0.0f, kZeros, 32, 0.25f)
378 .WithImpulse(2.0f, 2) 384 .WithImpulse(2.0f, 2)
379 .HasExpectedResult(0.00023811f, 4.0f), 385 .HasExpectedResult(0.00023811f, 4.0f),
380 EWMATestScenario(0.0f, kZeros, 32, 0.25f) 386 EWMATestScenario(0.0f, kZeros, 32, 0.25f)
381 .WithImpulse(2.0f, 3) 387 .WithImpulse(2.0f, 3)
382 .HasExpectedResult(0.00031748f, 4.0f) 388 .HasExpectedResult(0.00031748f, 4.0f)
383 )); 389 ));
384 390
385 } // namespace media 391 } // namespace media
OLDNEW
« no previous file with comments | « media/base/vector_math.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698