| OLD | NEW | 
| (Empty) |  | 
 |   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 #include "webrtc/modules/audio_processing/aec3/residual_echo_estimator.h" | 
 |  12  | 
 |  13 #include <math.h> | 
 |  14 #include <vector> | 
 |  15  | 
 |  16 #include "webrtc/base/checks.h" | 
 |  17  | 
 |  18 namespace webrtc { | 
 |  19  | 
 |  20 ResidualEchoEstimator::ResidualEchoEstimator() { | 
 |  21   echo_path_gain_.fill(0.f); | 
 |  22 } | 
 |  23  | 
 |  24 ResidualEchoEstimator::~ResidualEchoEstimator() = default; | 
 |  25  | 
 |  26 void ResidualEchoEstimator::Estimate( | 
 |  27     const AecState& aec_state, | 
 |  28     const FftBuffer& X_buffer, | 
 |  29     const std::vector<std::array<float, kFftLengthBy2Plus1>>& H2, | 
 |  30     const std::array<float, kFftLengthBy2Plus1>& E2_main, | 
 |  31     const std::array<float, kFftLengthBy2Plus1>& E2_shadow, | 
 |  32     const std::array<float, kFftLengthBy2Plus1>& S2_linear, | 
 |  33     const std::array<float, kFftLengthBy2Plus1>& S2_fallback, | 
 |  34     const std::array<float, kFftLengthBy2Plus1>& Y2, | 
 |  35     const DelayHandler& delay_handler, | 
 |  36     std::array<float, kFftLengthBy2Plus1>* R2) { | 
 |  37   const rtc::Optional<size_t>& linear_filter_based_delay = | 
 |  38       delay_handler.FilterDelay(); | 
 |  39   if (linear_filter_based_delay) { | 
 |  40     std::copy(H2[*linear_filter_based_delay].begin(), | 
 |  41               H2[*linear_filter_based_delay].end(), echo_path_gain_.begin()); | 
 |  42   } | 
 |  43  | 
 |  44   const std::array<bool, kFftLengthBy2Plus1>& bands_with_reliable_filter = | 
 |  45       aec_state.BandsWithReliableFilter(); | 
 |  46  | 
 |  47   if (aec_state.UsableLinearEstimate()) { | 
 |  48     const std::array<float, kFftLengthBy2Plus1>& erle = aec_state.Erle(); | 
 |  49  | 
 |  50     for (size_t k = 0; k < R2->size(); ++k) { | 
 |  51       RTC_DCHECK_LT(0.f, erle[k]); | 
 |  52       (*R2)[k] = bands_with_reliable_filter[k] ? S2_linear[k] / erle[k] | 
 |  53                                                : S2_fallback[k]; | 
 |  54     } | 
 |  55  | 
 |  56   } else if (aec_state.ModelBasedAecFeasible()) { | 
 |  57     const rtc::Optional<size_t>& provided_delay = delay_handler.ExternalDelay(); | 
 |  58     RTC_DCHECK(provided_delay); | 
 |  59     const std::array<float, kFftLengthBy2Plus1>& X2 = | 
 |  60         X_buffer.Spectrum(*provided_delay); | 
 |  61     for (size_t k = 0; k < R2->size(); ++k) { | 
 |  62       (*R2)[k] = bands_with_reliable_filter[k] ? echo_path_gain_[k] * X2[k] | 
 |  63                                                : S2_fallback[k]; | 
 |  64     } | 
 |  65   } else if (aec_state.EchoLeakageDetected()) { | 
 |  66     if (aec_state.ActiveRender()) { | 
 |  67       std::copy(Y2.begin(), Y2.end(), R2->begin()); | 
 |  68     } else { | 
 |  69       R2->fill(0.f); | 
 |  70     } | 
 |  71   } else { | 
 |  72     R2->fill(0.f); | 
 |  73   } | 
 |  74 } | 
 |  75  | 
 |  76 }  // namespace webrtc | 
| OLD | NEW |