2017-02-23 05:16:26 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
2018-07-04 11:02:09 +02:00
|
|
|
#include "absl/types/optional.h"
|
2017-12-01 23:01:44 +01:00
|
|
|
#include "api/array_view.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
2018-07-04 11:02:09 +02:00
|
|
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/constructormagic.h"
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Estimates the echo return loss enhancement based on the signal spectra.
|
|
|
|
|
class ErleEstimator {
|
|
|
|
|
public:
|
2017-08-24 22:36:53 -07:00
|
|
|
ErleEstimator(float min_erle, float max_erle_lf, float max_erle_hf);
|
2017-02-23 05:16:26 -08:00
|
|
|
~ErleEstimator();
|
|
|
|
|
|
2018-08-29 11:15:30 +02:00
|
|
|
// Reset the ERLE estimator.
|
|
|
|
|
void Reset();
|
|
|
|
|
|
2017-02-23 05:16:26 -08:00
|
|
|
// Updates the ERLE estimate.
|
2017-12-01 23:01:44 +01:00
|
|
|
void Update(rtc::ArrayView<const float> render_spectrum,
|
|
|
|
|
rtc::ArrayView<const float> capture_spectrum,
|
2018-05-21 15:23:48 +02:00
|
|
|
rtc::ArrayView<const float> subtractor_spectrum,
|
2018-08-28 14:27:45 +02:00
|
|
|
bool converged_filter,
|
|
|
|
|
bool onset_detection);
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
// Returns the most recent ERLE estimate.
|
|
|
|
|
const std::array<float, kFftLengthBy2Plus1>& Erle() const { return erle_; }
|
Improves in the ERLE estimation for AEC3
The estimation on how well the linear filter in the AEC3 is performing
is done through an estimation of the ERLE. That estimation is then
used for knowing how much the suppressor needs to react in order to
cancel all the echoes.
In the current code, the ERLE is quite conservative during farend
inactivity and it is common that it goes to a minimum value during
those periods. Under highly varying conditions, that is probably the
right approach. However, in other scenarios where conditions does not
change that fast there is a loss in transparency that could be avoided
by means of a different ERLE estimation.
In the current CL, the ERLE estimation has been changed in the
following way:
- During farend activity the ERLE is estimated through a 1st order AR
smoother. This smoother goes faster toward lower ERLE values than to
larger ones in order to avoid overestimation of this
value. Furthermore, during the beginning of the farend burst, an
estimation of the ERLE is done that aim to represent the performance
of the linear filter during onsets. Under highly variant environments,
those quantities, the ERLE during onsets and the one computed during
the whole farend duration, would differ a lot. If the environment is
more stationary, those quantities would be much more similar.
- During nearend activity the ERLE estimation is decreased toward a
value of the ERLE during onsets.
Bug: webrtc:9040
Change-Id: Ieab86370a4333d2d0cd7041047d29651de4f6827
Reviewed-on: https://webrtc-review.googlesource.com/62342
Commit-Queue: Jesus de Vicente Pena <devicentepena@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22568}
2018-03-22 14:53:23 +01:00
|
|
|
// Returns the ERLE that is estimated during onsets. Use for logging/testing.
|
|
|
|
|
const std::array<float, kFftLengthBy2Plus1>& ErleOnsets() const {
|
|
|
|
|
return erle_onsets_;
|
|
|
|
|
}
|
2018-07-04 11:02:09 +02:00
|
|
|
float ErleTimeDomainLog2() const { return erle_time_domain_log2_; }
|
|
|
|
|
|
|
|
|
|
absl::optional<float> GetInstLinearQualityEstimate() const {
|
|
|
|
|
return erle_time_inst_.GetInstQualityEstimate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper);
|
|
|
|
|
|
|
|
|
|
class ErleTimeInstantaneous {
|
|
|
|
|
public:
|
|
|
|
|
ErleTimeInstantaneous(int points_to_accumulate);
|
|
|
|
|
~ErleTimeInstantaneous();
|
|
|
|
|
// Update the estimator with a new point, returns true
|
|
|
|
|
// if the instantaneous erle was updated due to having enough
|
|
|
|
|
// points for performing the estimate.
|
|
|
|
|
bool Update(const float Y2_sum, const float E2_sum);
|
|
|
|
|
// Reset all the members of the class.
|
|
|
|
|
void Reset();
|
|
|
|
|
// Reset the members realated with an instantaneous estimate.
|
|
|
|
|
void ResetAccumulators();
|
|
|
|
|
// Returns the instantaneous ERLE in log2 units.
|
|
|
|
|
absl::optional<float> GetInstErle_log2() const { return erle_log2_; }
|
|
|
|
|
// Get an indication between 0 and 1 of the performance of the linear filter
|
|
|
|
|
// for the current time instant.
|
|
|
|
|
absl::optional<float> GetInstQualityEstimate() const {
|
|
|
|
|
return erle_log2_ ? absl::optional<float>(inst_quality_estimate_)
|
|
|
|
|
: absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void UpdateMaxMin();
|
|
|
|
|
void UpdateQualityEstimate();
|
|
|
|
|
absl::optional<float> erle_log2_;
|
|
|
|
|
float inst_quality_estimate_;
|
|
|
|
|
float max_erle_log2_;
|
|
|
|
|
float min_erle_log2_;
|
|
|
|
|
float Y2_acum_;
|
|
|
|
|
float E2_acum_;
|
|
|
|
|
int num_points_;
|
|
|
|
|
const int points_to_accumulate_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ErleFreqInstantaneous {
|
|
|
|
|
public:
|
|
|
|
|
ErleFreqInstantaneous(int points_to_accumulate);
|
|
|
|
|
~ErleFreqInstantaneous();
|
|
|
|
|
// Updates the ERLE for a band with a new block. Returns absl::nullopt
|
|
|
|
|
// if not enough points were accuulated for doing the estimation.
|
|
|
|
|
absl::optional<float> Update(float Y2, float E2, size_t band);
|
|
|
|
|
// Reset all the member of the class.
|
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1> Y2_acum_;
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1> E2_acum_;
|
|
|
|
|
std::array<int, kFftLengthBy2Plus1> num_points_;
|
|
|
|
|
const int points_to_accumulate_;
|
|
|
|
|
};
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1> erle_;
|
Improves in the ERLE estimation for AEC3
The estimation on how well the linear filter in the AEC3 is performing
is done through an estimation of the ERLE. That estimation is then
used for knowing how much the suppressor needs to react in order to
cancel all the echoes.
In the current code, the ERLE is quite conservative during farend
inactivity and it is common that it goes to a minimum value during
those periods. Under highly varying conditions, that is probably the
right approach. However, in other scenarios where conditions does not
change that fast there is a loss in transparency that could be avoided
by means of a different ERLE estimation.
In the current CL, the ERLE estimation has been changed in the
following way:
- During farend activity the ERLE is estimated through a 1st order AR
smoother. This smoother goes faster toward lower ERLE values than to
larger ones in order to avoid overestimation of this
value. Furthermore, during the beginning of the farend burst, an
estimation of the ERLE is done that aim to represent the performance
of the linear filter during onsets. Under highly variant environments,
those quantities, the ERLE during onsets and the one computed during
the whole farend duration, would differ a lot. If the environment is
more stationary, those quantities would be much more similar.
- During nearend activity the ERLE estimation is decreased toward a
value of the ERLE during onsets.
Bug: webrtc:9040
Change-Id: Ieab86370a4333d2d0cd7041047d29651de4f6827
Reviewed-on: https://webrtc-review.googlesource.com/62342
Commit-Queue: Jesus de Vicente Pena <devicentepena@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22568}
2018-03-22 14:53:23 +01:00
|
|
|
std::array<float, kFftLengthBy2Plus1> erle_onsets_;
|
2018-05-21 15:23:48 +02:00
|
|
|
std::array<bool, kFftLengthBy2Plus1> coming_onset_;
|
|
|
|
|
std::array<int, kFftLengthBy2Plus1> hold_counters_;
|
2017-11-16 11:20:59 +01:00
|
|
|
int hold_counter_time_domain_;
|
2018-07-04 11:02:09 +02:00
|
|
|
float erle_time_domain_log2_;
|
2017-08-24 22:36:53 -07:00
|
|
|
const float min_erle_;
|
2018-07-04 11:02:09 +02:00
|
|
|
const float min_erle_log2_;
|
2017-08-24 22:36:53 -07:00
|
|
|
const float max_erle_lf_;
|
2018-07-04 11:02:09 +02:00
|
|
|
const float max_erle_lf_log2;
|
2017-08-24 22:36:53 -07:00
|
|
|
const float max_erle_hf_;
|
2018-07-04 11:02:09 +02:00
|
|
|
ErleFreqInstantaneous erle_freq_inst_;
|
|
|
|
|
ErleTimeInstantaneous erle_time_inst_;
|
2017-02-23 05:16:26 -08:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(ErleEstimator);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_
|