OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_processing/aec3/aec_state.h" | |
12 | |
13 #include <math.h> | |
14 #include <numeric> | |
15 #include <vector> | |
16 | |
17 #include "webrtc/base/checks.h" | |
18 | |
19 namespace webrtc { | |
20 namespace { | |
21 | |
22 // Updates the bands where the filter performs reliable. | |
23 void UpdateBandsWithReliableFilter( | |
24 rtc::ArrayView<const float> E2_main, | |
25 rtc::ArrayView<const float> E2_shadow, | |
26 rtc::ArrayView<const float> X2, | |
27 rtc::ArrayView<const float> Y2, | |
28 rtc::ArrayView<bool> bands_with_reliable_filter) { | |
29 const float kX2Min = 44015068.0f / 1000.f; | |
ivoc
2017/02/10 13:52:33
A comment about where this value comes from would
peah-webrtc
2017/02/20 07:37:15
Good point! It has now been removed though.
Done.
ivoc
2017/02/21 17:26:00
Acknowledged.
peah-webrtc
2017/02/21 23:00:39
Acknowledged.
| |
30 for (size_t k = 1; k < kFftLengthBy2 - 5; ++k) { | |
31 if (X2[k] > kX2Min) { | |
32 if (E2_main[k] > Y2[k]) { | |
33 bands_with_reliable_filter[k] = false; | |
34 } else { | |
ivoc
2017/02/10 13:52:33
this can be "else if" to avoid the nested if. One
peah-webrtc
2017/02/20 07:37:15
You definitely have a point. And in the tuning, th
ivoc
2017/02/21 17:26:00
Acknowledged.
peah-webrtc
2017/02/21 23:00:39
Acknowledged.
| |
35 if ((2 * E2_main[k] < Y2[k]) || (E2_shadow[k] < E2_main[k])) { | |
36 bands_with_reliable_filter[k] = true; | |
37 } | |
38 } | |
39 } | |
40 } | |
41 | |
42 bands_with_reliable_filter[0] = bands_with_reliable_filter[1]; | |
43 std::fill(bands_with_reliable_filter.begin() + kFftLengthBy2 - 5, | |
44 bands_with_reliable_filter.end(), | |
45 bands_with_reliable_filter[kFftLengthBy2 - 6]); | |
46 } | |
47 | |
48 constexpr int kActiveRenderCounterInitial = 50; | |
49 constexpr int kActiveRenderCounterMax = 200; | |
50 constexpr int kEchoPathChangeCounterInitial = 50; | |
51 constexpr int kEchoPathChangeCounterMax = 200; | |
52 | |
53 } // namespace | |
54 | |
55 AecState::AecState() | |
56 : echo_path_change_counter_(kEchoPathChangeCounterInitial), | |
57 active_render_counter_(kActiveRenderCounterInitial) { | |
58 bands_with_reliable_filter_.fill(false); | |
59 } | |
60 | |
61 AecState::~AecState() = default; | |
62 | |
63 void AecState::Update(const FftBuffer& X_buffer, | |
64 const std::array<float, kFftLengthBy2Plus1>& E2_main, | |
65 const std::array<float, kFftLengthBy2Plus1>& E2_shadow, | |
66 const std::array<float, kFftLengthBy2Plus1>& Y2, | |
67 rtc::ArrayView<const float> x, | |
68 const DelayHandler& delay_handler, | |
69 const EchoPathVariability& echo_path_variability, | |
70 bool echo_leakage_detected) { | |
71 const rtc::Optional<size_t> linear_filter_based_delay = | |
72 delay_handler.FilterDelay(); | |
73 | |
74 const float x_energy = | |
75 std::accumulate(x.begin(), x.end(), 0.f, | |
76 [](float a, float b) -> float { return a + b * b; }); | |
77 echo_path_change_counter_ = echo_path_variability.AudioPathChanged() | |
78 ? kEchoPathChangeCounterMax | |
79 : echo_path_change_counter_ - 1; | |
80 active_render_counter_ = x_energy > 10000 * kFftLengthBy2 | |
81 ? kActiveRenderCounterMax | |
82 : active_render_counter_ - 1; | |
83 | |
84 usable_linear_estimate_ = | |
85 linear_filter_based_delay && echo_path_change_counter_ <= 0; | |
86 | |
87 echo_leakage_detected_ = echo_leakage_detected; | |
88 | |
89 model_based_aec_feasible_ = | |
90 usable_linear_estimate_ || | |
91 (delay_handler.ExternalDelay() && echo_path_change_counter_ <= 0); | |
92 | |
93 if (usable_linear_estimate_) { | |
94 const std::array<float, kFftLengthBy2Plus1>& X2 = | |
95 X_buffer.Spectrum(*linear_filter_based_delay); | |
96 | |
97 UpdateBandsWithReliableFilter(E2_main, E2_shadow, X2, Y2, | |
98 bands_with_reliable_filter_); | |
99 | |
100 // TODO(peah): Expose these as stats. | |
101 erle_estimator_.Update(X2, Y2, E2_main); | |
102 erl_estimator_.Update(X2, Y2); | |
103 } | |
104 } | |
105 | |
106 } // namespace webrtc | |
OLD | NEW |