peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 14 | #include <stddef.h> |
| 15 | #include <array> |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 16 | #include <memory> |
| 17 | #include <vector> |
| 18 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "api/array_view.h" |
Gustaf Ullberg | 3646f97 | 2018-02-14 15:19:04 +0100 | [diff] [blame] | 21 | #include "api/audio/echo_canceller3_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/audio_processing/aec3/aec3_common.h" |
Per Åhgren | 3ab308f | 2018-02-21 08:46:03 +0100 | [diff] [blame] | 23 | #include "modules/audio_processing/aec3/delay_estimate.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 24 | #include "modules/audio_processing/aec3/echo_audibility.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/audio_processing/aec3/echo_path_variability.h" |
| 26 | #include "modules/audio_processing/aec3/erl_estimator.h" |
| 27 | #include "modules/audio_processing/aec3/erle_estimator.h" |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 28 | #include "modules/audio_processing/aec3/filter_analyzer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "modules/audio_processing/aec3/render_buffer.h" |
Jesús de Vicente Peña | c98849c | 2018-10-22 11:41:05 +0200 | [diff] [blame] | 30 | #include "modules/audio_processing/aec3/render_reverb_model.h" |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 31 | #include "modules/audio_processing/aec3/reverb_model_estimator.h" |
Per Åhgren | b20b937 | 2018-07-13 00:22:54 +0200 | [diff] [blame] | 32 | #include "modules/audio_processing/aec3/subtractor_output.h" |
| 33 | #include "modules/audio_processing/aec3/subtractor_output_analyzer.h" |
Per Åhgren | 12eb858 | 2018-03-06 10:40:51 +0100 | [diff] [blame] | 34 | #include "modules/audio_processing/aec3/suppression_gain_limiter.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 35 | |
| 36 | namespace webrtc { |
| 37 | |
| 38 | class ApmDataDumper; |
| 39 | |
| 40 | // Handles the state and the conditions for the echo removal functionality. |
| 41 | class AecState { |
| 42 | public: |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 43 | explicit AecState(const EchoCanceller3Config& config); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 44 | ~AecState(); |
| 45 | |
Per Åhgren | 4b3bc0f | 2017-12-20 15:26:13 +0100 | [diff] [blame] | 46 | // Returns whether the echo subtractor can be used to determine the residual |
| 47 | // echo. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 48 | bool UsableLinearEstimate() const { |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 49 | if (use_legacy_filter_quality_) { |
| 50 | return legacy_filter_quality_state_.LinearFilterUsable(); |
| 51 | } |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 52 | return filter_quality_state_.LinearFilterUsable(); |
| 53 | } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 54 | |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 55 | // Returns whether the echo subtractor output should be used as output. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 56 | bool UseLinearFilterOutput() const { |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 57 | if (use_legacy_filter_quality_) { |
| 58 | return legacy_filter_quality_state_.LinearFilterUsable(); |
| 59 | } |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 60 | return filter_quality_state_.LinearFilterUsable(); |
| 61 | } |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 62 | |
| 63 | // Returns the estimated echo path gain. |
Per Åhgren | ced31ba | 2018-05-09 11:48:49 +0200 | [diff] [blame] | 64 | float EchoPathGain() const { return filter_analyzer_.Gain(); } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 65 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 66 | // Returns whether the render signal is currently active. |
Per Åhgren | 4b3bc0f | 2017-12-20 15:26:13 +0100 | [diff] [blame] | 67 | bool ActiveRender() const { return blocks_with_active_render_ > 200; } |
peah | ebe7778 | 2017-02-27 07:29:21 -0800 | [diff] [blame] | 68 | |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 69 | // Returns the appropriate scaling of the residual echo to match the |
| 70 | // audibility. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 71 | void GetResidualEchoScaling(rtc::ArrayView<float> residual_scaling) const; |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 72 | |
| 73 | // Returns whether the stationary properties of the signals are used in the |
| 74 | // aec. |
Per Åhgren | f4801a1 | 2018-09-27 13:14:02 +0200 | [diff] [blame] | 75 | bool UseStationaryProperties() const { |
| 76 | return config_.echo_audibility.use_stationary_properties; |
| 77 | } |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 78 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 79 | // Returns the ERLE. |
| 80 | const std::array<float, kFftLengthBy2Plus1>& Erle() const { |
| 81 | return erle_estimator_.Erle(); |
| 82 | } |
| 83 | |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 84 | // Returns an offset to apply to the estimation of the residual echo |
| 85 | // computation. Returning nullopt means that no offset should be used, while |
| 86 | // any other value will be applied as a multiplier to the estimated residual |
| 87 | // echo. |
| 88 | absl::optional<float> ErleUncertainty() const; |
Gustaf Ullberg | 6c618c7 | 2018-06-28 14:21:16 +0200 | [diff] [blame] | 89 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 90 | // Returns the fullband ERLE estimate in log2 units. |
| 91 | float FullBandErleLog2() const { return erle_estimator_.FullbandErleLog2(); } |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 92 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 93 | // Returns the ERL. |
| 94 | const std::array<float, kFftLengthBy2Plus1>& Erl() const { |
| 95 | return erl_estimator_.Erl(); |
| 96 | } |
| 97 | |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 98 | // Returns the time-domain ERL. |
| 99 | float ErlTimeDomain() const { return erl_estimator_.ErlTimeDomain(); } |
| 100 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 101 | // Returns the delay estimate based on the linear filter. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 102 | int FilterDelayBlocks() const { return delay_state_.DirectPathFilterDelay(); } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 103 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 104 | // Returns whether the capture signal is saturated. |
| 105 | bool SaturatedCapture() const { return capture_signal_saturation_; } |
| 106 | |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 107 | // Returns whether the echo signal is saturated. |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 108 | bool SaturatedEcho() const { |
| 109 | return use_legacy_saturation_behavior_ |
| 110 | ? legacy_saturation_detector_.SaturatedEcho() |
| 111 | : saturation_detector_.SaturatedEcho(); |
| 112 | } |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 113 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 114 | // Updates the capture signal saturation. |
| 115 | void UpdateCaptureSaturation(bool capture_signal_saturation) { |
| 116 | capture_signal_saturation_ = capture_signal_saturation; |
| 117 | } |
| 118 | |
Per Åhgren | 1b4059e | 2017-10-15 20:19:21 +0200 | [diff] [blame] | 119 | // Returns whether the transparent mode is active |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 120 | bool TransparentMode() const { return transparent_state_.Active(); } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 121 | |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 122 | // Takes appropriate action at an echo path change. |
| 123 | void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); |
| 124 | |
peah | 8942045 | 2017-04-07 06:13:39 -0700 | [diff] [blame] | 125 | // Returns the decay factor for the echo reverberation. |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 126 | float ReverbDecay() const { return reverb_model_estimator_.ReverbDecay(); } |
peah | 8942045 | 2017-04-07 06:13:39 -0700 | [diff] [blame] | 127 | |
Per Åhgren | ef5d5af | 2018-07-31 00:03:46 +0200 | [diff] [blame] | 128 | // Return the frequency response of the reverberant echo. |
| 129 | rtc::ArrayView<const float> GetReverbFrequencyResponse() const { |
| 130 | return reverb_model_estimator_.GetReverbFrequencyResponse(); |
| 131 | } |
| 132 | |
Per Åhgren | b6b00dc | 2018-02-20 22:18:27 +0100 | [diff] [blame] | 133 | // Returns the upper limit for the echo suppression gain. |
Per Åhgren | 12eb858 | 2018-03-06 10:40:51 +0100 | [diff] [blame] | 134 | float SuppressionGainLimit() const { |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 135 | if (use_suppressor_gain_limiter_) { |
| 136 | return suppression_gain_limiter_.Limit(); |
| 137 | } else { |
| 138 | return 1.f; |
| 139 | } |
Per Åhgren | 12eb858 | 2018-03-06 10:40:51 +0100 | [diff] [blame] | 140 | } |
peah | 6d822ad | 2017-04-10 13:52:14 -0700 | [diff] [blame] | 141 | |
Jesús de Vicente Peña | dd09287 | 2018-05-25 16:55:11 +0200 | [diff] [blame] | 142 | // Returns whether the suppression gain limiter is active. |
| 143 | bool IsSuppressionGainLimitActive() const { |
| 144 | return suppression_gain_limiter_.IsActive(); |
| 145 | } |
| 146 | |
Jesús de Vicente Peña | 02e9e44 | 2018-08-29 13:34:07 +0200 | [diff] [blame] | 147 | // Returns whether the transition for going out of the initial stated has |
| 148 | // been triggered. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 149 | bool TransitionTriggered() const { |
| 150 | return initial_state_.TransitionTriggered(); |
| 151 | } |
Per Åhgren | a98c807 | 2018-01-15 19:17:16 +0100 | [diff] [blame] | 152 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 153 | // Updates the aec state. |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 154 | void Update(const absl::optional<DelayEstimate>& external_delay, |
Per Åhgren | 3ab308f | 2018-02-21 08:46:03 +0100 | [diff] [blame] | 155 | const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 156 | adaptive_filter_frequency_response, |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame] | 157 | const std::vector<float>& adaptive_filter_impulse_response, |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 158 | const RenderBuffer& render_buffer, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 159 | const std::array<float, kFftLengthBy2Plus1>& E2_main, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 160 | const std::array<float, kFftLengthBy2Plus1>& Y2, |
Per Åhgren | b20b937 | 2018-07-13 00:22:54 +0200 | [diff] [blame] | 161 | const SubtractorOutput& subtractor_output, |
| 162 | rtc::ArrayView<const float> y); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 163 | |
Jesús de Vicente Peña | 075cb2b | 2018-06-13 15:13:55 +0200 | [diff] [blame] | 164 | // Returns filter length in blocks. |
| 165 | int FilterLengthBlocks() const { |
| 166 | return filter_analyzer_.FilterLengthBlocks(); |
| 167 | } |
| 168 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 169 | private: |
| 170 | static int instance_count_; |
| 171 | std::unique_ptr<ApmDataDumper> data_dumper_; |
Per Åhgren | 90e3fbd | 2018-05-16 15:25:04 +0200 | [diff] [blame] | 172 | const EchoCanceller3Config config_; |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 173 | const bool use_legacy_saturation_behavior_; |
| 174 | const bool enable_erle_resets_at_gain_changes_; |
Jesús de Vicente Peña | c98849c | 2018-10-22 11:41:05 +0200 | [diff] [blame] | 175 | const bool enable_erle_updates_during_reverb_; |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 176 | const bool use_legacy_filter_quality_; |
| 177 | const bool use_suppressor_gain_limiter_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 178 | |
| 179 | // Class for controlling the transition from the intial state, which in turn |
| 180 | // controls when the filter parameters for the initial state should be used. |
| 181 | class InitialState { |
| 182 | public: |
| 183 | explicit InitialState(const EchoCanceller3Config& config); |
| 184 | // Resets the state to again begin in the initial state. |
| 185 | void Reset(); |
| 186 | |
| 187 | // Updates the state based on new data. |
| 188 | void Update(bool active_render, bool saturated_capture); |
| 189 | |
| 190 | // Returns whether the initial state is active or not. |
| 191 | bool InitialStateActive() const { return initial_state_; } |
| 192 | |
| 193 | // Returns that the transition from the initial state has was started. |
| 194 | bool TransitionTriggered() const { return transition_triggered_; } |
| 195 | |
| 196 | private: |
| 197 | const bool conservative_initial_phase_; |
| 198 | const float initial_state_seconds_; |
| 199 | bool transition_triggered_ = false; |
| 200 | bool initial_state_ = true; |
| 201 | size_t strong_not_saturated_render_blocks_ = 0; |
| 202 | } initial_state_; |
| 203 | |
| 204 | // Class for choosing the direct-path delay relative to the beginning of the |
| 205 | // filter, as well as any other data related to the delay used within |
| 206 | // AecState. |
| 207 | class FilterDelay { |
| 208 | public: |
| 209 | explicit FilterDelay(const EchoCanceller3Config& config); |
| 210 | |
| 211 | // Returns whether an external delay has been reported to the AecState (from |
| 212 | // the delay estimator). |
| 213 | bool ExternalDelayReported() const { return external_delay_reported_; } |
| 214 | |
| 215 | // Returns the delay in blocks relative to the beginning of the filter that |
| 216 | // corresponds to the direct path of the echo. |
| 217 | int DirectPathFilterDelay() const { return filter_delay_blocks_; } |
| 218 | |
| 219 | // Updates the delay estimates based on new data. |
| 220 | void Update(const FilterAnalyzer& filter_analyzer, |
| 221 | const absl::optional<DelayEstimate>& external_delay, |
| 222 | size_t blocks_with_proper_filter_adaptation); |
| 223 | |
| 224 | private: |
| 225 | const int delay_headroom_blocks_; |
| 226 | bool external_delay_reported_ = false; |
| 227 | int filter_delay_blocks_ = 0; |
| 228 | absl::optional<DelayEstimate> external_delay_; |
| 229 | } delay_state_; |
| 230 | |
| 231 | // Class for detecting and toggling the transparent mode which causes the |
| 232 | // suppressor to apply no suppression. |
| 233 | class TransparentMode { |
| 234 | public: |
| 235 | explicit TransparentMode(const EchoCanceller3Config& config); |
| 236 | |
| 237 | // Returns whether the transparent mode should be active. |
| 238 | bool Active() const { return transparency_activated_; } |
| 239 | |
| 240 | // Resets the state of the detector. |
| 241 | void Reset(); |
| 242 | |
| 243 | // Updates the detection deciscion based on new data. |
| 244 | void Update(int filter_delay_blocks, |
| 245 | bool consistent_filter, |
| 246 | bool converged_filter, |
| 247 | bool diverged_filter, |
| 248 | bool active_render, |
| 249 | bool saturated_capture); |
| 250 | |
| 251 | private: |
| 252 | const bool bounded_erl_; |
| 253 | const bool linear_and_stable_echo_path_; |
| 254 | size_t capture_block_counter_ = 0; |
| 255 | bool transparency_activated_ = false; |
| 256 | size_t active_blocks_since_sane_filter_; |
| 257 | bool sane_filter_observed_ = false; |
| 258 | bool finite_erl_recently_detected_ = false; |
| 259 | size_t non_converged_sequence_size_; |
| 260 | size_t diverged_sequence_size_ = 0; |
| 261 | size_t active_non_converged_sequence_size_ = 0; |
| 262 | size_t num_converged_blocks_ = 0; |
| 263 | bool recent_convergence_during_activity_ = false; |
| 264 | size_t strong_not_saturated_render_blocks_ = 0; |
| 265 | } transparent_state_; |
| 266 | |
| 267 | // Class for analyzing how well the linear filter is, and can be expected to, |
| 268 | // perform on the current signals. The purpose of this is for using to |
| 269 | // select the echo suppression functionality as well as the input to the echo |
| 270 | // suppressor. |
| 271 | class FilteringQualityAnalyzer { |
| 272 | public: |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 273 | FilteringQualityAnalyzer(const EchoCanceller3Config& config); |
| 274 | |
| 275 | // Returns whether the the linear filter can be used for the echo |
| 276 | // canceller output. |
| 277 | bool LinearFilterUsable() const { return usable_linear_estimate_; } |
| 278 | |
| 279 | // Resets the state of the analyzer. |
| 280 | void Reset(); |
| 281 | |
| 282 | // Updates the analysis based on new data. |
| 283 | void Update(bool active_render, |
| 284 | bool transparent_mode, |
| 285 | bool saturated_capture, |
| 286 | bool consistent_estimate_, |
| 287 | const absl::optional<DelayEstimate>& external_delay, |
| 288 | bool converged_filter); |
| 289 | |
| 290 | private: |
| 291 | bool usable_linear_estimate_ = false; |
| 292 | size_t filter_update_blocks_since_reset_ = 0; |
| 293 | size_t filter_update_blocks_since_start_ = 0; |
| 294 | bool convergence_seen_ = false; |
| 295 | } filter_quality_state_; |
| 296 | |
| 297 | // Class containing the legacy functionality for analyzing how well the linear |
| 298 | // filter is, and can be expected to perform on the current signals. The |
| 299 | // purpose of this is for using to select the echo suppression functionality |
| 300 | // as well as the input to the echo suppressor. |
| 301 | class LegacyFilteringQualityAnalyzer { |
| 302 | public: |
| 303 | explicit LegacyFilteringQualityAnalyzer(const EchoCanceller3Config& config); |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 304 | |
| 305 | // Returns whether the the linear filter is can be used for the echo |
| 306 | // canceller output. |
| 307 | bool LinearFilterUsable() const { return usable_linear_estimate_; } |
| 308 | |
| 309 | // Resets the state of the analyzer. |
| 310 | void Reset(); |
| 311 | |
| 312 | // Updates the analysis based on new data. |
| 313 | void Update(bool saturated_echo, |
| 314 | bool active_render, |
| 315 | bool saturated_capture, |
| 316 | bool transparent_mode, |
| 317 | const absl::optional<DelayEstimate>& external_delay, |
| 318 | bool converged_filter, |
| 319 | bool diverged_filter); |
| 320 | |
| 321 | private: |
| 322 | const bool conservative_initial_phase_; |
| 323 | const float required_blocks_for_convergence_; |
| 324 | const bool linear_and_stable_echo_path_; |
| 325 | bool usable_linear_estimate_ = false; |
| 326 | size_t strong_not_saturated_render_blocks_ = 0; |
| 327 | size_t non_converged_sequence_size_; |
| 328 | size_t diverged_sequence_size_ = 0; |
| 329 | size_t active_non_converged_sequence_size_ = 0; |
| 330 | bool recent_convergence_during_activity_ = false; |
| 331 | bool recent_convergence_ = false; |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 332 | } legacy_filter_quality_state_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 333 | |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 334 | // Class for detecting whether the echo is to be considered to be |
| 335 | // saturated. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 336 | class SaturationDetector { |
| 337 | public: |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 338 | // Returns whether the echo is to be considered saturated. |
| 339 | bool SaturatedEcho() const { return saturated_echo_; }; |
| 340 | |
| 341 | // Updates the detection decision based on new data. |
| 342 | void Update(rtc::ArrayView<const float> x, |
| 343 | bool saturated_capture, |
| 344 | bool usable_linear_estimate, |
| 345 | const SubtractorOutput& subtractor_output, |
| 346 | float echo_path_gain); |
| 347 | |
| 348 | private: |
| 349 | bool saturated_echo_ = false; |
| 350 | } saturation_detector_; |
| 351 | |
| 352 | // Legacy class for detecting whether the echo is to be considered to be |
| 353 | // saturated. This is kept as a fallback solution to use instead of the class |
| 354 | // SaturationDetector, |
| 355 | class LegacySaturationDetector { |
| 356 | public: |
| 357 | explicit LegacySaturationDetector(const EchoCanceller3Config& config); |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 358 | |
| 359 | // Returns whether the echo is to be considered saturated. |
| 360 | bool SaturatedEcho() const { return saturated_echo_; }; |
| 361 | |
| 362 | // Resets the state of the detector. |
| 363 | void Reset(); |
| 364 | |
| 365 | // Updates the detection decision based on new data. |
| 366 | void Update(rtc::ArrayView<const float> x, |
| 367 | bool saturated_capture, |
| 368 | float echo_path_gain); |
| 369 | |
| 370 | private: |
| 371 | const bool echo_can_saturate_; |
| 372 | size_t not_saturated_sequence_size_; |
| 373 | bool saturated_echo_ = false; |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 374 | } legacy_saturation_detector_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 375 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 376 | ErlEstimator erl_estimator_; |
| 377 | ErleEstimator erle_estimator_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 378 | size_t strong_not_saturated_render_blocks_ = 0; |
Per Åhgren | 4b3bc0f | 2017-12-20 15:26:13 +0100 | [diff] [blame] | 379 | size_t blocks_with_active_render_ = 0; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 380 | bool capture_signal_saturation_ = false; |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 381 | |
Per Åhgren | 12eb858 | 2018-03-06 10:40:51 +0100 | [diff] [blame] | 382 | SuppressionGainUpperLimiter suppression_gain_limiter_; |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 383 | FilterAnalyzer filter_analyzer_; |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 384 | absl::optional<DelayEstimate> external_delay_; |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 385 | EchoAudibility echo_audibility_; |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 386 | ReverbModelEstimator reverb_model_estimator_; |
Jesús de Vicente Peña | c98849c | 2018-10-22 11:41:05 +0200 | [diff] [blame] | 387 | RenderReverbModel render_reverb_; |
Per Åhgren | b20b937 | 2018-07-13 00:22:54 +0200 | [diff] [blame] | 388 | SubtractorOutputAnalyzer subtractor_output_analyzer_; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | } // namespace webrtc |
| 392 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 393 | #endif // MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ |