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