peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 13 | |
| 14 | #include <array> |
| 15 | #include <algorithm> |
| 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 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" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | |
| 33 | // Proves linear echo cancellation functionality |
| 34 | class Subtractor { |
| 35 | public: |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame^] | 36 | Subtractor(const EchoCanceller3Config& config, |
| 37 | ApmDataDumper* data_dumper, |
| 38 | Aec3Optimization optimization); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 39 | ~Subtractor(); |
| 40 | |
| 41 | // Performs the echo subtraction. |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 42 | void Process(const RenderBuffer& render_buffer, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 43 | const rtc::ArrayView<const float> capture, |
| 44 | const RenderSignalAnalyzer& render_signal_analyzer, |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 45 | const AecState& aec_state, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 46 | SubtractorOutput* output); |
| 47 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 48 | void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); |
| 49 | |
peah | 2910357 | 2017-07-11 02:54:02 -0700 | [diff] [blame] | 50 | // Returns the block-wise frequency response for the main adaptive filter. |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 51 | const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
| 52 | FilterFrequencyResponse() const { |
| 53 | return main_filter_.FilterFrequencyResponse(); |
| 54 | } |
| 55 | |
peah | 2910357 | 2017-07-11 02:54:02 -0700 | [diff] [blame] | 56 | // Returns the estimate of the impulse response for the main adaptive filter. |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame^] | 57 | const std::vector<float>& FilterImpulseResponse() const { |
peah | 2910357 | 2017-07-11 02:54:02 -0700 | [diff] [blame] | 58 | return main_filter_.FilterImpulseResponse(); |
| 59 | } |
| 60 | |
Per Åhgren | 1b4059e | 2017-10-15 20:19:21 +0200 | [diff] [blame] | 61 | bool ConvergedFilter() const { return converged_filter_; } |
| 62 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 63 | private: |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 64 | const Aec3Fft fft_; |
| 65 | ApmDataDumper* data_dumper_; |
| 66 | const Aec3Optimization optimization_; |
| 67 | AdaptiveFirFilter main_filter_; |
| 68 | AdaptiveFirFilter shadow_filter_; |
| 69 | MainFilterUpdateGain G_main_; |
| 70 | ShadowFilterUpdateGain G_shadow_; |
Per Åhgren | 1b4059e | 2017-10-15 20:19:21 +0200 | [diff] [blame] | 71 | bool converged_filter_ = false; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 72 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Subtractor); |
| 73 | }; |
| 74 | |
| 75 | } // namespace webrtc |
| 76 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 77 | #endif // MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ |