render_signal_analyzer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_RENDER_SIGNAL_ANALYZER_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_RENDER_SIGNAL_ANALYZER_H_
  12. #include <algorithm>
  13. #include <array>
  14. #include <cstddef>
  15. #include "absl/types/optional.h"
  16. #include "api/audio/echo_canceller3_config.h"
  17. #include "modules/audio_processing/aec3/aec3_common.h"
  18. #include "modules/audio_processing/aec3/render_buffer.h"
  19. #include "rtc_base/checks.h"
  20. #include "rtc_base/constructor_magic.h"
  21. namespace webrtc {
  22. // Provides functionality for analyzing the properties of the render signal.
  23. class RenderSignalAnalyzer {
  24. public:
  25. explicit RenderSignalAnalyzer(const EchoCanceller3Config& config);
  26. ~RenderSignalAnalyzer();
  27. // Updates the render signal analysis with the most recent render signal.
  28. void Update(const RenderBuffer& render_buffer,
  29. const absl::optional<size_t>& delay_partitions);
  30. // Returns true if the render signal is poorly exciting.
  31. bool PoorSignalExcitation() const {
  32. RTC_DCHECK_LT(2, narrow_band_counters_.size());
  33. return std::any_of(narrow_band_counters_.begin(),
  34. narrow_band_counters_.end(),
  35. [](size_t a) { return a > 10; });
  36. }
  37. // Zeros the array around regions with narrow bands signal characteristics.
  38. void MaskRegionsAroundNarrowBands(
  39. std::array<float, kFftLengthBy2Plus1>* v) const;
  40. absl::optional<int> NarrowPeakBand() const { return narrow_peak_band_; }
  41. private:
  42. const int strong_peak_freeze_duration_;
  43. std::array<size_t, kFftLengthBy2 - 1> narrow_band_counters_;
  44. absl::optional<int> narrow_peak_band_;
  45. size_t narrow_peak_counter_;
  46. RTC_DISALLOW_COPY_AND_ASSIGN(RenderSignalAnalyzer);
  47. };
  48. } // namespace webrtc
  49. #endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_SIGNAL_ANALYZER_H_