| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_ |
| 12 |
#define MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_ |
| 13 |
|
| 14 |
#include <array> |
| 15 |
#include <memory> |
| 16 |
#include <vector> |
| 17 |
|
| 18 |
#include "absl/types/optional.h" |
| 19 |
#include "api/array_view.h" |
| 20 |
#include "api/audio/echo_canceller3_config.h" |
| 21 |
#include "modules/audio_processing/aec3/aec3_common.h" |
| 22 |
#include "modules/audio_processing/aec3/aec_state.h" |
| 23 |
#include "modules/audio_processing/aec3/fft_data.h" |
| 24 |
#include "modules/audio_processing/aec3/moving_average.h" |
| 25 |
#include "modules/audio_processing/aec3/nearend_detector.h" |
| 26 |
#include "modules/audio_processing/aec3/render_signal_analyzer.h" |
| 27 |
#include "modules/audio_processing/logging/apm_data_dumper.h" |
| 28 |
#include "rtc_base/constructor_magic.h" |
| 29 |
|
| 30 |
namespace webrtc { |
| 31 |
|
| 32 |
class SuppressionGain { |
| 33 |
public: |
| 34 |
SuppressionGain(const EchoCanceller3Config& config, |
| 35 |
Aec3Optimization optimization, |
| 36 |
int sample_rate_hz, |
| 37 |
size_t num_capture_channels); |
| 38 |
~SuppressionGain(); |
| 39 |
void GetGain( |
| 40 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> |
| 41 |
nearend_spectrum, |
| 42 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> echo_spectrum, |
| 43 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> |
| 44 |
residual_echo_spectrum, |
| 45 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> |
| 46 |
comfort_noise_spectrum, |
| 47 |
const RenderSignalAnalyzer& render_signal_analyzer, |
| 48 |
const AecState& aec_state, |
| 49 |
const std::vector<std::vector<std::vector<float>>>& render, |
| 50 |
bool clock_drift, |
| 51 |
float* high_bands_gain, |
| 52 |
std::array<float, kFftLengthBy2Plus1>* low_band_gain); |
| 53 |
|
| 54 |
bool IsDominantNearend() { |
| 55 |
return dominant_nearend_detector_->IsNearendState(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
void SetInitialState(bool state); |
| 60 |
|
| 61 |
private: |
| 62 |
|
| 63 |
float UpperBandsGain( |
| 64 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> echo_spectrum, |
| 65 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> |
| 66 |
comfort_noise_spectrum, |
| 67 |
const absl::optional<int>& narrow_peak_band, |
| 68 |
bool saturated_echo, |
| 69 |
const std::vector<std::vector<std::vector<float>>>& render, |
| 70 |
const std::array<float, kFftLengthBy2Plus1>& low_band_gain) const; |
| 71 |
|
| 72 |
void GainToNoAudibleEcho(const std::array<float, kFftLengthBy2Plus1>& nearend, |
| 73 |
const std::array<float, kFftLengthBy2Plus1>& echo, |
| 74 |
const std::array<float, kFftLengthBy2Plus1>& masker, |
| 75 |
std::array<float, kFftLengthBy2Plus1>* gain) const; |
| 76 |
|
| 77 |
void LowerBandGain( |
| 78 |
bool stationary_with_low_power, |
| 79 |
const AecState& aec_state, |
| 80 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> |
| 81 |
suppressor_input, |
| 82 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> residual_echo, |
| 83 |
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> comfort_noise, |
| 84 |
bool clock_drift, |
| 85 |
std::array<float, kFftLengthBy2Plus1>* gain); |
| 86 |
|
| 87 |
void GetMinGain(rtc::ArrayView<const float> weighted_residual_echo, |
| 88 |
rtc::ArrayView<const float> last_nearend, |
| 89 |
rtc::ArrayView<const float> last_echo, |
| 90 |
bool low_noise_render, |
| 91 |
bool saturated_echo, |
| 92 |
rtc::ArrayView<float> min_gain) const; |
| 93 |
|
| 94 |
void GetMaxGain(rtc::ArrayView<float> max_gain) const; |
| 95 |
|
| 96 |
class LowNoiseRenderDetector { |
| 97 |
public: |
| 98 |
bool Detect(const std::vector<std::vector<std::vector<float>>>& render); |
| 99 |
|
| 100 |
private: |
| 101 |
float average_power_ = 32768.f * 32768.f; |
| 102 |
}; |
| 103 |
|
| 104 |
struct GainParameters { |
| 105 |
explicit GainParameters( |
| 106 |
const EchoCanceller3Config::Suppressor::Tuning& tuning); |
| 107 |
const float max_inc_factor; |
| 108 |
const float max_dec_factor_lf; |
| 109 |
std::array<float, kFftLengthBy2Plus1> enr_transparent_; |
| 110 |
std::array<float, kFftLengthBy2Plus1> enr_suppress_; |
| 111 |
std::array<float, kFftLengthBy2Plus1> emr_transparent_; |
| 112 |
}; |
| 113 |
|
| 114 |
static int instance_count_; |
| 115 |
std::unique_ptr<ApmDataDumper> data_dumper_; |
| 116 |
const Aec3Optimization optimization_; |
| 117 |
const EchoCanceller3Config config_; |
| 118 |
const size_t num_capture_channels_; |
| 119 |
const int state_change_duration_blocks_; |
| 120 |
std::array<float, kFftLengthBy2Plus1> last_gain_; |
| 121 |
std::vector<std::array<float, kFftLengthBy2Plus1>> last_nearend_; |
| 122 |
std::vector<std::array<float, kFftLengthBy2Plus1>> last_echo_; |
| 123 |
LowNoiseRenderDetector low_render_detector_; |
| 124 |
bool initial_state_ = true; |
| 125 |
int initial_state_change_counter_ = 0; |
| 126 |
std::vector<aec3::MovingAverage> nearend_smoothers_; |
| 127 |
const GainParameters nearend_params_; |
| 128 |
const GainParameters normal_params_; |
| 129 |
std::unique_ptr<NearendDetector> dominant_nearend_detector_; |
| 130 |
|
| 131 |
RTC_DISALLOW_COPY_AND_ASSIGN(SuppressionGain); |
| 132 |
}; |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
#endif |