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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "webrtc/rtc_base/constructormagic.h" | 24 #include "webrtc/rtc_base/constructormagic.h" |
25 #include "webrtc/rtc_base/optional.h" | 25 #include "webrtc/rtc_base/optional.h" |
26 | 26 |
27 namespace webrtc { | 27 namespace webrtc { |
28 | 28 |
29 class ApmDataDumper; | 29 class ApmDataDumper; |
30 | 30 |
31 // Handles the state and the conditions for the echo removal functionality. | 31 // Handles the state and the conditions for the echo removal functionality. |
32 class AecState { | 32 class AecState { |
33 public: | 33 public: |
34 explicit AecState(float echo_decay); | 34 explicit AecState(float reverb_decay); |
35 ~AecState(); | 35 ~AecState(); |
36 | 36 |
37 // Returns whether the linear filter estimate is usable. | 37 // Returns whether the linear filter estimate is usable. |
38 bool UsableLinearEstimate() const { return usable_linear_estimate_; } | 38 bool UsableLinearEstimate() const { return usable_linear_estimate_; } |
39 | 39 |
40 // Returns whether there has been echo leakage detected. | 40 // Returns whether there has been echo leakage detected. |
41 bool EchoLeakageDetected() const { return echo_leakage_detected_; } | 41 bool EchoLeakageDetected() const { return echo_leakage_detected_; } |
42 | 42 |
43 // Returns whether the render signal is currently active. | 43 // Returns whether the render signal is currently active. |
44 // TODO(peah): Deprecate this in an upcoming CL. | 44 // TODO(peah): Deprecate this in an upcoming CL. |
(...skipping 26 matching lines...) Expand all Loading... |
71 capture_signal_saturation_ = capture_signal_saturation; | 71 capture_signal_saturation_ = capture_signal_saturation; |
72 } | 72 } |
73 | 73 |
74 // Returns whether a probable headset setup has been detected. | 74 // Returns whether a probable headset setup has been detected. |
75 bool HeadsetDetected() const { return headset_detected_; } | 75 bool HeadsetDetected() const { return headset_detected_; } |
76 | 76 |
77 // Takes appropriate action at an echo path change. | 77 // Takes appropriate action at an echo path change. |
78 void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); | 78 void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); |
79 | 79 |
80 // Returns the decay factor for the echo reverberation. | 80 // Returns the decay factor for the echo reverberation. |
81 // TODO(peah): Make this adaptive. | 81 float ReverbDecay() const { return reverb_decay_; } |
82 float ReverbDecayFactor() const { return echo_decay_factor_; } | |
83 | 82 |
84 // Returns whether the echo suppression gain should be forced to zero. | 83 // Returns whether the echo suppression gain should be forced to zero. |
85 bool ForcedZeroGain() const { return force_zero_gain_; } | 84 bool ForcedZeroGain() const { return force_zero_gain_; } |
86 | 85 |
| 86 // Returns whether the echo in the capture signal is audible. |
| 87 bool InaudibleEcho() const { return echo_audibility_.InaudibleEcho(); } |
| 88 |
| 89 // Updates the aec state with the AEC output signal. |
| 90 void UpdateWithOutput(rtc::ArrayView<const float> e) { |
| 91 echo_audibility_.UpdateWithOutput(e); |
| 92 } |
| 93 |
87 // Updates the aec state. | 94 // Updates the aec state. |
88 void Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& | 95 void Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
89 adaptive_filter_frequency_response, | 96 adaptive_filter_frequency_response, |
| 97 const std::array<float, kAdaptiveFilterTimeDomainLength>& |
| 98 adaptive_filter_impulse_response, |
90 const rtc::Optional<size_t>& external_delay_samples, | 99 const rtc::Optional<size_t>& external_delay_samples, |
91 const RenderBuffer& render_buffer, | 100 const RenderBuffer& render_buffer, |
92 const std::array<float, kFftLengthBy2Plus1>& E2_main, | 101 const std::array<float, kFftLengthBy2Plus1>& E2_main, |
93 const std::array<float, kFftLengthBy2Plus1>& Y2, | 102 const std::array<float, kFftLengthBy2Plus1>& Y2, |
94 rtc::ArrayView<const float> x, | 103 rtc::ArrayView<const float> x, |
| 104 const std::array<float, kBlockSize>& s_main, |
95 bool echo_leakage_detected); | 105 bool echo_leakage_detected); |
96 | 106 |
97 private: | 107 private: |
| 108 class EchoAudibility { |
| 109 public: |
| 110 void Update(rtc::ArrayView<const float> x, |
| 111 const std::array<float, kBlockSize>& s); |
| 112 void UpdateWithOutput(rtc::ArrayView<const float> e); |
| 113 bool InaudibleEcho() const { return inaudible_echo_; } |
| 114 |
| 115 private: |
| 116 float max_nearend_ = 0.f; |
| 117 size_t max_nearend_counter_ = 0; |
| 118 size_t low_farend_counter_ = 0; |
| 119 bool inaudible_echo_ = false; |
| 120 }; |
| 121 |
| 122 void UpdateReverb(const std::array<float, kAdaptiveFilterTimeDomainLength>& |
| 123 impulse_response); |
| 124 |
98 static int instance_count_; | 125 static int instance_count_; |
99 std::unique_ptr<ApmDataDumper> data_dumper_; | 126 std::unique_ptr<ApmDataDumper> data_dumper_; |
100 ErlEstimator erl_estimator_; | 127 ErlEstimator erl_estimator_; |
101 ErleEstimator erle_estimator_; | 128 ErleEstimator erle_estimator_; |
102 int echo_path_change_counter_; | 129 int echo_path_change_counter_; |
103 size_t blocks_with_filter_adaptation_ = 0; | 130 size_t blocks_with_filter_adaptation_ = 0; |
104 bool usable_linear_estimate_ = false; | 131 bool usable_linear_estimate_ = false; |
105 bool echo_leakage_detected_ = false; | 132 bool echo_leakage_detected_ = false; |
106 bool capture_signal_saturation_ = false; | 133 bool capture_signal_saturation_ = false; |
107 bool echo_saturation_ = false; | 134 bool echo_saturation_ = false; |
108 bool headset_detected_ = false; | 135 bool headset_detected_ = false; |
109 float previous_max_sample_ = 0.f; | 136 float previous_max_sample_ = 0.f; |
110 bool force_zero_gain_ = false; | 137 bool force_zero_gain_ = false; |
111 bool render_received_ = false; | 138 bool render_received_ = false; |
112 size_t force_zero_gain_counter_ = 0; | 139 size_t force_zero_gain_counter_ = 0; |
113 rtc::Optional<size_t> filter_delay_; | 140 rtc::Optional<size_t> filter_delay_; |
114 rtc::Optional<size_t> external_delay_; | 141 rtc::Optional<size_t> external_delay_; |
115 size_t blocks_since_last_saturation_ = 1000; | 142 size_t blocks_since_last_saturation_ = 1000; |
116 const float echo_decay_factor_; | 143 float reverb_decay_; |
| 144 float reverb_decay_to_test_ = 0.9f; |
| 145 float reverb_decay_candidate_ = 0.f; |
| 146 float reverb_decay_candidate_residual_ = -1.f; |
| 147 EchoAudibility echo_audibility_; |
| 148 |
117 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AecState); | 149 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AecState); |
118 }; | 150 }; |
119 | 151 |
120 } // namespace webrtc | 152 } // namespace webrtc |
121 | 153 |
122 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ | 154 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ |
OLD | NEW |