| 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 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/aligned_memory.h" | 12 #include "base/memory/aligned_memory.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "media/base/vector_math.h" | 16 #include "media/base/vector_math.h" |
| 16 #include "media/base/vector_math_testing.h" | 17 #include "media/base/vector_math_testing.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using std::fill; | 20 using std::fill; |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 fill(input_vector_.get(), input_vector_.get() + kVectorSize, input); | 43 fill(input_vector_.get(), input_vector_.get() + kVectorSize, input); |
| 43 fill(output_vector_.get(), output_vector_.get() + kVectorSize, output); | 44 fill(output_vector_.get(), output_vector_.get() + kVectorSize, output); |
| 44 } | 45 } |
| 45 | 46 |
| 46 void VerifyOutput(float value) { | 47 void VerifyOutput(float value) { |
| 47 for (int i = 0; i < kVectorSize; ++i) | 48 for (int i = 0; i < kVectorSize; ++i) |
| 48 ASSERT_FLOAT_EQ(output_vector_[i], value); | 49 ASSERT_FLOAT_EQ(output_vector_[i], value); |
| 49 } | 50 } |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 scoped_ptr<float[], base::AlignedFreeDeleter> input_vector_; | 53 std::unique_ptr<float[], base::AlignedFreeDeleter> input_vector_; |
| 53 scoped_ptr<float[], base::AlignedFreeDeleter> output_vector_; | 54 std::unique_ptr<float[], base::AlignedFreeDeleter> output_vector_; |
| 54 | 55 |
| 55 DISALLOW_COPY_AND_ASSIGN(VectorMathTest); | 56 DISALLOW_COPY_AND_ASSIGN(VectorMathTest); |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 // Ensure each optimized vector_math::FMAC() method returns the same value. | 59 // Ensure each optimized vector_math::FMAC() method returns the same value. |
| 59 TEST_F(VectorMathTest, FMAC) { | 60 TEST_F(VectorMathTest, FMAC) { |
| 60 static const float kResult = kInputFillValue * kScale + kOutputFillValue; | 61 static const float kResult = kInputFillValue * kScale + kOutputFillValue; |
| 61 | 62 |
| 62 { | 63 { |
| 63 SCOPED_TRACE("FMAC"); | 64 SCOPED_TRACE("FMAC"); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 const std::pair<float, float>& result = vector_math::EWMAAndMaxPower_NEON( | 241 const std::pair<float, float>& result = vector_math::EWMAAndMaxPower_NEON( |
| 241 initial_value_, data_.get(), data_len_, smoothing_factor_); | 242 initial_value_, data_.get(), data_len_, smoothing_factor_); |
| 242 EXPECT_NEAR(expected_final_avg_, result.first, 0.0000001f); | 243 EXPECT_NEAR(expected_final_avg_, result.first, 0.0000001f); |
| 243 EXPECT_NEAR(expected_max_, result.second, 0.0000001f); | 244 EXPECT_NEAR(expected_max_, result.second, 0.0000001f); |
| 244 } | 245 } |
| 245 #endif | 246 #endif |
| 246 } | 247 } |
| 247 | 248 |
| 248 private: | 249 private: |
| 249 float initial_value_; | 250 float initial_value_; |
| 250 scoped_ptr<float, base::AlignedFreeDeleter> data_; | 251 std::unique_ptr<float, base::AlignedFreeDeleter> data_; |
| 251 int data_len_; | 252 int data_len_; |
| 252 float smoothing_factor_; | 253 float smoothing_factor_; |
| 253 float expected_final_avg_; | 254 float expected_final_avg_; |
| 254 float expected_max_; | 255 float expected_max_; |
| 255 }; | 256 }; |
| 256 | 257 |
| 257 typedef testing::TestWithParam<EWMATestScenario> VectorMathEWMAAndMaxPowerTest; | 258 typedef testing::TestWithParam<EWMATestScenario> VectorMathEWMAAndMaxPowerTest; |
| 258 | 259 |
| 259 TEST_P(VectorMathEWMAAndMaxPowerTest, Correctness) { | 260 TEST_P(VectorMathEWMAAndMaxPowerTest, Correctness) { |
| 260 GetParam().RunTest(); | 261 GetParam().RunTest(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 .HasExpectedResult(0.00017858f, 4.0f), | 381 .HasExpectedResult(0.00017858f, 4.0f), |
| 381 EWMATestScenario(0.0f, kZeros, 32, 0.25f) | 382 EWMATestScenario(0.0f, kZeros, 32, 0.25f) |
| 382 .WithImpulse(2.0f, 2) | 383 .WithImpulse(2.0f, 2) |
| 383 .HasExpectedResult(0.00023811f, 4.0f), | 384 .HasExpectedResult(0.00023811f, 4.0f), |
| 384 EWMATestScenario(0.0f, kZeros, 32, 0.25f) | 385 EWMATestScenario(0.0f, kZeros, 32, 0.25f) |
| 385 .WithImpulse(2.0f, 3) | 386 .WithImpulse(2.0f, 3) |
| 386 .HasExpectedResult(0.00031748f, 4.0f) | 387 .HasExpectedResult(0.00031748f, 4.0f) |
| 387 )); | 388 )); |
| 388 | 389 |
| 389 } // namespace media | 390 } // namespace media |
| OLD | NEW |