1 /*
2 * Copyright (c) 2018 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
11 #include "modules/audio_processing/aec3/reverb_model_estimator.h"
12
13 namespace webrtc {
14
ReverbModelEstimator(const EchoCanceller3Config & config,size_t num_capture_channels)15 ReverbModelEstimator::ReverbModelEstimator(const EchoCanceller3Config& config,
16 size_t num_capture_channels)
17 : reverb_decay_estimators_(num_capture_channels),
18 reverb_frequency_responses_(
19 num_capture_channels,
20 ReverbFrequencyResponse(
21 config.ep_strength.use_conservative_tail_frequency_response)) {
22 for (size_t ch = 0; ch < reverb_decay_estimators_.size(); ++ch) {
23 reverb_decay_estimators_[ch] =
24 std::make_unique<ReverbDecayEstimator>(config);
25 }
26 }
27
28 ReverbModelEstimator::~ReverbModelEstimator() = default;
29
Update(rtc::ArrayView<const std::vector<float>> impulse_responses,rtc::ArrayView<const std::vector<std::array<float,kFftLengthBy2Plus1>>> frequency_responses,rtc::ArrayView<const absl::optional<float>> linear_filter_qualities,rtc::ArrayView<const int> filter_delays_blocks,const std::vector<bool> & usable_linear_estimates,bool stationary_block)30 void ReverbModelEstimator::Update(
31 rtc::ArrayView<const std::vector<float>> impulse_responses,
32 rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>>
33 frequency_responses,
34 rtc::ArrayView<const absl::optional<float>> linear_filter_qualities,
35 rtc::ArrayView<const int> filter_delays_blocks,
36 const std::vector<bool>& usable_linear_estimates,
37 bool stationary_block) {
38 const size_t num_capture_channels = reverb_decay_estimators_.size();
39 RTC_DCHECK_EQ(num_capture_channels, impulse_responses.size());
40 RTC_DCHECK_EQ(num_capture_channels, frequency_responses.size());
41 RTC_DCHECK_EQ(num_capture_channels, usable_linear_estimates.size());
42
43 for (size_t ch = 0; ch < num_capture_channels; ++ch) {
44 // Estimate the frequency response for the reverb.
45 reverb_frequency_responses_[ch].Update(
46 frequency_responses[ch], filter_delays_blocks[ch],
47 linear_filter_qualities[ch], stationary_block);
48
49 // Estimate the reverb decay,
50 reverb_decay_estimators_[ch]->Update(
51 impulse_responses[ch], linear_filter_qualities[ch],
52 filter_delays_blocks[ch], usable_linear_estimates[ch],
53 stationary_block);
54 }
55 }
56
57 } // namespace webrtc
58