blob: c3d8e20da176fb4a445614d96fb47c962c416991 [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <array>
15
16#include "modules/audio_processing/aec3/aec3_common.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_processing/aec3/aec_state.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/constructor_magic.h"
peahe985b3f2017-02-28 22:08:53 -080019
20namespace webrtc {
21
22// Handles the reporting of metrics for the echo remover.
23class EchoRemoverMetrics {
24 public:
25 struct DbMetric {
26 DbMetric();
27 DbMetric(float sum_value, float floor_value, float ceil_value);
28 void Update(float value);
Gustaf Ullberg2723fb12017-11-23 14:46:48 +010029 void UpdateInstant(float value);
peahe985b3f2017-02-28 22:08:53 -080030 float sum_value;
31 float floor_value;
32 float ceil_value;
33 };
34
35 EchoRemoverMetrics();
36
37 // Updates the metric with new data.
38 void Update(
39 const AecState& aec_state,
40 const std::array<float, kFftLengthBy2Plus1>& comfort_noise_spectrum,
41 const std::array<float, kFftLengthBy2Plus1>& suppressor_gain);
42
43 // Returns true if the metrics have just been reported, otherwise false.
44 bool MetricsReported() { return metrics_reported_; }
45
46 private:
47 // Resets the metrics.
48 void ResetMetrics();
49
50 int block_counter_ = 0;
Gustaf Ullberg2723fb12017-11-23 14:46:48 +010051 DbMetric erl_time_domain_;
Gustaf Ullberg2723fb12017-11-23 14:46:48 +010052 DbMetric erle_time_domain_;
peahe985b3f2017-02-28 22:08:53 -080053 bool saturated_capture_ = false;
54 bool metrics_reported_ = false;
55
56 RTC_DISALLOW_COPY_AND_ASSIGN(EchoRemoverMetrics);
57};
58
59namespace aec3 {
60
61// Updates a banded metric of type DbMetric with the values in the supplied
62// array.
63void UpdateDbMetric(const std::array<float, kFftLengthBy2Plus1>& value,
64 std::array<EchoRemoverMetrics::DbMetric, 2>* statistic);
65
66// Transforms a DbMetric from the linear domain into the logarithmic domain.
67int TransformDbMetricForReporting(bool negate,
68 float min_value,
69 float max_value,
70 float offset,
71 float scaling,
72 float value);
73
74} // namespace aec3
75
76} // namespace webrtc
77
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020078#endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_