| 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/aec_state.h" | 11 #include "webrtc/modules/audio_processing/aec3/aec_state.h" |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 13 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
| 14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
| 15 | 15 |
| 16 namespace webrtc { | 16 namespace webrtc { |
| 17 | 17 |
| 18 // Verify the general functionality of AecState | 18 // Verify the general functionality of AecState |
| 19 TEST(AecState, NormalUsage) { | 19 TEST(AecState, NormalUsage) { |
| 20 ApmDataDumper data_dumper(42); | 20 ApmDataDumper data_dumper(42); |
| 21 AecState state(0.f); | 21 AecState state(AudioProcessing::Config::EchoCanceller3{}); |
| 22 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 30, | 22 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 30, |
| 23 std::vector<size_t>(1, 30)); | 23 std::vector<size_t>(1, 30)); |
| 24 std::array<float, kFftLengthBy2Plus1> E2_main = {}; | 24 std::array<float, kFftLengthBy2Plus1> E2_main = {}; |
| 25 std::array<float, kFftLengthBy2Plus1> Y2 = {}; | 25 std::array<float, kFftLengthBy2Plus1> Y2 = {}; |
| 26 std::vector<std::vector<float>> x(3, std::vector<float>(kBlockSize, 0.f)); | 26 std::vector<std::vector<float>> x(3, std::vector<float>(kBlockSize, 0.f)); |
| 27 EchoPathVariability echo_path_variability(false, false); | 27 EchoPathVariability echo_path_variability(false, false); |
| 28 std::array<float, kBlockSize> s; | 28 std::array<float, kBlockSize> s; |
| 29 s.fill(100.f); | 29 s.fill(100.f); |
| 30 | 30 |
| 31 std::vector<std::array<float, kFftLengthBy2Plus1>> | 31 std::vector<std::array<float, kFftLengthBy2Plus1>> |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 for (size_t k = kLowFrequencyLimit; k < erle.size() - 1; ++k) { | 157 for (size_t k = kLowFrequencyLimit; k < erle.size() - 1; ++k) { |
| 158 EXPECT_NEAR(k % 2 == 0 ? 1.5f : 1.f, erle[k], 0.1); | 158 EXPECT_NEAR(k % 2 == 0 ? 1.5f : 1.f, erle[k], 0.1); |
| 159 } | 159 } |
| 160 EXPECT_EQ(erle[erle.size() - 2], erle[erle.size() - 1]); | 160 EXPECT_EQ(erle[erle.size() - 2], erle[erle.size() - 1]); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Verifies the a non-significant delay is correctly identified. | 164 // Verifies the a non-significant delay is correctly identified. |
| 165 TEST(AecState, NonSignificantDelay) { | 165 TEST(AecState, NonSignificantDelay) { |
| 166 AecState state(0.f); | 166 AecState state(AudioProcessing::Config::EchoCanceller3{}); |
| 167 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 30, | 167 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 30, |
| 168 std::vector<size_t>(1, 30)); | 168 std::vector<size_t>(1, 30)); |
| 169 std::array<float, kFftLengthBy2Plus1> E2_main; | 169 std::array<float, kFftLengthBy2Plus1> E2_main; |
| 170 std::array<float, kFftLengthBy2Plus1> Y2; | 170 std::array<float, kFftLengthBy2Plus1> Y2; |
| 171 std::array<float, kBlockSize> x; | 171 std::array<float, kBlockSize> x; |
| 172 EchoPathVariability echo_path_variability(false, false); | 172 EchoPathVariability echo_path_variability(false, false); |
| 173 std::array<float, kBlockSize> s; | 173 std::array<float, kBlockSize> s; |
| 174 s.fill(100.f); | 174 s.fill(100.f); |
| 175 x.fill(0.f); | 175 x.fill(0.f); |
| 176 | 176 |
| 177 std::vector<std::array<float, kFftLengthBy2Plus1>> frequency_response(30); | 177 std::vector<std::array<float, kFftLengthBy2Plus1>> frequency_response(30); |
| 178 for (auto& v : frequency_response) { | 178 for (auto& v : frequency_response) { |
| 179 v.fill(0.01f); | 179 v.fill(0.01f); |
| 180 } | 180 } |
| 181 | 181 |
| 182 std::array<float, kAdaptiveFilterTimeDomainLength> impulse_response; | 182 std::array<float, kAdaptiveFilterTimeDomainLength> impulse_response; |
| 183 impulse_response.fill(0.f); | 183 impulse_response.fill(0.f); |
| 184 | 184 |
| 185 // Verify that a non-significant filter delay is identified correctly. | 185 // Verify that a non-significant filter delay is identified correctly. |
| 186 state.HandleEchoPathChange(echo_path_variability); | 186 state.HandleEchoPathChange(echo_path_variability); |
| 187 state.Update(frequency_response, impulse_response, rtc::Optional<size_t>(), | 187 state.Update(frequency_response, impulse_response, rtc::Optional<size_t>(), |
| 188 render_buffer, E2_main, Y2, x, s, false); | 188 render_buffer, E2_main, Y2, x, s, false); |
| 189 EXPECT_FALSE(state.FilterDelay()); | 189 EXPECT_FALSE(state.FilterDelay()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Verifies the delay for a converged filter is correctly identified. | 192 // Verifies the delay for a converged filter is correctly identified. |
| 193 TEST(AecState, ConvergedFilterDelay) { | 193 TEST(AecState, ConvergedFilterDelay) { |
| 194 constexpr int kFilterLength = 10; | 194 constexpr int kFilterLength = 10; |
| 195 AecState state(0.f); | 195 AecState state(AudioProcessing::Config::EchoCanceller3{}); |
| 196 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 30, | 196 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 30, |
| 197 std::vector<size_t>(1, 30)); | 197 std::vector<size_t>(1, 30)); |
| 198 std::array<float, kFftLengthBy2Plus1> E2_main; | 198 std::array<float, kFftLengthBy2Plus1> E2_main; |
| 199 std::array<float, kFftLengthBy2Plus1> Y2; | 199 std::array<float, kFftLengthBy2Plus1> Y2; |
| 200 std::array<float, kBlockSize> x; | 200 std::array<float, kBlockSize> x; |
| 201 EchoPathVariability echo_path_variability(false, false); | 201 EchoPathVariability echo_path_variability(false, false); |
| 202 std::array<float, kBlockSize> s; | 202 std::array<float, kBlockSize> s; |
| 203 s.fill(100.f); | 203 s.fill(100.f); |
| 204 x.fill(0.f); | 204 x.fill(0.f); |
| 205 | 205 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 221 render_buffer, E2_main, Y2, x, s, false); | 221 render_buffer, E2_main, Y2, x, s, false); |
| 222 EXPECT_TRUE(k == (kFilterLength - 1) || state.FilterDelay()); | 222 EXPECT_TRUE(k == (kFilterLength - 1) || state.FilterDelay()); |
| 223 if (k != (kFilterLength - 1)) { | 223 if (k != (kFilterLength - 1)) { |
| 224 EXPECT_EQ(k, state.FilterDelay()); | 224 EXPECT_EQ(k, state.FilterDelay()); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Verify that the externally reported delay is properly reported and converted. | 229 // Verify that the externally reported delay is properly reported and converted. |
| 230 TEST(AecState, ExternalDelay) { | 230 TEST(AecState, ExternalDelay) { |
| 231 AecState state(0.f); | 231 AecState state(AudioProcessing::Config::EchoCanceller3{}); |
| 232 std::array<float, kFftLengthBy2Plus1> E2_main; | 232 std::array<float, kFftLengthBy2Plus1> E2_main; |
| 233 std::array<float, kFftLengthBy2Plus1> E2_shadow; | 233 std::array<float, kFftLengthBy2Plus1> E2_shadow; |
| 234 std::array<float, kFftLengthBy2Plus1> Y2; | 234 std::array<float, kFftLengthBy2Plus1> Y2; |
| 235 std::array<float, kBlockSize> x; | 235 std::array<float, kBlockSize> x; |
| 236 std::array<float, kBlockSize> s; | 236 std::array<float, kBlockSize> s; |
| 237 s.fill(100.f); | 237 s.fill(100.f); |
| 238 E2_main.fill(0.f); | 238 E2_main.fill(0.f); |
| 239 E2_shadow.fill(0.f); | 239 E2_shadow.fill(0.f); |
| 240 Y2.fill(0.f); | 240 Y2.fill(0.f); |
| 241 x.fill(0.f); | 241 x.fill(0.f); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 260 | 260 |
| 261 // Verify that the externally reported delay is properly unset when it is no | 261 // Verify that the externally reported delay is properly unset when it is no |
| 262 // longer present. | 262 // longer present. |
| 263 state.HandleEchoPathChange(EchoPathVariability(false, false)); | 263 state.HandleEchoPathChange(EchoPathVariability(false, false)); |
| 264 state.Update(frequency_response, impulse_response, rtc::Optional<size_t>(), | 264 state.Update(frequency_response, impulse_response, rtc::Optional<size_t>(), |
| 265 render_buffer, E2_main, Y2, x, s, false); | 265 render_buffer, E2_main, Y2, x, s, false); |
| 266 EXPECT_FALSE(state.ExternalDelay()); | 266 EXPECT_FALSE(state.ExternalDelay()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 } // namespace webrtc | 269 } // namespace webrtc |
| OLD | NEW |