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