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_RESIDUAL_ECHO_ESTIMATOR_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
#include <array>
|
2018-06-13 15:13:55 +02:00
|
|
|
#include <memory>
|
2017-02-23 05:16:26 -08:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "absl/types/optional.h"
|
2018-02-14 15:19:04 +01:00
|
|
|
#include "api/audio/echo_canceller3_config.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
|
|
|
|
#include "modules/audio_processing/aec3/aec_state.h"
|
|
|
|
|
#include "modules/audio_processing/aec3/render_buffer.h"
|
2018-06-13 15:13:55 +02:00
|
|
|
#include "modules/audio_processing/aec3/reverb_model.h"
|
|
|
|
|
#include "modules/audio_processing/aec3/reverb_model_fallback.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/audio_processing/aec3/vector_buffer.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class ResidualEchoEstimator {
|
|
|
|
|
public:
|
2017-10-18 12:32:42 +02:00
|
|
|
explicit ResidualEchoEstimator(const EchoCanceller3Config& config);
|
2017-02-23 05:16:26 -08:00
|
|
|
~ResidualEchoEstimator();
|
|
|
|
|
|
2017-10-09 13:01:39 +02:00
|
|
|
void Estimate(const AecState& aec_state,
|
2017-04-06 15:45:32 -07:00
|
|
|
const RenderBuffer& render_buffer,
|
2017-02-23 05:16:26 -08:00
|
|
|
const std::array<float, kFftLengthBy2Plus1>& S2_linear,
|
|
|
|
|
const std::array<float, kFftLengthBy2Plus1>& Y2,
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1>* R2);
|
|
|
|
|
|
2018-06-13 15:13:55 +02:00
|
|
|
// Returns the reverberant power spectrum contributions to the echo residual.
|
2018-10-22 11:41:05 +02:00
|
|
|
rtc::ArrayView<const float> GetReverbPowerSpectrum() const {
|
2018-06-13 15:13:55 +02:00
|
|
|
if (echo_reverb_) {
|
|
|
|
|
return echo_reverb_->GetPowerSpectrum();
|
|
|
|
|
} else {
|
|
|
|
|
RTC_DCHECK(echo_reverb_fallback);
|
|
|
|
|
return echo_reverb_fallback->GetPowerSpectrum();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 05:16:26 -08:00
|
|
|
private:
|
2017-04-07 06:13:39 -07:00
|
|
|
// Resets the state.
|
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
|
|
// Estimates the residual echo power based on the echo return loss enhancement
|
|
|
|
|
// (ERLE) and the linear power estimate.
|
|
|
|
|
void LinearEstimate(const std::array<float, kFftLengthBy2Plus1>& S2_linear,
|
|
|
|
|
const std::array<float, kFftLengthBy2Plus1>& erle,
|
2018-06-28 14:21:16 +02:00
|
|
|
absl::optional<float> erle_uncertainty,
|
2017-04-07 06:13:39 -07:00
|
|
|
std::array<float, kFftLengthBy2Plus1>* R2);
|
|
|
|
|
|
|
|
|
|
// Estimates the residual echo power based on the estimate of the echo path
|
|
|
|
|
// gain.
|
2018-04-10 16:33:55 +02:00
|
|
|
void NonLinearEstimate(float echo_path_gain,
|
2017-04-19 09:03:40 -07:00
|
|
|
const std::array<float, kFftLengthBy2Plus1>& X2,
|
2017-04-07 06:13:39 -07:00
|
|
|
std::array<float, kFftLengthBy2Plus1>* R2);
|
|
|
|
|
|
2018-03-28 16:31:57 +02:00
|
|
|
// Estimates the echo generating signal power as gated maximal power over a
|
|
|
|
|
// time window.
|
2018-05-25 16:55:11 +02:00
|
|
|
void EchoGeneratingPower(const VectorBuffer& spectrum_buffer,
|
|
|
|
|
const EchoCanceller3Config::EchoModel& echo_model,
|
|
|
|
|
int filter_delay_blocks,
|
2018-05-02 14:28:30 +02:00
|
|
|
bool apply_noise_gating,
|
2018-03-28 16:31:57 +02:00
|
|
|
std::array<float, kFftLengthBy2Plus1>* X2) const;
|
|
|
|
|
|
|
|
|
|
// Updates estimate for the power of the stationary noise component in the
|
|
|
|
|
// render signal.
|
|
|
|
|
void RenderNoisePower(
|
|
|
|
|
const RenderBuffer& render_buffer,
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1>* X2_noise_floor,
|
|
|
|
|
std::array<int, kFftLengthBy2Plus1>* X2_noise_floor_counter) const;
|
|
|
|
|
|
2017-12-11 22:28:45 +01:00
|
|
|
const EchoCanceller3Config config_;
|
2017-04-19 09:03:40 -07:00
|
|
|
std::array<float, kFftLengthBy2Plus1> X2_noise_floor_;
|
|
|
|
|
std::array<int, kFftLengthBy2Plus1> X2_noise_floor_counter_;
|
2018-06-13 15:13:55 +02:00
|
|
|
std::unique_ptr<ReverbModel> echo_reverb_;
|
|
|
|
|
std::unique_ptr<ReverbModelFallback> echo_reverb_fallback;
|
2017-08-24 22:36:53 -07:00
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ResidualEchoEstimator);
|
2017-02-23 05:16:26 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_
|