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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ | |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ | |
13 | |
14 #include <algorithm> | |
15 #include <memory> | |
16 #include <vector> | |
17 | |
18 #include "webrtc/base/array_view.h" | |
19 #include "webrtc/base/constructormagic.h" | |
20 #include "webrtc/base/optional.h" | |
21 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | |
22 #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" | |
23 #include "webrtc/modules/audio_processing/aec3/erle_estimator.h" | |
24 #include "webrtc/modules/audio_processing/aec3/erl_estimator.h" | |
25 #include "webrtc/modules/audio_processing/aec3/fft_buffer.h" | |
26 | |
27 namespace webrtc { | |
28 | |
29 class ApmDataDumper; | |
30 | |
31 // Handles the state and the conditions for the echo removal functionality. | |
32 class AecState { | |
33 public: | |
34 AecState(); | |
35 ~AecState(); | |
36 | |
37 // Returns whether the linear filter estimate is usable. | |
38 bool UsableLinearEstimate() const { return usable_linear_estimate_; } | |
39 | |
40 // Returns whether there has been echo leakage detected. | |
41 bool EchoLeakageDetected() const { return echo_leakage_detected_; } | |
42 | |
43 // Returns whether it is possible at all to use the model based echo removal | |
44 // functionalities. | |
45 bool ModelBasedAecFeasible() const { return model_based_aec_feasible_; } | |
46 | |
47 // Returns whether the render signal is currently active. | |
48 bool ActiveRender() const { return active_render_counter_ > 0; } | |
49 | |
50 // Returns the ERLE. | |
51 const std::array<float, kFftLengthBy2Plus1>& Erle() const { | |
52 return erle_estimator_.Erle(); | |
53 } | |
54 | |
55 // Returns the ERL. | |
56 const std::array<float, kFftLengthBy2Plus1>& Erl() const { | |
57 return erl_estimator_.Erl(); | |
58 } | |
59 | |
60 // Returns the delay estimate based on the linear filter, | |
hlundin-webrtc
2017/02/22 15:24:06
, -> .
peah-webrtc
2017/02/22 23:51:37
Done.
| |
61 const rtc::Optional<size_t>& FilterDelay() const { return filter_delay_; } | |
hlundin-webrtc
2017/02/22 15:24:06
I think you should return rtc::Optional<size_t>, n
peah-webrtc
2017/02/22 23:51:37
I adopt your suggested change, but I'm not convinc
hlundin-webrtc
2017/02/23 07:42:09
Hmm. Yeah, you are probably right. Feel free to ch
peah-webrtc
2017/02/23 11:18:32
Acknowledged.
| |
62 | |
63 // Returns the externally provided delay. | |
64 const rtc::Optional<size_t>& ExternalDelay() const { return external_delay_; } | |
hlundin-webrtc
2017/02/22 15:24:06
I think you should return rtc::Optional<size_t>, n
peah-webrtc
2017/02/22 23:51:37
Done.
| |
65 | |
66 // Returns the bands where the linear filter is reliable. | |
67 const std::array<bool, kFftLengthBy2Plus1>& BandsWithReliableFilter() const { | |
68 return bands_with_reliable_filter_; | |
69 } | |
70 | |
71 // Reports whether the filter is poorly aligned. | |
72 bool PoorlyAlignedFilter() const { | |
73 return FilterDelay() ? *FilterDelay() > 0.75f * filter_length_ : false; | |
74 } | |
75 | |
76 // Returns the strength of the filter. | |
77 const std::array<float, kFftLengthBy2Plus1>& FilterEstimateStrength() const { | |
78 return filter_estimate_strength_; | |
79 } | |
80 | |
81 // Returns whether the capture signal is saturated. | |
82 bool SaturatedCapture() const { return capture_signal_saturation_; } | |
83 | |
84 // Updates the capture signal saturation. | |
85 void UpdateCaptureSaturation(bool capture_signal_saturation) { | |
86 capture_signal_saturation_ = capture_signal_saturation; | |
87 } | |
88 | |
89 // Returns whether a probably headset setup has been detected. | |
hlundin-webrtc
2017/02/22 15:24:06
probably -> probable?
peah-webrtc
2017/02/22 23:51:37
Done.
| |
90 bool HeadsetDetected() const { return headset_detected_; } | |
91 | |
92 // Updates the aec state. | |
93 void Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& | |
94 filter_frequency_response, | |
95 const rtc::Optional<size_t>& external_delay_samples, | |
96 const FftBuffer& X_buffer, | |
97 const std::array<float, kFftLengthBy2Plus1>& E2_main, | |
98 const std::array<float, kFftLengthBy2Plus1>& E2_shadow, | |
99 const std::array<float, kFftLengthBy2Plus1>& Y2, | |
100 rtc::ArrayView<const float> x, | |
101 const EchoPathVariability& echo_path_variability, | |
102 bool echo_leakage_detected); | |
103 | |
104 private: | |
105 static int instance_count_; | |
106 std::unique_ptr<ApmDataDumper> data_dumper_; | |
107 ErlEstimator erl_estimator_; | |
108 ErleEstimator erle_estimator_; | |
109 int echo_path_change_counter_; | |
110 int active_render_counter_; | |
111 bool usable_linear_estimate_ = false; | |
112 bool echo_leakage_detected_ = false; | |
113 bool model_based_aec_feasible_ = false; | |
114 bool capture_signal_saturation_ = false; | |
115 bool headset_detected_ = false; | |
116 rtc::Optional<size_t> filter_delay_; | |
117 rtc::Optional<size_t> external_delay_; | |
118 std::array<bool, kFftLengthBy2Plus1> bands_with_reliable_filter_; | |
119 std::array<float, kFftLengthBy2Plus1> filter_estimate_strength_; | |
120 size_t filter_length_; | |
121 | |
122 RTC_DISALLOW_COPY_AND_ASSIGN(AecState); | |
123 }; | |
124 | |
125 } // namespace webrtc | |
126 | |
127 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ | |
OLD | NEW |