tor-browser

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

residual_echo_estimator.h (3450B)


      1 /*
      2 *  Copyright (c) 2017 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_RESIDUAL_ECHO_ESTIMATOR_H_
     12 #define MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_
     13 
     14 #include <array>
     15 #include <cstddef>
     16 
     17 #include "api/array_view.h"
     18 #include "api/audio/echo_canceller3_config.h"
     19 #include "api/audio/neural_residual_echo_estimator.h"
     20 #include "api/environment/environment.h"
     21 #include "modules/audio_processing/aec3/aec3_common.h"
     22 #include "modules/audio_processing/aec3/aec_state.h"
     23 #include "modules/audio_processing/aec3/render_buffer.h"
     24 #include "modules/audio_processing/aec3/reverb_model.h"
     25 
     26 namespace webrtc {
     27 
     28 class ResidualEchoEstimator {
     29 public:
     30  ResidualEchoEstimator(
     31      const Environment& env,
     32      const EchoCanceller3Config& config,
     33      size_t num_render_channels,
     34      NeuralResidualEchoEstimator* neural_residual_echo_estimator);
     35  ~ResidualEchoEstimator();
     36 
     37  ResidualEchoEstimator(const ResidualEchoEstimator&) = delete;
     38  ResidualEchoEstimator& operator=(const ResidualEchoEstimator&) = delete;
     39 
     40  void Estimate(
     41      const AecState& aec_state,
     42      const RenderBuffer& render_buffer,
     43      ArrayView<const std::array<float, kFftLengthBy2>> capture,
     44      ArrayView<const std::array<float, kFftLengthBy2>> linear_aec_output,
     45      ArrayView<const std::array<float, kFftLengthBy2Plus1>> S2_linear,
     46      ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2,
     47      ArrayView<const std::array<float, kFftLengthBy2Plus1>> E2,
     48      bool dominant_nearend,
     49      ArrayView<std::array<float, kFftLengthBy2Plus1>> R2,
     50      ArrayView<std::array<float, kFftLengthBy2Plus1>> R2_unbounded);
     51 
     52 private:
     53  enum class ReverbType { kLinear, kNonLinear };
     54 
     55  // Resets the state.
     56  void Reset();
     57 
     58  // Updates estimate for the power of the stationary noise component in the
     59  // render signal.
     60  void UpdateRenderNoisePower(const RenderBuffer& render_buffer);
     61 
     62  // Updates the reverb estimation.
     63  void UpdateReverb(ReverbType reverb_type,
     64                    const AecState& aec_state,
     65                    const RenderBuffer& render_buffer,
     66                    bool dominant_nearend);
     67 
     68  // Adds the estimated unmodelled echo power to the residual echo power
     69  // estimate.
     70  void AddReverb(ArrayView<std::array<float, kFftLengthBy2Plus1>> R2) const;
     71 
     72  // Gets the echo path gain to apply.
     73  float GetEchoPathGain(const AecState& aec_state,
     74                        bool gain_for_early_reflections) const;
     75 
     76  const EchoCanceller3Config config_;
     77  const size_t num_render_channels_;
     78  const float early_reflections_transparent_mode_gain_;
     79  const float late_reflections_transparent_mode_gain_;
     80  const float early_reflections_general_gain_;
     81  const float late_reflections_general_gain_;
     82  const bool erle_onset_compensation_in_dominant_nearend_;
     83  std::array<float, kFftLengthBy2Plus1> X2_noise_floor_;
     84  std::array<int, kFftLengthBy2Plus1> X2_noise_floor_counter_;
     85  ReverbModel echo_reverb_;
     86  NeuralResidualEchoEstimator* neural_residual_echo_estimator_;
     87 };
     88 
     89 }  // namespace webrtc
     90 
     91 #endif  // MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_