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_ERLE_ESTIMATOR_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_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> |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 15 | #include <array> |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 16 | #include <memory> |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 17 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 18 | #include "absl/types/optional.h" |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 19 | #include "api/array_view.h" |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 20 | #include "api/audio/echo_canceller3_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/aec3/aec3_common.h" |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 22 | #include "modules/audio_processing/aec3/fullband_erle_estimator.h" |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 23 | #include "modules/audio_processing/aec3/render_buffer.h" |
| 24 | #include "modules/audio_processing/aec3/signal_dependent_erle_estimator.h" |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 25 | #include "modules/audio_processing/aec3/subband_erle_estimator.h" |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 26 | #include "modules/audio_processing/logging/apm_data_dumper.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 30 | // Estimates the echo return loss enhancement. One estimate is done per subband |
| 31 | // and another one is done using the aggreation of energy over all the subbands. |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 32 | class ErleEstimator { |
| 33 | public: |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 34 | ErleEstimator(size_t startup_phase_length_blocks_, |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 35 | const EchoCanceller3Config& config); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 36 | ~ErleEstimator(); |
| 37 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 38 | // Resets the fullband ERLE estimator and the subbands ERLE estimators. |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 39 | void Reset(bool delay_change); |
Jesús de Vicente Peña | 7015bb4 | 2018-08-29 11:15:30 +0200 | [diff] [blame] | 40 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 41 | // Updates the ERLE estimates. |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 42 | void Update(const RenderBuffer& render_buffer, |
| 43 | const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
| 44 | filter_frequency_response, |
| 45 | rtc::ArrayView<const float> reverb_render_spectrum, |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 46 | rtc::ArrayView<const float> capture_spectrum, |
Jesús de Vicente Peña | 666beca | 2018-05-21 15:23:48 +0200 | [diff] [blame] | 47 | rtc::ArrayView<const float> subtractor_spectrum, |
Jesús de Vicente Peña | a687812 | 2018-08-28 14:27:45 +0200 | [diff] [blame] | 48 | bool converged_filter, |
| 49 | bool onset_detection); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 50 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 51 | // Returns the most recent subband ERLE estimates. |
| 52 | const std::array<float, kFftLengthBy2Plus1>& Erle() const { |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 53 | return use_signal_dependent_erle_ ? signal_dependent_erle_estimator_.Erle() |
| 54 | : subband_erle_estimator_.Erle(); |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 55 | } |
| 56 | // Returns the subband ERLE that are estimated during onsets. Used |
| 57 | // for logging/testing. |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 58 | rtc::ArrayView<const float> ErleOnsets() const { |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 59 | return subband_erle_estimator_.ErleOnsets(); |
Jesús de Vicente Peña | 7682c6e | 2018-03-22 14:53:23 +0100 | [diff] [blame] | 60 | } |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 61 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 62 | // Returns the fullband ERLE estimate. |
| 63 | float FullbandErleLog2() const { |
| 64 | return fullband_erle_estimator_.FullbandErleLog2(); |
| 65 | } |
| 66 | |
| 67 | // Returns an estimation of the current linear filter quality based on the |
| 68 | // current and past fullband ERLE estimates. The returned value is a float |
| 69 | // between 0 and 1 where 1 indicates that, at this current time instant, the |
| 70 | // linear filter is reaching its maximum subtraction performance. |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 71 | absl::optional<float> GetInstLinearQualityEstimate() const { |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 72 | return fullband_erle_estimator_.GetInstLinearQualityEstimate(); |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 75 | void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper) const; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 76 | |
| 77 | private: |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 78 | const size_t startup_phase_length_blocks__; |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 79 | const bool use_signal_dependent_erle_; |
Jesús de Vicente Peña | e9a7e90 | 2018-09-27 11:49:39 +0200 | [diff] [blame] | 80 | FullBandErleEstimator fullband_erle_estimator_; |
| 81 | SubbandErleEstimator subband_erle_estimator_; |
Jesús de Vicente Peña | 44974e1 | 2018-11-20 12:54:23 +0100 | [diff] [blame] | 82 | SignalDependentErleEstimator signal_dependent_erle_estimator_; |
Per Åhgren | c5a38ad | 2018-10-04 15:37:54 +0200 | [diff] [blame] | 83 | size_t blocks_since_reset_ = 0; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace webrtc |
| 87 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 88 | #endif // MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_ |