tor-browser

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

subband_erle_estimator.h (3981B)


      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 #ifndef MODULES_AUDIO_PROCESSING_AEC3_SUBBAND_ERLE_ESTIMATOR_H_
     12 #define MODULES_AUDIO_PROCESSING_AEC3_SUBBAND_ERLE_ESTIMATOR_H_
     13 
     14 #include <stddef.h>
     15 
     16 #include <array>
     17 #include <memory>
     18 #include <vector>
     19 
     20 #include "api/array_view.h"
     21 #include "api/audio/echo_canceller3_config.h"
     22 #include "api/environment/environment.h"
     23 #include "modules/audio_processing/aec3/aec3_common.h"
     24 #include "modules/audio_processing/logging/apm_data_dumper.h"
     25 
     26 namespace webrtc {
     27 
     28 // Estimates the echo return loss enhancement for each frequency subband.
     29 class SubbandErleEstimator {
     30 public:
     31  SubbandErleEstimator(const Environment& env,
     32                       const EchoCanceller3Config& config,
     33                       size_t num_capture_channels);
     34  ~SubbandErleEstimator();
     35 
     36  // Resets the ERLE estimator.
     37  void Reset();
     38 
     39  // Updates the ERLE estimate.
     40  void Update(ArrayView<const float, kFftLengthBy2Plus1> X2,
     41              ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2,
     42              ArrayView<const std::array<float, kFftLengthBy2Plus1>> E2,
     43              const std::vector<bool>& converged_filters);
     44 
     45  // Returns the ERLE estimate.
     46  ArrayView<const std::array<float, kFftLengthBy2Plus1>> Erle(
     47      bool onset_compensated) const {
     48    return onset_compensated && use_onset_detection_ ? erle_onset_compensated_
     49                                                     : erle_;
     50  }
     51 
     52  // Returns the non-capped ERLE estimate.
     53  ArrayView<const std::array<float, kFftLengthBy2Plus1>> ErleUnbounded() const {
     54    return erle_unbounded_;
     55  }
     56 
     57  // Returns the ERLE estimate at onsets (only used for testing).
     58  ArrayView<const std::array<float, kFftLengthBy2Plus1>> ErleDuringOnsets()
     59      const {
     60    return erle_during_onsets_;
     61  }
     62 
     63  void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper) const;
     64 
     65 private:
     66  struct AccumulatedSpectra {
     67    explicit AccumulatedSpectra(size_t num_capture_channels)
     68        : Y2(num_capture_channels),
     69          E2(num_capture_channels),
     70          low_render_energy(num_capture_channels),
     71          num_points(num_capture_channels) {}
     72    std::vector<std::array<float, kFftLengthBy2Plus1>> Y2;
     73    std::vector<std::array<float, kFftLengthBy2Plus1>> E2;
     74    std::vector<std::array<bool, kFftLengthBy2Plus1>> low_render_energy;
     75    std::vector<int> num_points;
     76  };
     77 
     78  void UpdateAccumulatedSpectra(
     79      ArrayView<const float, kFftLengthBy2Plus1> X2,
     80      ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2,
     81      ArrayView<const std::array<float, kFftLengthBy2Plus1>> E2,
     82      const std::vector<bool>& converged_filters);
     83 
     84  void ResetAccumulatedSpectra();
     85 
     86  void UpdateBands(const std::vector<bool>& converged_filters);
     87  void DecreaseErlePerBandForLowRenderSignals();
     88 
     89  const bool use_onset_detection_;
     90  const float min_erle_;
     91  const std::array<float, kFftLengthBy2Plus1> max_erle_;
     92  const bool use_min_erle_during_onsets_;
     93  AccumulatedSpectra accum_spectra_;
     94  // ERLE without special handling of render onsets.
     95  std::vector<std::array<float, kFftLengthBy2Plus1>> erle_;
     96  // ERLE lowered during render onsets.
     97  std::vector<std::array<float, kFftLengthBy2Plus1>> erle_onset_compensated_;
     98  std::vector<std::array<float, kFftLengthBy2Plus1>> erle_unbounded_;
     99  // Estimation of ERLE during render onsets.
    100  std::vector<std::array<float, kFftLengthBy2Plus1>> erle_during_onsets_;
    101  std::vector<std::array<bool, kFftLengthBy2Plus1>> coming_onset_;
    102  std::vector<std::array<int, kFftLengthBy2Plus1>> hold_counters_;
    103 };
    104 
    105 }  // namespace webrtc
    106 
    107 #endif  // MODULES_AUDIO_PROCESSING_AEC3_SUBBAND_ERLE_ESTIMATOR_H_