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 MODULES_AUDIO_PROCESSING_AEC3_COARSE_FILTER_UPDATE_GAIN_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_COARSE_FILTER_UPDATE_GAIN_H_ 13 14 #include <stddef.h> 15 16 #include <array> 17 18 #include "api/audio/echo_canceller3_config.h" 19 #include "modules/audio_processing/aec3/aec3_common.h" 20 #include "modules/audio_processing/aec3/fft_data.h" 21 #include "modules/audio_processing/aec3/render_signal_analyzer.h" 22 23 namespace webrtc { 24 25 // Provides functionality for computing the fixed gain for the coarse filter. 26 class CoarseFilterUpdateGain { 27 public: 28 explicit CoarseFilterUpdateGain( 29 const EchoCanceller3Config::Filter::CoarseConfiguration& config, 30 size_t config_change_duration_blocks); 31 32 // Takes action in the case of a known echo path change. 33 void HandleEchoPathChange(); 34 35 // Computes the gain. 36 void Compute(const std::array<float, kFftLengthBy2Plus1>& render_power, 37 const RenderSignalAnalyzer& render_signal_analyzer, 38 const FftData& E_coarse, 39 size_t size_partitions, 40 bool saturated_capture_signal, 41 FftData* G); 42 43 // Sets a new config. SetConfig(const EchoCanceller3Config::Filter::CoarseConfiguration & config,bool immediate_effect)44 void SetConfig( 45 const EchoCanceller3Config::Filter::CoarseConfiguration& config, 46 bool immediate_effect) { 47 if (immediate_effect) { 48 old_target_config_ = current_config_ = target_config_ = config; 49 config_change_counter_ = 0; 50 } else { 51 old_target_config_ = current_config_; 52 target_config_ = config; 53 config_change_counter_ = config_change_duration_blocks_; 54 } 55 } 56 57 private: 58 EchoCanceller3Config::Filter::CoarseConfiguration current_config_; 59 EchoCanceller3Config::Filter::CoarseConfiguration target_config_; 60 EchoCanceller3Config::Filter::CoarseConfiguration old_target_config_; 61 const int config_change_duration_blocks_; 62 float one_by_config_change_duration_blocks_; 63 // TODO(peah): Check whether this counter should instead be initialized to a 64 // large value. 65 size_t poor_signal_excitation_counter_ = 0; 66 size_t call_counter_ = 0; 67 int config_change_counter_ = 0; 68 69 void UpdateCurrentConfig(); 70 }; 71 72 } // namespace webrtc 73 74 #endif // MODULES_AUDIO_PROCESSING_AEC3_COARSE_FILTER_UPDATE_GAIN_H_ 75