blob: d4cdff34b266863b9ecc30498bf935ac8bf29587 [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_
peah522d71b2017-02-23 05:16:26 -080013
14#include <array>
peah86afe9d2017-04-06 15:45:32 -070015#include <vector>
peah522d71b2017-02-23 05:16:26 -080016
Gustaf Ullberg3646f972018-02-14 15:19:04 +010017#include "api/audio/echo_canceller3_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_processing/aec3/aec3_common.h"
Per Åhgren7ddd4632017-10-25 02:59:45 +020019#include "modules/audio_processing/aec3/aec_state.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/aec3/render_signal_analyzer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/constructormagic.h"
peah522d71b2017-02-23 05:16:26 -080022
23namespace webrtc {
peah522d71b2017-02-23 05:16:26 -080024
25class SuppressionGain {
26 public:
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020027 SuppressionGain(const EchoCanceller3Config& config,
peah8cee56f2017-08-24 22:36:53 -070028 Aec3Optimization optimization);
peah1d680892017-05-23 04:07:10 -070029 void GetGain(const std::array<float, kFftLengthBy2Plus1>& nearend,
30 const std::array<float, kFftLengthBy2Plus1>& echo,
31 const std::array<float, kFftLengthBy2Plus1>& comfort_noise,
peah14c11a42017-07-11 06:13:43 -070032 const RenderSignalAnalyzer& render_signal_analyzer,
Per Åhgren7ddd4632017-10-25 02:59:45 +020033 const AecState& aec_state,
peah86afe9d2017-04-06 15:45:32 -070034 const std::vector<std::vector<float>>& render,
peah86afe9d2017-04-06 15:45:32 -070035 float* high_bands_gain,
36 std::array<float, kFftLengthBy2Plus1>* low_band_gain);
peah522d71b2017-02-23 05:16:26 -080037
38 private:
peah1d680892017-05-23 04:07:10 -070039 void LowerBandGain(bool stationary_with_low_power,
peah14c11a42017-07-11 06:13:43 -070040 const rtc::Optional<int>& narrow_peak_band,
peah1d680892017-05-23 04:07:10 -070041 bool saturated_echo,
Per Åhgren7ddd4632017-10-25 02:59:45 +020042 bool saturating_echo_path,
Per Åhgrend980c572018-01-15 22:11:29 +010043 bool initial_state,
Per Åhgrenc65ce782017-10-09 13:01:39 +020044 bool linear_echo_estimate,
peah1d680892017-05-23 04:07:10 -070045 const std::array<float, kFftLengthBy2Plus1>& nearend,
46 const std::array<float, kFftLengthBy2Plus1>& echo,
47 const std::array<float, kFftLengthBy2Plus1>& comfort_noise,
48 std::array<float, kFftLengthBy2Plus1>* gain);
49
50 class LowNoiseRenderDetector {
51 public:
52 bool Detect(const std::vector<std::vector<float>>& render);
53
54 private:
55 float average_power_ = 32768.f * 32768.f;
56 };
57
peah522d71b2017-02-23 05:16:26 -080058 const Aec3Optimization optimization_;
peah1d680892017-05-23 04:07:10 -070059 std::array<float, kFftLengthBy2Plus1> last_gain_;
60 std::array<float, kFftLengthBy2Plus1> last_masker_;
61 std::array<float, kFftLengthBy2Plus1> gain_increase_;
62 std::array<float, kFftLengthBy2Plus1> last_echo_;
63
64 LowNoiseRenderDetector low_render_detector_;
65 size_t no_saturation_counter_ = 0;
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020066 const EchoCanceller3Config config_;
peah8cee56f2017-08-24 22:36:53 -070067 RTC_DISALLOW_COPY_AND_ASSIGN(SuppressionGain);
peah522d71b2017-02-23 05:16:26 -080068};
69
70} // namespace webrtc
71
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020072#endif // MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_