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