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