peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_ |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 13 | |
| 14 | #include <array> |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 15 | #include <vector> |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_processing/aec3/aec3_common.h" |
| 18 | #include "modules/audio_processing/aec3/render_signal_analyzer.h" |
| 19 | #include "modules/audio_processing/include/audio_processing.h" |
| 20 | #include "rtc_base/constructormagic.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 23 | |
| 24 | class SuppressionGain { |
| 25 | public: |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 26 | SuppressionGain(const EchoCanceller3Config& config, |
peah | 8cee56f | 2017-08-24 22:36:53 -0700 | [diff] [blame] | 27 | Aec3Optimization optimization); |
peah | 1d68089 | 2017-05-23 04:07:10 -0700 | [diff] [blame] | 28 | void GetGain(const std::array<float, kFftLengthBy2Plus1>& nearend, |
| 29 | const std::array<float, kFftLengthBy2Plus1>& echo, |
| 30 | const std::array<float, kFftLengthBy2Plus1>& comfort_noise, |
peah | 14c11a4 | 2017-07-11 06:13:43 -0700 | [diff] [blame] | 31 | const RenderSignalAnalyzer& render_signal_analyzer, |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 32 | bool saturated_echo, |
| 33 | const std::vector<std::vector<float>>& render, |
peah | 6d822ad | 2017-04-10 13:52:14 -0700 | [diff] [blame] | 34 | bool force_zero_gain, |
Per Åhgren | c65ce78 | 2017-10-09 13:01:39 +0200 | [diff] [blame] | 35 | bool linear_echo_estimate, |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 36 | float* high_bands_gain, |
| 37 | std::array<float, kFftLengthBy2Plus1>* low_band_gain); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 38 | |
| 39 | private: |
peah | 1d68089 | 2017-05-23 04:07:10 -0700 | [diff] [blame] | 40 | void LowerBandGain(bool stationary_with_low_power, |
peah | 14c11a4 | 2017-07-11 06:13:43 -0700 | [diff] [blame] | 41 | const rtc::Optional<int>& narrow_peak_band, |
peah | 1d68089 | 2017-05-23 04:07:10 -0700 | [diff] [blame] | 42 | bool saturated_echo, |
Per Åhgren | c65ce78 | 2017-10-09 13:01:39 +0200 | [diff] [blame] | 43 | bool linear_echo_estimate, |
peah | 1d68089 | 2017-05-23 04:07:10 -0700 | [diff] [blame] | 44 | const std::array<float, kFftLengthBy2Plus1>& nearend, |
| 45 | const std::array<float, kFftLengthBy2Plus1>& echo, |
| 46 | const std::array<float, kFftLengthBy2Plus1>& comfort_noise, |
| 47 | std::array<float, kFftLengthBy2Plus1>* gain); |
| 48 | |
| 49 | class LowNoiseRenderDetector { |
| 50 | public: |
| 51 | bool Detect(const std::vector<std::vector<float>>& render); |
| 52 | |
| 53 | private: |
| 54 | float average_power_ = 32768.f * 32768.f; |
| 55 | }; |
| 56 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 57 | const Aec3Optimization optimization_; |
peah | 1d68089 | 2017-05-23 04:07:10 -0700 | [diff] [blame] | 58 | std::array<float, kFftLengthBy2Plus1> last_gain_; |
| 59 | std::array<float, kFftLengthBy2Plus1> last_masker_; |
| 60 | std::array<float, kFftLengthBy2Plus1> gain_increase_; |
| 61 | std::array<float, kFftLengthBy2Plus1> last_echo_; |
| 62 | |
| 63 | LowNoiseRenderDetector low_render_detector_; |
| 64 | size_t no_saturation_counter_ = 0; |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 65 | const EchoCanceller3Config config_; |
peah | 8cee56f | 2017-08-24 22:36:53 -0700 | [diff] [blame] | 66 | RTC_DISALLOW_COPY_AND_ASSIGN(SuppressionGain); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace webrtc |
| 70 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 71 | #endif // MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_ |