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/residual_echo_estimator.h" | 11 #include "webrtc/modules/audio_processing/aec3/residual_echo_estimator.h" |
12 | 12 |
13 // TODO(peah): Reactivate once the next CL has landed. | |
14 #if 0 | |
15 #include "webrtc/base/random.h" | 13 #include "webrtc/base/random.h" |
16 #include "webrtc/modules/audio_processing/aec3/aec_state.h" | 14 #include "webrtc/modules/audio_processing/aec3/aec_state.h" |
17 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" | 15 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
18 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | 16 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
19 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
20 | 18 |
21 namespace webrtc { | 19 namespace webrtc { |
22 | 20 |
23 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 21 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
24 | 22 |
25 // Verifies that the check for non-null output gains works. | 23 // Verifies that the check for non-null output residual echo power works. |
26 TEST(ResidualEchoEstimator, NullOutputGains) { | 24 TEST(ResidualEchoEstimator, NullResidualEchoPowerOutput) { |
27 AecState aec_state; | 25 AecState aec_state; |
28 FftBuffer X_buffer(Aec3Optimization::kNone, 10, std::vector<size_t>(1, 10)); | 26 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 10, |
| 27 std::vector<size_t>(1, 10)); |
29 std::vector<std::array<float, kFftLengthBy2Plus1>> H2; | 28 std::vector<std::array<float, kFftLengthBy2Plus1>> H2; |
30 std::array<float, kFftLengthBy2Plus1> E2_main; | |
31 std::array<float, kFftLengthBy2Plus1> E2_shadow; | |
32 std::array<float, kFftLengthBy2Plus1> S2_linear; | 29 std::array<float, kFftLengthBy2Plus1> S2_linear; |
33 std::array<float, kFftLengthBy2Plus1> S2_fallback; | |
34 std::array<float, kFftLengthBy2Plus1> Y2; | 30 std::array<float, kFftLengthBy2Plus1> Y2; |
35 | 31 EXPECT_DEATH(ResidualEchoEstimator().Estimate(true, aec_state, render_buffer, |
36 EXPECT_DEATH(ResidualEchoEstimator().Estimate(true, aec_state, X_buffer, H2, | 32 S2_linear, Y2, nullptr), |
37 E2_main, E2_shadow, S2_linear, | |
38 S2_fallback, Y2, nullptr), | |
39 ""); | 33 ""); |
40 } | 34 } |
41 | 35 |
42 #endif | 36 #endif |
43 | 37 |
44 TEST(ResidualEchoEstimator, BasicTest) { | 38 TEST(ResidualEchoEstimator, BasicTest) { |
45 ResidualEchoEstimator estimator; | 39 ResidualEchoEstimator estimator; |
46 AecState aec_state; | 40 AecState aec_state; |
47 FftBuffer X_buffer(Aec3Optimization::kNone, 10, std::vector<size_t>(1, 10)); | 41 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 10, |
| 42 std::vector<size_t>(1, 10)); |
48 std::array<float, kFftLengthBy2Plus1> E2_main; | 43 std::array<float, kFftLengthBy2Plus1> E2_main; |
49 std::array<float, kFftLengthBy2Plus1> E2_shadow; | 44 std::array<float, kFftLengthBy2Plus1> E2_shadow; |
50 std::array<float, kFftLengthBy2Plus1> S2_linear; | 45 std::array<float, kFftLengthBy2Plus1> S2_linear; |
51 std::array<float, kFftLengthBy2Plus1> S2_fallback; | 46 std::array<float, kFftLengthBy2Plus1> S2_fallback; |
52 std::array<float, kFftLengthBy2Plus1> Y2; | 47 std::array<float, kFftLengthBy2Plus1> Y2; |
53 std::array<float, kFftLengthBy2Plus1> R2; | 48 std::array<float, kFftLengthBy2Plus1> R2; |
54 EchoPathVariability echo_path_variability(false, false); | 49 EchoPathVariability echo_path_variability(false, false); |
55 std::array<float, kBlockSize> x; | 50 std::vector<std::vector<float>> x(3, std::vector<float>(kBlockSize, 0.f)); |
56 std::vector<std::array<float, kFftLengthBy2Plus1>> H2(10); | 51 std::vector<std::array<float, kFftLengthBy2Plus1>> H2(10); |
57 Random random_generator(42U); | 52 Random random_generator(42U); |
58 FftData X; | 53 FftData X; |
59 std::array<float, kBlockSize> x_old; | 54 std::array<float, kBlockSize> x_old; |
60 Aec3Fft fft; | 55 Aec3Fft fft; |
61 | 56 |
62 for (auto& H2_k : H2) { | 57 for (auto& H2_k : H2) { |
63 H2_k.fill(0.01f); | 58 H2_k.fill(0.01f); |
64 } | 59 } |
65 H2[2].fill(10.f); | 60 H2[2].fill(10.f); |
| 61 H2[2][0] = 0.1f; |
66 | 62 |
67 constexpr float kLevel = 10.f; | 63 constexpr float kLevel = 10.f; |
68 E2_shadow.fill(kLevel); | 64 E2_shadow.fill(kLevel); |
69 E2_main.fill(kLevel); | 65 E2_main.fill(kLevel); |
70 S2_linear.fill(kLevel); | 66 S2_linear.fill(kLevel); |
71 S2_fallback.fill(kLevel); | 67 S2_fallback.fill(kLevel); |
72 Y2.fill(kLevel); | 68 Y2.fill(kLevel); |
73 | 69 |
74 for (int k = 0; k < 100; ++k) { | 70 for (int k = 0; k < 2000; ++k) { |
75 RandomizeSampleVector(&random_generator, x); | 71 RandomizeSampleVector(&random_generator, x[0]); |
76 fft.PaddedFft(x, x_old, &X); | 72 std::for_each(x[0].begin(), x[0].end(), [](float& a) { a /= 30.f; }); |
77 X_buffer.Insert(X); | 73 fft.PaddedFft(x[0], x_old, &X); |
| 74 render_buffer.Insert(x); |
78 | 75 |
79 aec_state.Update(H2, rtc::Optional<size_t>(2), X_buffer, E2_main, E2_shadow, | 76 aec_state.HandleEchoPathChange(echo_path_variability); |
80 Y2, x, echo_path_variability, false); | 77 aec_state.Update(H2, rtc::Optional<size_t>(2), render_buffer, E2_main, Y2, |
| 78 x[0], false); |
81 | 79 |
82 estimator.Estimate(true, aec_state, X_buffer, H2, E2_main, E2_shadow, | 80 estimator.Estimate(true, aec_state, render_buffer, S2_linear, Y2, &R2); |
83 S2_linear, S2_fallback, Y2, &R2); | |
84 } | 81 } |
85 std::for_each(R2.begin(), R2.end(), | 82 std::for_each(R2.begin(), R2.end(), |
86 [&](float a) { EXPECT_NEAR(kLevel, a, 0.1f); }); | 83 [&](float a) { EXPECT_NEAR(kLevel, a, 0.1f); }); |
87 } | 84 } |
88 | 85 |
89 } // namespace webrtc | 86 } // namespace webrtc |
90 | |
91 #endif | |
OLD | NEW |