| 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 22 matching lines...) Expand all Loading... |
| 33 public: | 33 public: |
| 34 AecState(); | 34 AecState(); |
| 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 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. | 43 // Returns whether the render signal is currently active. |
| 48 bool ActiveRender() const { return active_render_counter_ > 0; } | 44 bool ActiveRender() const { return active_render_blocks_ > 200; } |
| 49 | |
| 50 // Returns whether the number of active render blocks since an echo path | |
| 51 // change. | |
| 52 size_t ActiveRenderBlocks() const { return active_render_blocks_; } | |
| 53 | 45 |
| 54 // Returns the ERLE. | 46 // Returns the ERLE. |
| 55 const std::array<float, kFftLengthBy2Plus1>& Erle() const { | 47 const std::array<float, kFftLengthBy2Plus1>& Erle() const { |
| 56 return erle_estimator_.Erle(); | 48 return erle_estimator_.Erle(); |
| 57 } | 49 } |
| 58 | 50 |
| 59 // Returns the ERL. | 51 // Returns the ERL. |
| 60 const std::array<float, kFftLengthBy2Plus1>& Erl() const { | 52 const std::array<float, kFftLengthBy2Plus1>& Erl() const { |
| 61 return erl_estimator_.Erl(); | 53 return erl_estimator_.Erl(); |
| 62 } | 54 } |
| 63 | 55 |
| 64 // Returns the delay estimate based on the linear filter. | 56 // Returns the delay estimate based on the linear filter. |
| 65 rtc::Optional<size_t> FilterDelay() const { return filter_delay_; } | 57 rtc::Optional<size_t> FilterDelay() const { return filter_delay_; } |
| 66 | 58 |
| 67 // Returns the externally provided delay. | 59 // Returns the externally provided delay. |
| 68 rtc::Optional<size_t> ExternalDelay() const { return external_delay_; } | 60 rtc::Optional<size_t> ExternalDelay() const { return external_delay_; } |
| 69 | 61 |
| 70 // Returns the bands where the linear filter is reliable. | |
| 71 const std::array<bool, kFftLengthBy2Plus1>& BandsWithReliableFilter() const { | |
| 72 return bands_with_reliable_filter_; | |
| 73 } | |
| 74 | |
| 75 // Reports whether the filter is poorly aligned. | |
| 76 bool PoorlyAlignedFilter() const { | |
| 77 return FilterDelay() ? *FilterDelay() > 0.75f * filter_length_ : false; | |
| 78 } | |
| 79 | |
| 80 // Returns the strength of the filter. | |
| 81 const std::array<float, kFftLengthBy2Plus1>& FilterEstimateStrength() const { | |
| 82 return filter_estimate_strength_; | |
| 83 } | |
| 84 | |
| 85 // Returns whether the capture signal is saturated. | 62 // Returns whether the capture signal is saturated. |
| 86 bool SaturatedCapture() const { return capture_signal_saturation_; } | 63 bool SaturatedCapture() const { return capture_signal_saturation_; } |
| 87 | 64 |
| 65 // Returns whether the echo signal is saturated. |
| 66 bool SaturatedEcho() const { return echo_saturation_; } |
| 67 |
| 88 // Updates the capture signal saturation. | 68 // Updates the capture signal saturation. |
| 89 void UpdateCaptureSaturation(bool capture_signal_saturation) { | 69 void UpdateCaptureSaturation(bool capture_signal_saturation) { |
| 90 capture_signal_saturation_ = capture_signal_saturation; | 70 capture_signal_saturation_ = capture_signal_saturation; |
| 91 } | 71 } |
| 92 | 72 |
| 93 // Returns whether a probable headset setup has been detected. | 73 // Returns whether a probable headset setup has been detected. |
| 94 bool HeadsetDetected() const { return headset_detected_; } | 74 bool HeadsetDetected() const { return headset_detected_; } |
| 95 | 75 |
| 76 // Takes appropriate action at an echo path change. |
| 77 void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); |
| 78 |
| 96 // Updates the aec state. | 79 // Updates the aec state. |
| 97 void Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& | 80 void Update(const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
| 98 filter_frequency_response, | 81 adaptive_filter_frequency_response, |
| 99 const rtc::Optional<size_t>& external_delay_samples, | 82 const rtc::Optional<size_t>& external_delay_samples, |
| 100 const RenderBuffer& X_buffer, | 83 const RenderBuffer& render_buffer, |
| 101 const std::array<float, kFftLengthBy2Plus1>& E2_main, | 84 const std::array<float, kFftLengthBy2Plus1>& E2_main, |
| 102 const std::array<float, kFftLengthBy2Plus1>& E2_shadow, | |
| 103 const std::array<float, kFftLengthBy2Plus1>& Y2, | 85 const std::array<float, kFftLengthBy2Plus1>& Y2, |
| 104 rtc::ArrayView<const float> x, | 86 rtc::ArrayView<const float> x, |
| 105 const EchoPathVariability& echo_path_variability, | |
| 106 bool echo_leakage_detected); | 87 bool echo_leakage_detected); |
| 107 | 88 |
| 108 private: | 89 private: |
| 109 static int instance_count_; | 90 static int instance_count_; |
| 110 std::unique_ptr<ApmDataDumper> data_dumper_; | 91 std::unique_ptr<ApmDataDumper> data_dumper_; |
| 111 ErlEstimator erl_estimator_; | 92 ErlEstimator erl_estimator_; |
| 112 ErleEstimator erle_estimator_; | 93 ErleEstimator erle_estimator_; |
| 113 int echo_path_change_counter_; | 94 int echo_path_change_counter_; |
| 114 int active_render_counter_; | |
| 115 size_t active_render_blocks_ = 0; | 95 size_t active_render_blocks_ = 0; |
| 116 bool usable_linear_estimate_ = false; | 96 bool usable_linear_estimate_ = false; |
| 117 bool echo_leakage_detected_ = false; | 97 bool echo_leakage_detected_ = false; |
| 118 bool model_based_aec_feasible_ = false; | |
| 119 bool capture_signal_saturation_ = false; | 98 bool capture_signal_saturation_ = false; |
| 99 bool echo_saturation_ = false; |
| 120 bool headset_detected_ = false; | 100 bool headset_detected_ = false; |
| 101 float previous_max_sample_ = 0.f; |
| 121 rtc::Optional<size_t> filter_delay_; | 102 rtc::Optional<size_t> filter_delay_; |
| 122 rtc::Optional<size_t> external_delay_; | 103 rtc::Optional<size_t> external_delay_; |
| 123 std::array<bool, kFftLengthBy2Plus1> bands_with_reliable_filter_; | 104 size_t blocks_since_last_saturation_ = 1000; |
| 124 std::array<float, kFftLengthBy2Plus1> filter_estimate_strength_; | |
| 125 size_t filter_length_; | |
| 126 | 105 |
| 127 RTC_DISALLOW_COPY_AND_ASSIGN(AecState); | 106 RTC_DISALLOW_COPY_AND_ASSIGN(AecState); |
| 128 }; | 107 }; |
| 129 | 108 |
| 130 } // namespace webrtc | 109 } // namespace webrtc |
| 131 | 110 |
| 132 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ | 111 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC_STATE_H_ |
| OLD | NEW |