blob: c774c41252da3145e918a92b48471c7e95a0bc85 [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"
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/rtc_base/constructormagic.h"
peah522d71b2017-02-23 05:16:26 -080019
20namespace webrtc {
peah522d71b2017-02-23 05:16:26 -080021
22class SuppressionGain {
23 public:
24 explicit SuppressionGain(Aec3Optimization optimization);
peah1d680892017-05-23 04:07:10 -070025 void GetGain(const std::array<float, kFftLengthBy2Plus1>& nearend,
26 const std::array<float, kFftLengthBy2Plus1>& echo,
27 const std::array<float, kFftLengthBy2Plus1>& comfort_noise,
peah86afe9d2017-04-06 15:45:32 -070028 bool saturated_echo,
29 const std::vector<std::vector<float>>& render,
peah6d822ad2017-04-10 13:52:14 -070030 bool force_zero_gain,
peah86afe9d2017-04-06 15:45:32 -070031 float* high_bands_gain,
32 std::array<float, kFftLengthBy2Plus1>* low_band_gain);
peah522d71b2017-02-23 05:16:26 -080033
34 private:
peah1d680892017-05-23 04:07:10 -070035 void LowerBandGain(bool stationary_with_low_power,
36 bool saturated_echo,
37 const std::array<float, kFftLengthBy2Plus1>& nearend,
38 const std::array<float, kFftLengthBy2Plus1>& echo,
39 const std::array<float, kFftLengthBy2Plus1>& comfort_noise,
40 std::array<float, kFftLengthBy2Plus1>* gain);
41
42 class LowNoiseRenderDetector {
43 public:
44 bool Detect(const std::vector<std::vector<float>>& render);
45
46 private:
47 float average_power_ = 32768.f * 32768.f;
48 };
49
peah522d71b2017-02-23 05:16:26 -080050 const Aec3Optimization optimization_;
peah1d680892017-05-23 04:07:10 -070051 std::array<float, kFftLengthBy2Plus1> last_gain_;
52 std::array<float, kFftLengthBy2Plus1> last_masker_;
53 std::array<float, kFftLengthBy2Plus1> gain_increase_;
54 std::array<float, kFftLengthBy2Plus1> last_echo_;
55
56 LowNoiseRenderDetector low_render_detector_;
57 size_t no_saturation_counter_ = 0;
peah522d71b2017-02-23 05:16:26 -080058 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SuppressionGain);
59};
60
61} // namespace webrtc
62
63#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_