blob: d22eb8a5232c16e6701bb0dce12abfca24261640 [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
11#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_
13
14#include <array>
peah86afe9d2017-04-06 15:45:32 -070015#include <vector>
peah522d71b2017-02-23 05:16:26 -080016
peah522d71b2017-02-23 05:16:26 -080017#include "webrtc/modules/audio_processing/aec3/aec3_common.h"
peah14c11a42017-07-11 06:13:43 -070018#include "webrtc/modules/audio_processing/aec3/render_signal_analyzer.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020019#include "webrtc/rtc_base/constructormagic.h"
peah522d71b2017-02-23 05:16:26 -080020
21namespace webrtc {
peah522d71b2017-02-23 05:16:26 -080022
23class SuppressionGain {
24 public:
25 explicit SuppressionGain(Aec3Optimization optimization);
peah1d680892017-05-23 04:07:10 -070026 void GetGain(const std::array<float, kFftLengthBy2Plus1>& nearend,
27 const std::array<float, kFftLengthBy2Plus1>& echo,
28 const std::array<float, kFftLengthBy2Plus1>& comfort_noise,
peah14c11a42017-07-11 06:13:43 -070029 const RenderSignalAnalyzer& render_signal_analyzer,
peah86afe9d2017-04-06 15:45:32 -070030 bool saturated_echo,
31 const std::vector<std::vector<float>>& render,
peah6d822ad2017-04-10 13:52:14 -070032 bool force_zero_gain,
peah86afe9d2017-04-06 15:45:32 -070033 float* high_bands_gain,
34 std::array<float, kFftLengthBy2Plus1>* low_band_gain);
peah522d71b2017-02-23 05:16:26 -080035
36 private:
peah1d680892017-05-23 04:07:10 -070037 void LowerBandGain(bool stationary_with_low_power,
peah14c11a42017-07-11 06:13:43 -070038 const rtc::Optional<int>& narrow_peak_band,
peah1d680892017-05-23 04:07:10 -070039 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
peah522d71b2017-02-23 05:16:26 -080053 const Aec3Optimization optimization_;
peah1d680892017-05-23 04:07:10 -070054 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;
peah522d71b2017-02-23 05:16:26 -080061 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SuppressionGain);
62};
63
64} // namespace webrtc
65
66#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_