tor-browser

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

noise_estimator.h (2690B)


      1 /*
      2 *  Copyright (c) 2019 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_NS_NOISE_ESTIMATOR_H_
     12 #define MODULES_AUDIO_PROCESSING_NS_NOISE_ESTIMATOR_H_
     13 
     14 #include <array>
     15 #include <cstdint>
     16 
     17 #include "api/array_view.h"
     18 #include "modules/audio_processing/ns/ns_common.h"
     19 #include "modules/audio_processing/ns/quantile_noise_estimator.h"
     20 #include "modules/audio_processing/ns/suppression_params.h"
     21 
     22 namespace webrtc {
     23 
     24 // Class for estimating the spectral characteristics of the noise in an incoming
     25 // signal.
     26 class NoiseEstimator {
     27 public:
     28  explicit NoiseEstimator(const SuppressionParams& suppression_params);
     29 
     30  // Prepare the estimator for analysis of a new frame.
     31  void PrepareAnalysis();
     32 
     33  // Performs the first step of the estimator update.
     34  void PreUpdate(int32_t num_analyzed_frames,
     35                 ArrayView<const float, kFftSizeBy2Plus1> signal_spectrum,
     36                 float signal_spectral_sum);
     37 
     38  // Performs the second step of the estimator update.
     39  void PostUpdate(ArrayView<const float> speech_probability,
     40                  ArrayView<const float, kFftSizeBy2Plus1> signal_spectrum);
     41 
     42  // Returns the noise spectral estimate.
     43  ArrayView<const float, kFftSizeBy2Plus1> get_noise_spectrum() const {
     44    return noise_spectrum_;
     45  }
     46 
     47  // Returns the noise from the previous frame.
     48  ArrayView<const float, kFftSizeBy2Plus1> get_prev_noise_spectrum() const {
     49    return prev_noise_spectrum_;
     50  }
     51 
     52  // Returns a noise spectral estimate based on white and pink noise parameters.
     53  ArrayView<const float, kFftSizeBy2Plus1> get_parametric_noise_spectrum()
     54      const {
     55    return parametric_noise_spectrum_;
     56  }
     57  ArrayView<const float, kFftSizeBy2Plus1> get_conservative_noise_spectrum()
     58      const {
     59    return conservative_noise_spectrum_;
     60  }
     61 
     62 private:
     63  const SuppressionParams& suppression_params_;
     64  float white_noise_level_ = 0.f;
     65  float pink_noise_numerator_ = 0.f;
     66  float pink_noise_exp_ = 0.f;
     67  std::array<float, kFftSizeBy2Plus1> prev_noise_spectrum_;
     68  std::array<float, kFftSizeBy2Plus1> conservative_noise_spectrum_;
     69  std::array<float, kFftSizeBy2Plus1> parametric_noise_spectrum_;
     70  std::array<float, kFftSizeBy2Plus1> noise_spectrum_;
     71  QuantileNoiseEstimator quantile_noise_estimator_;
     72 };
     73 
     74 }  // namespace webrtc
     75 
     76 #endif  // MODULES_AUDIO_PROCESSING_NS_NOISE_ESTIMATOR_H_