echo_audibility.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2018 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_ECHO_AUDIBILITY_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_AUDIBILITY_H_
  12. #include <stddef.h>
  13. #include "absl/types/optional.h"
  14. #include "api/array_view.h"
  15. #include "modules/audio_processing/aec3/block_buffer.h"
  16. #include "modules/audio_processing/aec3/render_buffer.h"
  17. #include "modules/audio_processing/aec3/spectrum_buffer.h"
  18. #include "modules/audio_processing/aec3/stationarity_estimator.h"
  19. #include "rtc_base/constructor_magic.h"
  20. namespace webrtc {
  21. class EchoAudibility {
  22. public:
  23. explicit EchoAudibility(bool use_render_stationarity_at_init);
  24. ~EchoAudibility();
  25. EchoAudibility(const EchoAudibility&) = delete;
  26. EchoAudibility& operator=(const EchoAudibility&) = delete;
  27. // Feed new render data to the echo audibility estimator.
  28. void Update(const RenderBuffer& render_buffer,
  29. rtc::ArrayView<const float> average_reverb,
  30. int min_channel_delay_blocks,
  31. bool external_delay_seen);
  32. // Get the residual echo scaling.
  33. void GetResidualEchoScaling(bool filter_has_had_time_to_converge,
  34. rtc::ArrayView<float> residual_scaling) const {
  35. for (size_t band = 0; band < residual_scaling.size(); ++band) {
  36. if (render_stationarity_.IsBandStationary(band) &&
  37. (filter_has_had_time_to_converge ||
  38. use_render_stationarity_at_init_)) {
  39. residual_scaling[band] = 0.f;
  40. } else {
  41. residual_scaling[band] = 1.0f;
  42. }
  43. }
  44. }
  45. // Returns true if the current render block is estimated as stationary.
  46. bool IsBlockStationary() const {
  47. return render_stationarity_.IsBlockStationary();
  48. }
  49. private:
  50. // Reset the EchoAudibility class.
  51. void Reset();
  52. // Updates the render stationarity flags for the current frame.
  53. void UpdateRenderStationarityFlags(const RenderBuffer& render_buffer,
  54. rtc::ArrayView<const float> average_reverb,
  55. int delay_blocks);
  56. // Updates the noise estimator with the new render data since the previous
  57. // call to this method.
  58. void UpdateRenderNoiseEstimator(const SpectrumBuffer& spectrum_buffer,
  59. const BlockBuffer& block_buffer,
  60. bool external_delay_seen);
  61. // Returns a bool being true if the render signal contains just close to zero
  62. // values.
  63. bool IsRenderTooLow(const BlockBuffer& block_buffer);
  64. absl::optional<int> render_spectrum_write_prev_;
  65. int render_block_write_prev_;
  66. bool non_zero_render_seen_;
  67. const bool use_render_stationarity_at_init_;
  68. StationarityEstimator render_stationarity_;
  69. };
  70. } // namespace webrtc
  71. #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_AUDIBILITY_H_