peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_ |
peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/audio_processing/aec3/aec_state.h" |
| 15 | #include "rtc_base/constructormagic.h" |
peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 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); |
Gustaf Ullberg | 2723fb1 | 2017-11-23 14:46:48 +0100 | [diff] [blame^] | 26 | void UpdateInstant(float value); |
peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 27 | 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 Ullberg | 2723fb1 | 2017-11-23 14:46:48 +0100 | [diff] [blame^] | 49 | DbMetric erl_time_domain_; |
peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 50 | std::array<DbMetric, 2> erle_; |
Gustaf Ullberg | 2723fb1 | 2017-11-23 14:46:48 +0100 | [diff] [blame^] | 51 | DbMetric erle_time_domain_; |
peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 52 | 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 | |
| 61 | namespace aec3 { |
| 62 | |
| 63 | // Updates a banded metric of type DbMetric with the values in the supplied |
| 64 | // array. |
| 65 | void 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. |
| 69 | int 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 80 | #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_ |