| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 "webrtc/modules/audio_processing/aec3/suppression_gain.h" | 11 #include "webrtc/modules/audio_processing/aec3/suppression_gain.h" |
| 12 | 12 |
| 13 #include "webrtc/typedefs.h" | 13 #include "webrtc/typedefs.h" |
| 14 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 14 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
| 15 #include "webrtc/test/gtest.h" | 15 #include "webrtc/test/gtest.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 namespace aec3 { | 18 namespace aec3 { |
| 19 | 19 |
| 20 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 20 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 21 | 21 |
| 22 // Verifies that the check for non-null output gains works. | 22 // Verifies that the check for non-null output gains works. |
| 23 TEST(SuppressionGain, NullOutputGains) { | 23 TEST(SuppressionGain, NullOutputGains) { |
| 24 std::array<float, kFftLengthBy2Plus1> E2; | 24 std::array<float, kFftLengthBy2Plus1> E2; |
| 25 std::array<float, kFftLengthBy2Plus1> R2; | 25 std::array<float, kFftLengthBy2Plus1> R2; |
| 26 std::array<float, kFftLengthBy2Plus1> N2; | 26 std::array<float, kFftLengthBy2Plus1> N2; |
| 27 EXPECT_DEATH( | 27 E2.fill(0.f); |
| 28 SuppressionGain(DetectOptimization()).GetGain(E2, R2, N2, 0.1f, nullptr), | 28 R2.fill(0.f); |
| 29 ""); | 29 N2.fill(0.f); |
| 30 float high_bands_gain; |
| 31 EXPECT_DEATH(SuppressionGain(DetectOptimization()) |
| 32 .GetGain(E2, R2, N2, false, |
| 33 std::vector<std::vector<float>>( |
| 34 3, std::vector<float>(kBlockSize, 0.f)), |
| 35 1, &high_bands_gain, nullptr), |
| 36 ""); |
| 30 } | 37 } |
| 31 | 38 |
| 32 #endif | 39 #endif |
| 33 | 40 |
| 34 #if defined(WEBRTC_ARCH_X86_FAMILY) | 41 #if defined(WEBRTC_ARCH_X86_FAMILY) |
| 35 // Verifies that the optimized methods are bitexact to their reference | 42 // Verifies that the optimized methods are bitexact to their reference |
| 36 // counterparts. | 43 // counterparts. |
| 37 TEST(SuppressionGain, TestOptimizations) { | 44 TEST(SuppressionGain, TestOptimizations) { |
| 38 if (WebRtc_GetCPUInfo(kSSE2) != 0) { | 45 if (WebRtc_GetCPUInfo(kSSE2) != 0) { |
| 39 std::array<float, kFftLengthBy2 - 1> G2_old; | 46 std::array<float, kFftLengthBy2 - 1> G2_old; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); | 108 EXPECT_NEAR(g[j], g_SSE2[j], 0.0000001f); |
| 102 } | 109 } |
| 103 } | 110 } |
| 104 } | 111 } |
| 105 } | 112 } |
| 106 #endif | 113 #endif |
| 107 | 114 |
| 108 // Does a sanity check that the gains are correctly computed. | 115 // Does a sanity check that the gains are correctly computed. |
| 109 TEST(SuppressionGain, BasicGainComputation) { | 116 TEST(SuppressionGain, BasicGainComputation) { |
| 110 SuppressionGain suppression_gain(DetectOptimization()); | 117 SuppressionGain suppression_gain(DetectOptimization()); |
| 118 float high_bands_gain; |
| 111 std::array<float, kFftLengthBy2Plus1> E2; | 119 std::array<float, kFftLengthBy2Plus1> E2; |
| 112 std::array<float, kFftLengthBy2Plus1> R2; | 120 std::array<float, kFftLengthBy2Plus1> R2; |
| 113 std::array<float, kFftLengthBy2Plus1> N2; | 121 std::array<float, kFftLengthBy2Plus1> N2; |
| 114 std::array<float, kFftLengthBy2Plus1> g; | 122 std::array<float, kFftLengthBy2Plus1> g; |
| 123 std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f)); |
| 115 | 124 |
| 116 // Ensure that a strong noise is detected to mask any echoes. | 125 // Ensure that a strong noise is detected to mask any echoes. |
| 117 E2.fill(10.f); | 126 E2.fill(10.f); |
| 118 R2.fill(0.1f); | 127 R2.fill(0.1f); |
| 119 N2.fill(100.f); | 128 N2.fill(100.f); |
| 120 for (int k = 0; k < 10; ++k) { | 129 for (int k = 0; k < 10; ++k) { |
| 121 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g); | 130 suppression_gain.GetGain(E2, R2, N2, false, x, 1, &high_bands_gain, &g); |
| 122 } | 131 } |
| 123 std::for_each(g.begin(), g.end(), | 132 std::for_each(g.begin(), g.end(), |
| 124 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); | 133 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); |
| 125 | 134 |
| 126 // Ensure that a strong nearend is detected to mask any echoes. | 135 // Ensure that a strong nearend is detected to mask any echoes. |
| 127 E2.fill(100.f); | 136 E2.fill(100.f); |
| 128 R2.fill(0.1f); | 137 R2.fill(0.1f); |
| 129 N2.fill(0.f); | 138 N2.fill(0.f); |
| 130 for (int k = 0; k < 10; ++k) { | 139 for (int k = 0; k < 10; ++k) { |
| 131 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g); | 140 suppression_gain.GetGain(E2, R2, N2, false, x, 1, &high_bands_gain, &g); |
| 132 } | 141 } |
| 133 std::for_each(g.begin(), g.end(), | 142 std::for_each(g.begin(), g.end(), |
| 134 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); | 143 [](float a) { EXPECT_NEAR(1.f, a, 0.001); }); |
| 135 | 144 |
| 136 // Ensure that a strong echo is suppressed. | 145 // Ensure that a strong echo is suppressed. |
| 137 E2.fill(0.1f); | 146 E2.fill(0.1f); |
| 138 R2.fill(100.f); | 147 R2.fill(100.f); |
| 139 N2.fill(0.f); | 148 N2.fill(0.f); |
| 140 for (int k = 0; k < 10; ++k) { | 149 for (int k = 0; k < 10; ++k) { |
| 141 suppression_gain.GetGain(E2, R2, N2, 0.1f, &g); | 150 suppression_gain.GetGain(E2, R2, N2, false, x, 1, &high_bands_gain, &g); |
| 142 } | 151 } |
| 143 std::for_each(g.begin(), g.end(), | 152 std::for_each(g.begin(), g.end(), |
| 144 [](float a) { EXPECT_NEAR(0.f, a, 0.001); }); | 153 [](float a) { EXPECT_NEAR(0.f, a, 0.001); }); |
| 145 } | 154 } |
| 146 | 155 |
| 147 } // namespace aec3 | 156 } // namespace aec3 |
| 148 } // namespace webrtc | 157 } // namespace webrtc |
| OLD | NEW |