blob: 89bf6ace36175535978ab800f1fa1f354bfd5662 [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_ERL_ESTIMATOR_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_ERL_ESTIMATOR_H_
peah522d71b2017-02-23 05:16:26 -080013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
peah522d71b2017-02-23 05:16:26 -080016#include <array>
Sam Zackrisson6e5433c2019-10-18 16:49:13 +020017#include <vector>
peah522d71b2017-02-23 05:16:26 -080018
Per Åhgren8ba58612017-12-01 23:01:44 +010019#include "api/array_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/aec3/aec3_common.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/constructor_magic.h"
peah522d71b2017-02-23 05:16:26 -080022
23namespace webrtc {
24
25// Estimates the echo return loss based on the signal spectra.
26class ErlEstimator {
27 public:
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020028 explicit ErlEstimator(size_t startup_phase_length_blocks_);
peah522d71b2017-02-23 05:16:26 -080029 ~ErlEstimator();
30
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020031 // Resets the ERL estimation.
32 void Reset();
33
peah522d71b2017-02-23 05:16:26 -080034 // Updates the ERL estimate.
Sam Zackrisson6e5433c2019-10-18 16:49:13 +020035 void Update(const std::vector<bool>& converged_filters,
36 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
37 render_spectra,
38 rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
39 capture_spectra);
peah522d71b2017-02-23 05:16:26 -080040
41 // Returns the most recent ERL estimate.
42 const std::array<float, kFftLengthBy2Plus1>& Erl() const { return erl_; }
Gustaf Ullbergfe4d6732017-11-16 09:31:27 +010043 float ErlTimeDomain() const { return erl_time_domain_; }
peah522d71b2017-02-23 05:16:26 -080044
45 private:
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020046 const size_t startup_phase_length_blocks__;
peah522d71b2017-02-23 05:16:26 -080047 std::array<float, kFftLengthBy2Plus1> erl_;
48 std::array<int, kFftLengthBy2Minus1> hold_counters_;
Gustaf Ullbergfe4d6732017-11-16 09:31:27 +010049 float erl_time_domain_;
50 int hold_counter_time_domain_;
Per Åhgrenc5a38ad2018-10-04 15:37:54 +020051 size_t blocks_since_reset_ = 0;
peah522d71b2017-02-23 05:16:26 -080052 RTC_DISALLOW_COPY_AND_ASSIGN(ErlEstimator);
53};
54
55} // namespace webrtc
56
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020057#endif // MODULES_AUDIO_PROCESSING_AEC3_ERL_ESTIMATOR_H_