tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

reverb_model_estimator.cc (2692B)


      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 #include <array>
     14 #include <cstddef>
     15 #include <memory>
     16 #include <optional>
     17 #include <vector>
     18 
     19 #include "api/array_view.h"
     20 #include "api/audio/echo_canceller3_config.h"
     21 #include "modules/audio_processing/aec3/aec3_common.h"
     22 #include "modules/audio_processing/aec3/reverb_decay_estimator.h"
     23 #include "modules/audio_processing/aec3/reverb_frequency_response.h"
     24 #include "rtc_base/checks.h"
     25 
     26 namespace webrtc {
     27 
     28 ReverbModelEstimator::ReverbModelEstimator(const EchoCanceller3Config& config,
     29                                           size_t num_capture_channels)
     30    : reverb_decay_estimators_(num_capture_channels),
     31      reverb_frequency_responses_(
     32          num_capture_channels,
     33          ReverbFrequencyResponse(
     34              config.ep_strength.use_conservative_tail_frequency_response)) {
     35  for (size_t ch = 0; ch < reverb_decay_estimators_.size(); ++ch) {
     36    reverb_decay_estimators_[ch] =
     37        std::make_unique<ReverbDecayEstimator>(config);
     38  }
     39 }
     40 
     41 ReverbModelEstimator::~ReverbModelEstimator() = default;
     42 
     43 void ReverbModelEstimator::Update(
     44    ArrayView<const std::vector<float>> impulse_responses,
     45    ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>>
     46        frequency_responses,
     47    ArrayView<const std::optional<float>> linear_filter_qualities,
     48    ArrayView<const int> filter_delays_blocks,
     49    const std::vector<bool>& usable_linear_estimates,
     50    bool stationary_block) {
     51  const size_t num_capture_channels = reverb_decay_estimators_.size();
     52  RTC_DCHECK_EQ(num_capture_channels, impulse_responses.size());
     53  RTC_DCHECK_EQ(num_capture_channels, frequency_responses.size());
     54  RTC_DCHECK_EQ(num_capture_channels, usable_linear_estimates.size());
     55 
     56  for (size_t ch = 0; ch < num_capture_channels; ++ch) {
     57    // Estimate the frequency response for the reverb.
     58    reverb_frequency_responses_[ch].Update(
     59        frequency_responses[ch], filter_delays_blocks[ch],
     60        linear_filter_qualities[ch], stationary_block);
     61 
     62    // Estimate the reverb decay,
     63    reverb_decay_estimators_[ch]->Update(
     64        impulse_responses[ch], linear_filter_qualities[ch],
     65        filter_delays_blocks[ch], usable_linear_estimates[ch],
     66        stationary_block);
     67  }
     68 }
     69 
     70 }  // namespace webrtc