echo_remover_metrics.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_ECHO_REMOVER_METRICS_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_
  12. #include <array>
  13. #include "modules/audio_processing/aec3/aec3_common.h"
  14. #include "modules/audio_processing/aec3/aec_state.h"
  15. #include "rtc_base/constructor_magic.h"
  16. namespace webrtc {
  17. // Handles the reporting of metrics for the echo remover.
  18. class EchoRemoverMetrics {
  19. public:
  20. struct DbMetric {
  21. DbMetric();
  22. DbMetric(float sum_value, float floor_value, float ceil_value);
  23. void Update(float value);
  24. void UpdateInstant(float value);
  25. float sum_value;
  26. float floor_value;
  27. float ceil_value;
  28. };
  29. EchoRemoverMetrics();
  30. // Updates the metric with new data.
  31. void Update(
  32. const AecState& aec_state,
  33. const std::array<float, kFftLengthBy2Plus1>& comfort_noise_spectrum,
  34. const std::array<float, kFftLengthBy2Plus1>& suppressor_gain);
  35. // Returns true if the metrics have just been reported, otherwise false.
  36. bool MetricsReported() { return metrics_reported_; }
  37. private:
  38. // Resets the metrics.
  39. void ResetMetrics();
  40. int block_counter_ = 0;
  41. std::array<DbMetric, 2> erl_;
  42. DbMetric erl_time_domain_;
  43. std::array<DbMetric, 2> erle_;
  44. DbMetric erle_time_domain_;
  45. int active_render_count_ = 0;
  46. bool saturated_capture_ = false;
  47. bool metrics_reported_ = false;
  48. RTC_DISALLOW_COPY_AND_ASSIGN(EchoRemoverMetrics);
  49. };
  50. namespace aec3 {
  51. // Updates a banded metric of type DbMetric with the values in the supplied
  52. // array.
  53. void UpdateDbMetric(const std::array<float, kFftLengthBy2Plus1>& value,
  54. std::array<EchoRemoverMetrics::DbMetric, 2>* statistic);
  55. // Transforms a DbMetric from the linear domain into the logarithmic domain.
  56. int TransformDbMetricForReporting(bool negate,
  57. float min_value,
  58. float max_value,
  59. float offset,
  60. float scaling,
  61. float value);
  62. } // namespace aec3
  63. } // namespace webrtc
  64. #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_