tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

echo_remover_metrics.h (2493B)


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