| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <algorithm> |
| 12 #include <sstream> |
| 13 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 13 | 16 |
| 14 static const size_t kVector16Size = 9; | 17 static const size_t kVector16Size = 9; |
| 15 static const int16_t vector16[kVector16Size] = {1, -15511, 4323, 1963, | 18 static const int16_t vector16[kVector16Size] = {1, -15511, 4323, 1963, |
| 16 WEBRTC_SPL_WORD16_MAX, 0, WEBRTC_SPL_WORD16_MIN + 5, -3333, 345}; | 19 WEBRTC_SPL_WORD16_MAX, 0, WEBRTC_SPL_WORD16_MIN + 5, -3333, 345}; |
| 17 | 20 |
| 18 class SplTest : public testing::Test { | 21 class SplTest : public testing::Test { |
| 19 protected: | 22 protected: |
| 20 SplTest() { | 23 SplTest() { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 EXPECT_EQ(14 - ii, WebRtcSpl_NormW16(value)); | 114 EXPECT_EQ(14 - ii, WebRtcSpl_NormW16(value)); |
| 112 EXPECT_EQ(15 - ii, WebRtcSpl_NormW16(-value)); | 115 EXPECT_EQ(15 - ii, WebRtcSpl_NormW16(-value)); |
| 113 } | 116 } |
| 114 | 117 |
| 115 EXPECT_EQ(0, WebRtcSpl_NormU32(0u)); | 118 EXPECT_EQ(0, WebRtcSpl_NormU32(0u)); |
| 116 EXPECT_EQ(0, WebRtcSpl_NormU32(0xffffffff)); | 119 EXPECT_EQ(0, WebRtcSpl_NormU32(0xffffffff)); |
| 117 EXPECT_EQ(15, WebRtcSpl_NormU32(static_cast<uint32_t>(a32))); | 120 EXPECT_EQ(15, WebRtcSpl_NormU32(static_cast<uint32_t>(a32))); |
| 118 | 121 |
| 119 EXPECT_EQ(104, WebRtcSpl_AddSatW16(a16, b16)); | 122 EXPECT_EQ(104, WebRtcSpl_AddSatW16(a16, b16)); |
| 120 EXPECT_EQ(138, WebRtcSpl_SubSatW16(a16, b16)); | 123 EXPECT_EQ(138, WebRtcSpl_SubSatW16(a16, b16)); |
| 124 } |
| 121 | 125 |
| 122 EXPECT_EQ(109410, WebRtcSpl_AddSatW32(a32, b32)); | 126 TEST_F(SplTest, AddSubSatW32) { |
| 123 EXPECT_EQ(112832, WebRtcSpl_SubSatW32(a32, b32)); | 127 static constexpr int32_t kAddSubArgs[] = { |
| 124 | 128 INT32_MIN, INT32_MIN + 1, -3, -2, -1, 0, 1, -1, 2, |
| 125 a32 = 0x80000000; | 129 3, INT32_MAX - 1, INT32_MAX}; |
| 126 b32 = 0x80000000; | 130 for (int32_t a : kAddSubArgs) { |
| 127 // Cast to signed int to avoid compiler complaint on gtest.h. | 131 for (int32_t b : kAddSubArgs) { |
| 128 EXPECT_EQ(static_cast<int>(0x80000000), WebRtcSpl_AddSatW32(a32, b32)); | 132 const int64_t sum = std::max<int64_t>( |
| 129 a32 = 0x7fffffff; | 133 INT32_MIN, std::min<int64_t>(INT32_MAX, static_cast<int64_t>(a) + b)); |
| 130 b32 = 0x7fffffff; | 134 const int64_t diff = std::max<int64_t>( |
| 131 EXPECT_EQ(0x7fffffff, WebRtcSpl_AddSatW32(a32, b32)); | 135 INT32_MIN, std::min<int64_t>(INT32_MAX, static_cast<int64_t>(a) - b)); |
| 132 a32 = 0; | 136 std::ostringstream ss; |
| 133 b32 = 0x80000000; | 137 ss << a << " +/- " << b << ": sum " << sum << ", diff " << diff; |
| 134 EXPECT_EQ(0x7fffffff, WebRtcSpl_SubSatW32(a32, b32)); | 138 SCOPED_TRACE(ss.str()); |
| 135 a32 = 0x7fffffff; | 139 EXPECT_EQ(sum, WebRtcSpl_AddSatW32(a, b)); |
| 136 b32 = 0x80000000; | 140 EXPECT_EQ(diff, WebRtcSpl_SubSatW32(a, b)); |
| 137 EXPECT_EQ(0x7fffffff, WebRtcSpl_SubSatW32(a32, b32)); | 141 } |
| 138 a32 = 0x80000000; | 142 } |
| 139 b32 = 0x7fffffff; | |
| 140 EXPECT_EQ(static_cast<int>(0x80000000), WebRtcSpl_SubSatW32(a32, b32)); | |
| 141 } | 143 } |
| 142 | 144 |
| 143 TEST_F(SplTest, MathOperationsTest) { | 145 TEST_F(SplTest, MathOperationsTest) { |
| 144 int A = 1134567892; | 146 int A = 1134567892; |
| 145 int32_t num = 117; | 147 int32_t num = 117; |
| 146 int32_t den = -5; | 148 int32_t den = -5; |
| 147 uint16_t denU = 5; | 149 uint16_t denU = 5; |
| 148 EXPECT_EQ(33700, WebRtcSpl_Sqrt(A)); | 150 EXPECT_EQ(33700, WebRtcSpl_Sqrt(A)); |
| 149 EXPECT_EQ(33683, WebRtcSpl_SqrtFloor(A)); | 151 EXPECT_EQ(33683, WebRtcSpl_SqrtFloor(A)); |
| 150 | 152 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 // 12-15 are skipped to account for the filter lag. | 572 // 12-15 are skipped to account for the filter lag. |
| 571 for (size_t i = 0; i < 12; ++i) { | 573 for (size_t i = 0; i < 12; ++i) { |
| 572 EXPECT_EQ(kRefValue32kHz1, out_vector[i]); | 574 EXPECT_EQ(kRefValue32kHz1, out_vector[i]); |
| 573 EXPECT_EQ(kRefValue16kHz1, out_vector_w16[i]); | 575 EXPECT_EQ(kRefValue16kHz1, out_vector_w16[i]); |
| 574 } | 576 } |
| 575 for (size_t i = 16; i < 2 * kBlockSize; ++i) { | 577 for (size_t i = 16; i < 2 * kBlockSize; ++i) { |
| 576 EXPECT_EQ(kRefValue32kHz2, out_vector[i]); | 578 EXPECT_EQ(kRefValue32kHz2, out_vector[i]); |
| 577 EXPECT_EQ(kRefValue16kHz2, out_vector_w16[i]); | 579 EXPECT_EQ(kRefValue16kHz2, out_vector_w16[i]); |
| 578 } | 580 } |
| 579 } | 581 } |
| OLD | NEW |