erl_estimator.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef MODULES_AUDIO_PROCESSING_AEC3_ERL_ESTIMATOR_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_ERL_ESTIMATOR_H_
  12. #include <stddef.h>
  13. #include <array>
  14. #include <vector>
  15. #include "api/array_view.h"
  16. #include "modules/audio_processing/aec3/aec3_common.h"
  17. #include "rtc_base/constructor_magic.h"
  18. namespace webrtc {
  19. // Estimates the echo return loss based on the signal spectra.
  20. class ErlEstimator {
  21. public:
  22. explicit ErlEstimator(size_t startup_phase_length_blocks_);
  23. ~ErlEstimator();
  24. // Resets the ERL estimation.
  25. void Reset();
  26. // Updates the ERL estimate.
  27. void Update(const std::vector<bool>& converged_filters,
  28. rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
  29. render_spectra,
  30. rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
  31. capture_spectra);
  32. // Returns the most recent ERL estimate.
  33. const std::array<float, kFftLengthBy2Plus1>& Erl() const { return erl_; }
  34. float ErlTimeDomain() const { return erl_time_domain_; }
  35. private:
  36. const size_t startup_phase_length_blocks__;
  37. std::array<float, kFftLengthBy2Plus1> erl_;
  38. std::array<int, kFftLengthBy2Minus1> hold_counters_;
  39. float erl_time_domain_;
  40. int hold_counter_time_domain_;
  41. size_t blocks_since_reset_ = 0;
  42. RTC_DISALLOW_COPY_AND_ASSIGN(ErlEstimator);
  43. };
  44. } // namespace webrtc
  45. #endif // MODULES_AUDIO_PROCESSING_AEC3_ERL_ESTIMATOR_H_