• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_(num_capture_channels) {
19   for (size_t ch = 0; ch < reverb_decay_estimators_.size(); ++ch) {
20     reverb_decay_estimators_[ch] =
21         std::make_unique<ReverbDecayEstimator>(config);
22   }
23 }
24 
25 ReverbModelEstimator::~ReverbModelEstimator() = default;
26 
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)27 void ReverbModelEstimator::Update(
28     rtc::ArrayView<const std::vector<float>> impulse_responses,
29     rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>>
30         frequency_responses,
31     rtc::ArrayView<const absl::optional<float>> linear_filter_qualities,
32     rtc::ArrayView<const int> filter_delays_blocks,
33     const std::vector<bool>& usable_linear_estimates,
34     bool stationary_block) {
35   const size_t num_capture_channels = reverb_decay_estimators_.size();
36   RTC_DCHECK_EQ(num_capture_channels, impulse_responses.size());
37   RTC_DCHECK_EQ(num_capture_channels, frequency_responses.size());
38   RTC_DCHECK_EQ(num_capture_channels, usable_linear_estimates.size());
39 
40   for (size_t ch = 0; ch < num_capture_channels; ++ch) {
41     // Estimate the frequency response for the reverb.
42     reverb_frequency_responses_[ch].Update(
43         frequency_responses[ch], filter_delays_blocks[ch],
44         linear_filter_qualities[ch], stationary_block);
45 
46     // Estimate the reverb decay,
47     reverb_decay_estimators_[ch]->Update(
48         impulse_responses[ch], linear_filter_qualities[ch],
49         filter_delays_blocks[ch], usable_linear_estimates[ch],
50         stationary_block);
51   }
52 }
53 
54 }  // namespace webrtc
55