noise_estimator.h 2.6 KB

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