• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
16 
17 #include "absl/types/optional.h"
18 #include "api/audio/echo_canceller3_config.h"
19 #include "modules/audio_processing/aec3/aec3_common.h"
20 #include "modules/audio_processing/aec3/aec_state.h"
21 #include "modules/audio_processing/aec3/render_buffer.h"
22 #include "modules/audio_processing/aec3/reverb_model.h"
23 #include "modules/audio_processing/aec3/spectrum_buffer.h"
24 #include "rtc_base/checks.h"
25 
26 namespace webrtc {
27 
28 class ResidualEchoEstimator {
29  public:
30   ResidualEchoEstimator(const EchoCanceller3Config& config,
31                         size_t num_render_channels);
32   ~ResidualEchoEstimator();
33 
34   ResidualEchoEstimator(const ResidualEchoEstimator&) = delete;
35   ResidualEchoEstimator& operator=(const ResidualEchoEstimator&) = delete;
36 
37   void Estimate(
38       const AecState& aec_state,
39       const RenderBuffer& render_buffer,
40       rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> S2_linear,
41       rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Y2,
42       rtc::ArrayView<std::array<float, kFftLengthBy2Plus1>> R2);
43 
44  private:
45   enum class ReverbType { kLinear, kNonLinear };
46 
47   // Resets the state.
48   void Reset();
49 
50   // Updates estimate for the power of the stationary noise component in the
51   // render signal.
52   void UpdateRenderNoisePower(const RenderBuffer& render_buffer);
53 
54   // Adds the estimated unmodelled echo power to the residual echo power
55   // estimate.
56   void AddReverb(ReverbType reverb_type,
57                  const AecState& aec_state,
58                  const RenderBuffer& render_buffer,
59                  rtc::ArrayView<std::array<float, kFftLengthBy2Plus1>> R2);
60 
61   // Gets the echo path gain to apply.
62   float GetEchoPathGain(const AecState& aec_state,
63                         bool gain_for_early_reflections) const;
64 
65   const EchoCanceller3Config config_;
66   const size_t num_render_channels_;
67   const float early_reflections_transparent_mode_gain_;
68   const float late_reflections_transparent_mode_gain_;
69   const float early_reflections_general_gain_;
70   const float late_reflections_general_gain_;
71   const bool model_reverb_in_nonlinear_mode_;
72   std::array<float, kFftLengthBy2Plus1> X2_noise_floor_;
73   std::array<int, kFftLengthBy2Plus1> X2_noise_floor_counter_;
74   ReverbModel echo_reverb_;
75 };
76 
77 }  // namespace webrtc
78 
79 #endif  // MODULES_AUDIO_PROCESSING_AEC3_RESIDUAL_ECHO_ESTIMATOR_H_
80