blob: 8036c2198b4e32bf4e8da1202685b9f5a50d4b2f [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_
peah522d71b2017-02-23 05:16:26 -080013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
peah522d71b2017-02-23 05:16:26 -080015#include <array>
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020016#include <memory>
peah522d71b2017-02-23 05:16:26 -080017
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020018#include "absl/types/optional.h"
Per Åhgren8ba58612017-12-01 23:01:44 +010019#include "api/array_view.h"
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010020#include "api/audio/echo_canceller3_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/audio_processing/aec3/aec3_common.h"
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020022#include "modules/audio_processing/aec3/fullband_erle_estimator.h"
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010023#include "modules/audio_processing/aec3/render_buffer.h"
24#include "modules/audio_processing/aec3/signal_dependent_erle_estimator.h"
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020025#include "modules/audio_processing/aec3/subband_erle_estimator.h"
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020026#include "modules/audio_processing/logging/apm_data_dumper.h"
peah522d71b2017-02-23 05:16:26 -080027
28namespace webrtc {
29
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020030// 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.
peah522d71b2017-02-23 05:16:26 -080032class ErleEstimator {
33 public:
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020034 ErleEstimator(size_t startup_phase_length_blocks_,
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010035 const EchoCanceller3Config& config);
peah522d71b2017-02-23 05:16:26 -080036 ~ErleEstimator();
37
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020038 // Resets the fullband ERLE estimator and the subbands ERLE estimators.
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020039 void Reset(bool delay_change);
Jesús de Vicente Peña7015bb42018-08-29 11:15:30 +020040
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020041 // Updates the ERLE estimates.
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010042 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 Åhgren8ba58612017-12-01 23:01:44 +010046 rtc::ArrayView<const float> capture_spectrum,
Jesús de Vicente Peña666beca2018-05-21 15:23:48 +020047 rtc::ArrayView<const float> subtractor_spectrum,
Jesús de Vicente Peñaa6878122018-08-28 14:27:45 +020048 bool converged_filter,
49 bool onset_detection);
peah522d71b2017-02-23 05:16:26 -080050
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020051 // Returns the most recent subband ERLE estimates.
52 const std::array<float, kFftLengthBy2Plus1>& Erle() const {
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010053 return use_signal_dependent_erle_ ? signal_dependent_erle_estimator_.Erle()
54 : subband_erle_estimator_.Erle();
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020055 }
56 // Returns the subband ERLE that are estimated during onsets. Used
57 // for logging/testing.
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010058 rtc::ArrayView<const float> ErleOnsets() const {
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020059 return subband_erle_estimator_.ErleOnsets();
Jesús de Vicente Peña7682c6e2018-03-22 14:53:23 +010060 }
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020061
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020062 // 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ña496cedf2018-07-04 11:02:09 +020071 absl::optional<float> GetInstLinearQualityEstimate() const {
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020072 return fullband_erle_estimator_.GetInstLinearQualityEstimate();
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020073 }
74
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020075 void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper) const;
peah522d71b2017-02-23 05:16:26 -080076
77 private:
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020078 const size_t startup_phase_length_blocks__;
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010079 const bool use_signal_dependent_erle_;
Jesús de Vicente Peñae9a7e902018-09-27 11:49:39 +020080 FullBandErleEstimator fullband_erle_estimator_;
81 SubbandErleEstimator subband_erle_estimator_;
Jesús de Vicente Peña44974e12018-11-20 12:54:23 +010082 SignalDependentErleEstimator signal_dependent_erle_estimator_;
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020083 size_t blocks_since_reset_ = 0;
peah522d71b2017-02-23 05:16:26 -080084};
85
86} // namespace webrtc
87
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#endif // MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_