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_SUBTRACTOR_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ 13 14 #include <array> 15 #include <algorithm> 16 #include <vector> 17 18 #include "modules/audio_processing/aec3/adaptive_fir_filter.h" 19 #include "modules/audio_processing/aec3/aec3_common.h" 20 #include "modules/audio_processing/aec3/aec3_fft.h" 21 #include "modules/audio_processing/aec3/aec_state.h" 22 #include "modules/audio_processing/aec3/echo_path_variability.h" 23 #include "modules/audio_processing/aec3/main_filter_update_gain.h" 24 #include "modules/audio_processing/aec3/render_buffer.h" 25 #include "modules/audio_processing/aec3/shadow_filter_update_gain.h" 26 #include "modules/audio_processing/aec3/subtractor_output.h" 27 #include "modules/audio_processing/logging/apm_data_dumper.h" 28 #include "modules/audio_processing/utility/ooura_fft.h" 29 #include "rtc_base/constructormagic.h" 30 31 namespace webrtc { 32 33 // Proves linear echo cancellation functionality 34 class Subtractor { 35 public: 36 Subtractor(ApmDataDumper* data_dumper, Aec3Optimization optimization); 37 ~Subtractor(); 38 39 // Performs the echo subtraction. 40 void Process(const RenderBuffer& render_buffer, 41 const rtc::ArrayView<const float> capture, 42 const RenderSignalAnalyzer& render_signal_analyzer, 43 const AecState& aec_state, 44 SubtractorOutput* output); 45 46 void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); 47 48 // Returns the block-wise frequency response for the main adaptive filter. 49 const std::vector<std::array<float, kFftLengthBy2Plus1>>& FilterFrequencyResponse()50 FilterFrequencyResponse() const { 51 return main_filter_.FilterFrequencyResponse(); 52 } 53 54 // Returns the estimate of the impulse response for the main adaptive filter. 55 const std::array<float, kAdaptiveFilterTimeDomainLength>& FilterImpulseResponse()56 FilterImpulseResponse() const { 57 return main_filter_.FilterImpulseResponse(); 58 } 59 ConvergedFilter()60 bool ConvergedFilter() const { return converged_filter_; } 61 62 private: 63 const Aec3Fft fft_; 64 ApmDataDumper* data_dumper_; 65 const Aec3Optimization optimization_; 66 AdaptiveFirFilter main_filter_; 67 AdaptiveFirFilter shadow_filter_; 68 MainFilterUpdateGain G_main_; 69 ShadowFilterUpdateGain G_shadow_; 70 bool converged_filter_ = false; 71 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Subtractor); 72 }; 73 74 } // namespace webrtc 75 76 #endif // MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ 77