erle_estimator.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_ERLE_ESTIMATOR_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_
  12. #include <stddef.h>
  13. #include <array>
  14. #include <memory>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. #include "api/array_view.h"
  18. #include "api/audio/echo_canceller3_config.h"
  19. #include "modules/audio_processing/aec3/aec3_common.h"
  20. #include "modules/audio_processing/aec3/fullband_erle_estimator.h"
  21. #include "modules/audio_processing/aec3/render_buffer.h"
  22. #include "modules/audio_processing/aec3/signal_dependent_erle_estimator.h"
  23. #include "modules/audio_processing/aec3/subband_erle_estimator.h"
  24. #include "modules/audio_processing/logging/apm_data_dumper.h"
  25. namespace webrtc {
  26. // Estimates the echo return loss enhancement. One estimate is done per subband
  27. // and another one is done using the aggreation of energy over all the subbands.
  28. class ErleEstimator {
  29. public:
  30. ErleEstimator(size_t startup_phase_length_blocks,
  31. const EchoCanceller3Config& config,
  32. size_t num_capture_channels);
  33. ~ErleEstimator();
  34. // Resets the fullband ERLE estimator and the subbands ERLE estimators.
  35. void Reset(bool delay_change);
  36. // Updates the ERLE estimates.
  37. void Update(
  38. const RenderBuffer& render_buffer,
  39. rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>>
  40. filter_frequency_responses,
  41. rtc::ArrayView<const float, kFftLengthBy2Plus1>
  42. avg_render_spectrum_with_reverb,
  43. rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
  44. capture_spectra,
  45. rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
  46. subtractor_spectra,
  47. const std::vector<bool>& converged_filters);
  48. // Returns the most recent subband ERLE estimates.
  49. rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> Erle() const {
  50. return signal_dependent_erle_estimator_
  51. ? signal_dependent_erle_estimator_->Erle()
  52. : subband_erle_estimator_.Erle();
  53. }
  54. // Returns the subband ERLE that are estimated during onsets (only used for
  55. // testing).
  56. rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> ErleOnsets()
  57. const {
  58. return subband_erle_estimator_.ErleOnsets();
  59. }
  60. // Returns the fullband ERLE estimate.
  61. float FullbandErleLog2() const {
  62. return fullband_erle_estimator_.FullbandErleLog2();
  63. }
  64. // Returns an estimation of the current linear filter quality based on the
  65. // current and past fullband ERLE estimates. The returned value is a float
  66. // vector with content between 0 and 1 where 1 indicates that, at this current
  67. // time instant, the linear filter is reaching its maximum subtraction
  68. // performance.
  69. rtc::ArrayView<const absl::optional<float>> GetInstLinearQualityEstimates()
  70. const {
  71. return fullband_erle_estimator_.GetInstLinearQualityEstimates();
  72. }
  73. void Dump(const std::unique_ptr<ApmDataDumper>& data_dumper) const;
  74. private:
  75. const size_t startup_phase_length_blocks_;
  76. FullBandErleEstimator fullband_erle_estimator_;
  77. SubbandErleEstimator subband_erle_estimator_;
  78. std::unique_ptr<SignalDependentErleEstimator>
  79. signal_dependent_erle_estimator_;
  80. size_t blocks_since_reset_ = 0;
  81. };
  82. } // namespace webrtc
  83. #endif // MODULES_AUDIO_PROCESSING_AEC3_ERLE_ESTIMATOR_H_