• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMFORT_NOISE_GENERATOR_H_
12 #define MODULES_AUDIO_PROCESSING_AEC3_COMFORT_NOISE_GENERATOR_H_
13 
14 #include <stdint.h>
15 
16 #include <array>
17 #include <memory>
18 
19 #include "modules/audio_processing/aec3/aec3_common.h"
20 #include "modules/audio_processing/aec3/aec_state.h"
21 #include "modules/audio_processing/aec3/fft_data.h"
22 #include "rtc_base/constructor_magic.h"
23 #include "rtc_base/system/arch.h"
24 
25 namespace webrtc {
26 namespace aec3 {
27 #if defined(WEBRTC_ARCH_X86_FAMILY)
28 
29 void EstimateComfortNoise_SSE2(const std::array<float, kFftLengthBy2Plus1>& N2,
30                                uint32_t* seed,
31                                FftData* lower_band_noise,
32                                FftData* upper_band_noise);
33 #endif
34 void EstimateComfortNoise(const std::array<float, kFftLengthBy2Plus1>& N2,
35                           uint32_t* seed,
36                           FftData* lower_band_noise,
37                           FftData* upper_band_noise);
38 
39 }  // namespace aec3
40 
41 // Generates the comfort noise.
42 class ComfortNoiseGenerator {
43  public:
44   ComfortNoiseGenerator(const EchoCanceller3Config& config,
45                         Aec3Optimization optimization,
46                         size_t num_capture_channels);
47   ComfortNoiseGenerator() = delete;
48   ~ComfortNoiseGenerator();
49   ComfortNoiseGenerator(const ComfortNoiseGenerator&) = delete;
50 
51   // Computes the comfort noise.
52   void Compute(bool saturated_capture,
53                rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>>
54                    capture_spectrum,
55                rtc::ArrayView<FftData> lower_band_noise,
56                rtc::ArrayView<FftData> upper_band_noise);
57 
58   // Returns the estimate of the background noise spectrum.
NoiseSpectrum()59   rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> NoiseSpectrum()
60       const {
61     return N2_;
62   }
63 
64  private:
65   const Aec3Optimization optimization_;
66   uint32_t seed_;
67   const size_t num_capture_channels_;
68   const float noise_floor_;
69   std::unique_ptr<std::vector<std::array<float, kFftLengthBy2Plus1>>>
70       N2_initial_;
71   std::vector<std::array<float, kFftLengthBy2Plus1>> Y2_smoothed_;
72   std::vector<std::array<float, kFftLengthBy2Plus1>> N2_;
73   int N2_counter_ = 0;
74 };
75 
76 }  // namespace webrtc
77 
78 #endif  // MODULES_AUDIO_PROCESSING_AEC3_COMFORT_NOISE_GENERATOR_H_
79