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
|
|
|
#include "modules/audio_processing/aec3/erle_estimator.h"
|
2017-02-23 05:16:26 -08:00
|
|
|
|
2018-07-04 11:02:09 +02:00
|
|
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2017-06-12 11:40:47 -07:00
|
|
|
|
2017-02-23 05:16:26 -08:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2018-10-04 15:37:54 +02:00
|
|
|
ErleEstimator::ErleEstimator(size_t startup_phase_length_blocks_,
|
2018-11-20 12:54:23 +01:00
|
|
|
const EchoCanceller3Config& config)
|
2018-10-04 15:37:54 +02:00
|
|
|
: startup_phase_length_blocks__(startup_phase_length_blocks_),
|
2018-11-20 12:54:23 +01:00
|
|
|
use_signal_dependent_erle_(config.erle.num_sections > 1),
|
|
|
|
|
fullband_erle_estimator_(config.erle.min, config.erle.max_l),
|
|
|
|
|
subband_erle_estimator_(config),
|
|
|
|
|
signal_dependent_erle_estimator_(config) {
|
2018-10-04 15:37:54 +02:00
|
|
|
Reset(true);
|
2018-08-29 11:15:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErleEstimator::~ErleEstimator() = default;
|
|
|
|
|
|
2018-10-04 15:37:54 +02:00
|
|
|
void ErleEstimator::Reset(bool delay_change) {
|
2018-09-27 11:49:39 +02:00
|
|
|
fullband_erle_estimator_.Reset();
|
|
|
|
|
subband_erle_estimator_.Reset();
|
2018-11-20 12:54:23 +01:00
|
|
|
signal_dependent_erle_estimator_.Reset();
|
2018-10-04 15:37:54 +02:00
|
|
|
if (delay_change) {
|
|
|
|
|
blocks_since_reset_ = 0;
|
|
|
|
|
}
|
2018-07-04 11:02:09 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-20 12:54:23 +01:00
|
|
|
void ErleEstimator::Update(
|
|
|
|
|
const RenderBuffer& render_buffer,
|
|
|
|
|
const std::vector<std::array<float, kFftLengthBy2Plus1>>&
|
|
|
|
|
filter_frequency_response,
|
|
|
|
|
rtc::ArrayView<const float> reverb_render_spectrum,
|
|
|
|
|
rtc::ArrayView<const float> capture_spectrum,
|
|
|
|
|
rtc::ArrayView<const float> subtractor_spectrum,
|
|
|
|
|
bool converged_filter,
|
|
|
|
|
bool onset_detection) {
|
2018-10-22 11:41:05 +02:00
|
|
|
RTC_DCHECK_EQ(kFftLengthBy2Plus1, reverb_render_spectrum.size());
|
2017-12-01 23:01:44 +01:00
|
|
|
RTC_DCHECK_EQ(kFftLengthBy2Plus1, capture_spectrum.size());
|
|
|
|
|
RTC_DCHECK_EQ(kFftLengthBy2Plus1, subtractor_spectrum.size());
|
2018-10-22 11:41:05 +02:00
|
|
|
const auto& X2_reverb = reverb_render_spectrum;
|
2017-02-23 05:16:26 -08:00
|
|
|
const auto& Y2 = capture_spectrum;
|
|
|
|
|
const auto& E2 = subtractor_spectrum;
|
|
|
|
|
|
2018-10-04 15:37:54 +02:00
|
|
|
if (++blocks_since_reset_ < startup_phase_length_blocks__) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:41:05 +02:00
|
|
|
subband_erle_estimator_.Update(X2_reverb, Y2, E2, converged_filter,
|
|
|
|
|
onset_detection);
|
2018-11-20 12:54:23 +01:00
|
|
|
|
|
|
|
|
if (use_signal_dependent_erle_) {
|
|
|
|
|
signal_dependent_erle_estimator_.Update(
|
|
|
|
|
render_buffer, filter_frequency_response, X2_reverb, Y2, E2,
|
|
|
|
|
subband_erle_estimator_.Erle(), converged_filter);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:41:05 +02:00
|
|
|
fullband_erle_estimator_.Update(X2_reverb, Y2, E2, converged_filter);
|
2018-07-04 11:02:09 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-27 11:49:39 +02:00
|
|
|
void ErleEstimator::Dump(
|
|
|
|
|
const std::unique_ptr<ApmDataDumper>& data_dumper) const {
|
|
|
|
|
fullband_erle_estimator_.Dump(data_dumper);
|
|
|
|
|
subband_erle_estimator_.Dump(data_dumper);
|
2018-11-20 12:54:23 +01:00
|
|
|
signal_dependent_erle_estimator_.Dump(data_dumper);
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|