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> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <array> |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 17 | #include <memory> |
| 18 | #include <vector> |
| 19 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/array_view.h" |
Gustaf Ullberg | 3646f97 | 2018-02-14 15:19:04 +0100 | [diff] [blame] | 22 | #include "api/audio/echo_canceller3_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "modules/audio_processing/aec3/aec3_common.h" |
Per Åhgren | 3ab308f | 2018-02-21 08:46:03 +0100 | [diff] [blame] | 24 | #include "modules/audio_processing/aec3/delay_estimate.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 25 | #include "modules/audio_processing/aec3/echo_audibility.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "modules/audio_processing/aec3/echo_path_variability.h" |
| 27 | #include "modules/audio_processing/aec3/erl_estimator.h" |
| 28 | #include "modules/audio_processing/aec3/erle_estimator.h" |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 29 | #include "modules/audio_processing/aec3/filter_analyzer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "modules/audio_processing/aec3/render_buffer.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" |
Gustaf Ullberg | afef7a7 | 2020-09-24 09:21:49 +0200 | [diff] [blame^] | 34 | #include "modules/audio_processing/aec3/transparent_mode.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: |
Sam Zackrisson | 8f736c0 | 2019-10-01 12:47:53 +0200 | [diff] [blame] | 43 | AecState(const EchoCanceller3Config& config, size_t num_capture_channels); |
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 { |
Gustaf Ullberg | 52caa0e | 2019-04-11 14:43:17 +0200 | [diff] [blame] | 49 | return filter_quality_state_.LinearFilterUsable() && |
| 50 | config_.filter.use_linear_filter; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 51 | } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 52 | |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 53 | // Returns whether the echo subtractor output should be used as output. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 54 | bool UseLinearFilterOutput() const { |
Gustaf Ullberg | 52caa0e | 2019-04-11 14:43:17 +0200 | [diff] [blame] | 55 | return filter_quality_state_.LinearFilterUsable() && |
| 56 | config_.filter.use_linear_filter; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 57 | } |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 58 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 59 | // Returns whether the render signal is currently active. |
Per Åhgren | 4b3bc0f | 2017-12-20 15:26:13 +0100 | [diff] [blame] | 60 | bool ActiveRender() const { return blocks_with_active_render_ > 200; } |
peah | ebe7778 | 2017-02-27 07:29:21 -0800 | [diff] [blame] | 61 | |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 62 | // Returns the appropriate scaling of the residual echo to match the |
| 63 | // audibility. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 64 | void GetResidualEchoScaling(rtc::ArrayView<float> residual_scaling) const; |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 65 | |
| 66 | // Returns whether the stationary properties of the signals are used in the |
| 67 | // aec. |
Per Åhgren | b4161d3 | 2019-10-08 12:35:47 +0200 | [diff] [blame] | 68 | bool UseStationarityProperties() const { |
Jesús de Vicente Peña | 70a5963 | 2019-04-16 12:32:15 +0200 | [diff] [blame] | 69 | return config_.echo_audibility.use_stationarity_properties; |
Per Åhgren | f4801a1 | 2018-09-27 13:14:02 +0200 | [diff] [blame] | 70 | } |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 71 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 72 | // Returns the ERLE. |
Per Åhgren | b4161d3 | 2019-10-08 12:35:47 +0200 | [diff] [blame] | 73 | rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Erle() const { |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 74 | return erle_estimator_.Erle(); |
| 75 | } |
| 76 | |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 77 | // Returns an offset to apply to the estimation of the residual echo |
| 78 | // computation. Returning nullopt means that no offset should be used, while |
| 79 | // any other value will be applied as a multiplier to the estimated residual |
| 80 | // echo. |
| 81 | absl::optional<float> ErleUncertainty() const; |
Gustaf Ullberg | 6c618c7 | 2018-06-28 14:21:16 +0200 | [diff] [blame] | 82 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 83 | // Returns the fullband ERLE estimate in log2 units. |
| 84 | float FullBandErleLog2() const { return erle_estimator_.FullbandErleLog2(); } |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 85 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 86 | // Returns the ERL. |
| 87 | const std::array<float, kFftLengthBy2Plus1>& Erl() const { |
| 88 | return erl_estimator_.Erl(); |
| 89 | } |
| 90 | |
Gustaf Ullberg | 332150d | 2017-11-22 14:17:39 +0100 | [diff] [blame] | 91 | // Returns the time-domain ERL. |
| 92 | float ErlTimeDomain() const { return erl_estimator_.ErlTimeDomain(); } |
| 93 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 94 | // Returns the delay estimate based on the linear filter. |
Per Åhgren | 8718afb | 2019-10-15 10:31:35 +0200 | [diff] [blame] | 95 | int MinDirectPathFilterDelay() const { |
| 96 | return delay_state_.MinDirectPathFilterDelay(); |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 97 | } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 98 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 99 | // Returns whether the capture signal is saturated. |
| 100 | bool SaturatedCapture() const { return capture_signal_saturation_; } |
| 101 | |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 102 | // Returns whether the echo signal is saturated. |
Gustaf Ullberg | 68d6d44 | 2019-01-29 10:08:15 +0100 | [diff] [blame] | 103 | bool SaturatedEcho() const { return saturation_detector_.SaturatedEcho(); } |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 104 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 105 | // Updates the capture signal saturation. |
| 106 | void UpdateCaptureSaturation(bool capture_signal_saturation) { |
| 107 | capture_signal_saturation_ = capture_signal_saturation; |
| 108 | } |
| 109 | |
Per Åhgren | 1b4059e | 2017-10-15 20:19:21 +0200 | [diff] [blame] | 110 | // Returns whether the transparent mode is active |
Gustaf Ullberg | afef7a7 | 2020-09-24 09:21:49 +0200 | [diff] [blame^] | 111 | bool TransparentModeActive() const { |
| 112 | return transparent_state_ && transparent_state_->Active(); |
Per Åhgren | d8d09c3 | 2020-04-01 17:30:18 +0200 | [diff] [blame] | 113 | } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 114 | |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 115 | // Takes appropriate action at an echo path change. |
| 116 | void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); |
| 117 | |
peah | 8942045 | 2017-04-07 06:13:39 -0700 | [diff] [blame] | 118 | // Returns the decay factor for the echo reverberation. |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 119 | float ReverbDecay() const { return reverb_model_estimator_.ReverbDecay(); } |
peah | 8942045 | 2017-04-07 06:13:39 -0700 | [diff] [blame] | 120 | |
Per Åhgren | ef5d5af | 2018-07-31 00:03:46 +0200 | [diff] [blame] | 121 | // Return the frequency response of the reverberant echo. |
| 122 | rtc::ArrayView<const float> GetReverbFrequencyResponse() const { |
| 123 | return reverb_model_estimator_.GetReverbFrequencyResponse(); |
| 124 | } |
| 125 | |
Jesús de Vicente Peña | 02e9e44 | 2018-08-29 13:34:07 +0200 | [diff] [blame] | 126 | // Returns whether the transition for going out of the initial stated has |
| 127 | // been triggered. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 128 | bool TransitionTriggered() const { |
| 129 | return initial_state_.TransitionTriggered(); |
| 130 | } |
Per Åhgren | a98c807 | 2018-01-15 19:17:16 +0100 | [diff] [blame] | 131 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 132 | // Updates the aec state. |
Per Åhgren | 119e219 | 2019-10-18 08:50:50 +0200 | [diff] [blame] | 133 | // TODO(bugs.webrtc.org/10913): Compute multi-channel ERL. |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 134 | void Update( |
| 135 | const absl::optional<DelayEstimate>& external_delay, |
| 136 | rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>> |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 137 | adaptive_filter_frequency_responses, |
| 138 | rtc::ArrayView<const std::vector<float>> |
| 139 | adaptive_filter_impulse_responses, |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 140 | const RenderBuffer& render_buffer, |
Per Åhgren | ff04511 | 2020-03-20 11:20:39 +0100 | [diff] [blame] | 141 | rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> E2_refined, |
Per Åhgren | f980725 | 2019-10-09 13:57:07 +0200 | [diff] [blame] | 142 | rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2, |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 143 | rtc::ArrayView<const SubtractorOutput> subtractor_output); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 144 | |
Jesús de Vicente Peña | 075cb2b | 2018-06-13 15:13:55 +0200 | [diff] [blame] | 145 | // Returns filter length in blocks. |
| 146 | int FilterLengthBlocks() const { |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 147 | // All filters have the same length, so arbitrarily return channel 0 length. |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 148 | return filter_analyzer_.FilterLengthBlocks(); |
Jesús de Vicente Peña | 075cb2b | 2018-06-13 15:13:55 +0200 | [diff] [blame] | 149 | } |
| 150 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 151 | private: |
| 152 | static int instance_count_; |
| 153 | std::unique_ptr<ApmDataDumper> data_dumper_; |
Per Åhgren | 90e3fbd | 2018-05-16 15:25:04 +0200 | [diff] [blame] | 154 | const EchoCanceller3Config config_; |
Per Åhgren | 785d4c4 | 2019-10-17 14:40:54 +0200 | [diff] [blame] | 155 | const size_t num_capture_channels_; |
Per Åhgren | d8d09c3 | 2020-04-01 17:30:18 +0200 | [diff] [blame] | 156 | const bool deactivate_initial_state_reset_at_echo_path_change_; |
| 157 | const bool full_reset_at_echo_path_change_; |
| 158 | const bool subtractor_analyzer_reset_at_echo_path_change_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 159 | |
| 160 | // Class for controlling the transition from the intial state, which in turn |
| 161 | // controls when the filter parameters for the initial state should be used. |
| 162 | class InitialState { |
| 163 | public: |
| 164 | explicit InitialState(const EchoCanceller3Config& config); |
| 165 | // Resets the state to again begin in the initial state. |
| 166 | void Reset(); |
| 167 | |
| 168 | // Updates the state based on new data. |
| 169 | void Update(bool active_render, bool saturated_capture); |
| 170 | |
| 171 | // Returns whether the initial state is active or not. |
| 172 | bool InitialStateActive() const { return initial_state_; } |
| 173 | |
| 174 | // Returns that the transition from the initial state has was started. |
| 175 | bool TransitionTriggered() const { return transition_triggered_; } |
| 176 | |
| 177 | private: |
| 178 | const bool conservative_initial_phase_; |
| 179 | const float initial_state_seconds_; |
| 180 | bool transition_triggered_ = false; |
| 181 | bool initial_state_ = true; |
| 182 | size_t strong_not_saturated_render_blocks_ = 0; |
| 183 | } initial_state_; |
| 184 | |
| 185 | // Class for choosing the direct-path delay relative to the beginning of the |
| 186 | // filter, as well as any other data related to the delay used within |
| 187 | // AecState. |
| 188 | class FilterDelay { |
| 189 | public: |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 190 | FilterDelay(const EchoCanceller3Config& config, |
| 191 | size_t num_capture_channels); |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 192 | |
| 193 | // Returns whether an external delay has been reported to the AecState (from |
| 194 | // the delay estimator). |
| 195 | bool ExternalDelayReported() const { return external_delay_reported_; } |
| 196 | |
| 197 | // Returns the delay in blocks relative to the beginning of the filter that |
| 198 | // corresponds to the direct path of the echo. |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 199 | rtc::ArrayView<const int> DirectPathFilterDelays() const { |
| 200 | return filter_delays_blocks_; |
| 201 | } |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 202 | |
Per Åhgren | 8718afb | 2019-10-15 10:31:35 +0200 | [diff] [blame] | 203 | // Returns the minimum delay among the direct path delays relative to the |
| 204 | // beginning of the filter |
| 205 | int MinDirectPathFilterDelay() const { return min_filter_delay_; } |
| 206 | |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 207 | // Updates the delay estimates based on new data. |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 208 | void Update( |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 209 | rtc::ArrayView<const int> analyzer_filter_delay_estimates_blocks, |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 210 | const absl::optional<DelayEstimate>& external_delay, |
| 211 | size_t blocks_with_proper_filter_adaptation); |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 212 | |
| 213 | private: |
Gustaf Ullberg | 9249fbf | 2019-03-14 11:24:54 +0100 | [diff] [blame] | 214 | const int delay_headroom_samples_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 215 | bool external_delay_reported_ = false; |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 216 | std::vector<int> filter_delays_blocks_; |
Per Åhgren | 8718afb | 2019-10-15 10:31:35 +0200 | [diff] [blame] | 217 | int min_filter_delay_ = 0; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 218 | absl::optional<DelayEstimate> external_delay_; |
| 219 | } delay_state_; |
| 220 | |
Gustaf Ullberg | afef7a7 | 2020-09-24 09:21:49 +0200 | [diff] [blame^] | 221 | // Classifier for toggling transparent mode when there is no echo. |
| 222 | std::unique_ptr<TransparentMode> transparent_state_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 223 | |
| 224 | // Class for analyzing how well the linear filter is, and can be expected to, |
| 225 | // perform on the current signals. The purpose of this is for using to |
| 226 | // select the echo suppression functionality as well as the input to the echo |
| 227 | // suppressor. |
| 228 | class FilteringQualityAnalyzer { |
| 229 | public: |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 230 | FilteringQualityAnalyzer(const EchoCanceller3Config& config, |
| 231 | size_t num_capture_channels); |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 232 | |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 233 | // Returns whether the linear filter can be used for the echo |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 234 | // canceller output. |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 235 | bool LinearFilterUsable() const { return overall_usable_linear_estimates_; } |
| 236 | |
| 237 | // Returns whether an individual filter output can be used for the echo |
| 238 | // canceller output. |
| 239 | const std::vector<bool>& UsableLinearFilterOutputs() const { |
| 240 | return usable_linear_filter_estimates_; |
| 241 | } |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 242 | |
| 243 | // Resets the state of the analyzer. |
| 244 | void Reset(); |
| 245 | |
| 246 | // Updates the analysis based on new data. |
| 247 | void Update(bool active_render, |
| 248 | bool transparent_mode, |
| 249 | bool saturated_capture, |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 250 | const absl::optional<DelayEstimate>& external_delay, |
Sam Zackrisson | 46b0140 | 2019-10-08 16:17:48 +0200 | [diff] [blame] | 251 | bool any_filter_converged); |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 252 | |
| 253 | private: |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 254 | const bool use_linear_filter_; |
| 255 | bool overall_usable_linear_estimates_ = false; |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 256 | size_t filter_update_blocks_since_reset_ = 0; |
| 257 | size_t filter_update_blocks_since_start_ = 0; |
| 258 | bool convergence_seen_ = false; |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 259 | std::vector<bool> usable_linear_filter_estimates_; |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 260 | } filter_quality_state_; |
| 261 | |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 262 | // Class for detecting whether the echo is to be considered to be |
| 263 | // saturated. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 264 | class SaturationDetector { |
| 265 | public: |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 266 | // Returns whether the echo is to be considered saturated. |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 267 | bool SaturatedEcho() const { return saturated_echo_; } |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 268 | |
| 269 | // Updates the detection decision based on new data. |
Sam Zackrisson | 8f736c0 | 2019-10-01 12:47:53 +0200 | [diff] [blame] | 270 | void Update(rtc::ArrayView<const std::vector<float>> x, |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 271 | bool saturated_capture, |
| 272 | bool usable_linear_estimate, |
Sam Zackrisson | 8f736c0 | 2019-10-01 12:47:53 +0200 | [diff] [blame] | 273 | rtc::ArrayView<const SubtractorOutput> subtractor_output, |
Per Åhgren | 3e7b7b1 | 2018-10-16 14:38:10 +0200 | [diff] [blame] | 274 | float echo_path_gain); |
| 275 | |
| 276 | private: |
| 277 | bool saturated_echo_ = false; |
| 278 | } saturation_detector_; |
| 279 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 280 | ErlEstimator erl_estimator_; |
| 281 | ErleEstimator erle_estimator_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 282 | size_t strong_not_saturated_render_blocks_ = 0; |
Per Åhgren | 4b3bc0f | 2017-12-20 15:26:13 +0100 | [diff] [blame] | 283 | size_t blocks_with_active_render_ = 0; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 284 | bool capture_signal_saturation_ = false; |
Per Åhgren | 8be669f | 2019-10-11 23:02:26 +0200 | [diff] [blame] | 285 | FilterAnalyzer filter_analyzer_; |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 286 | absl::optional<DelayEstimate> external_delay_; |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 287 | EchoAudibility echo_audibility_; |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 288 | ReverbModelEstimator reverb_model_estimator_; |
Per Åhgren | 8718afb | 2019-10-15 10:31:35 +0200 | [diff] [blame] | 289 | ReverbModel avg_render_reverb_; |
Per Åhgren | 785d4c4 | 2019-10-17 14:40:54 +0200 | [diff] [blame] | 290 | SubtractorOutputAnalyzer subtractor_output_analyzer_; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | } // namespace webrtc |
| 294 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 295 | #endif // MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ |