• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WIENER_FILTER_H_
12 #define MODULES_AUDIO_PROCESSING_NS_WIENER_FILTER_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/suppression_params.h"
19 
20 namespace webrtc {
21 
22 // Estimates a Wiener-filter based frequency domain noise reduction filter.
23 class WienerFilter {
24  public:
25   explicit WienerFilter(const SuppressionParams& suppression_params);
26   WienerFilter(const WienerFilter&) = delete;
27   WienerFilter& operator=(const WienerFilter&) = delete;
28 
29   // Updates the filter estimate.
30   void Update(
31       int32_t num_analyzed_frames,
32       rtc::ArrayView<const float, kFftSizeBy2Plus1> noise_spectrum,
33       rtc::ArrayView<const float, kFftSizeBy2Plus1> prev_noise_spectrum,
34       rtc::ArrayView<const float, kFftSizeBy2Plus1> parametric_noise_spectrum,
35       rtc::ArrayView<const float, kFftSizeBy2Plus1> signal_spectrum);
36 
37   // Compute an overall gain scaling factor.
38   float ComputeOverallScalingFactor(int32_t num_analyzed_frames,
39                                     float prior_speech_probability,
40                                     float energy_before_filtering,
41                                     float energy_after_filtering) const;
42 
43   // Returns the filter.
get_filter()44   rtc::ArrayView<const float, kFftSizeBy2Plus1> get_filter() const {
45     return filter_;
46   }
47 
48  private:
49   const SuppressionParams& suppression_params_;
50   std::array<float, kFftSizeBy2Plus1> spectrum_prev_process_;
51   std::array<float, kFftSizeBy2Plus1> initial_spectral_estimate_;
52   std::array<float, kFftSizeBy2Plus1> filter_;
53 };
54 
55 }  // namespace webrtc
56 
57 #endif  // MODULES_AUDIO_PROCESSING_NS_WIENER_FILTER_H_
58