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 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ |
| 13 | |
| 14 | #include <array> |
| 15 | #include <algorithm> |
| 16 | #include <vector> |
| 17 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/aec3/adaptive_fir_filter.h" |
| 19 | #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
| 20 | #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 21 | #include "webrtc/modules/audio_processing/aec3/aec_state.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 22 | #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 23 | #include "webrtc/modules/audio_processing/aec3/main_filter_update_gain.h" |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 24 | #include "webrtc/modules/audio_processing/aec3/render_buffer.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 25 | #include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h" |
| 26 | #include "webrtc/modules/audio_processing/aec3/subtractor_output.h" |
| 27 | #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
| 28 | #include "webrtc/modules/audio_processing/utility/ooura_fft.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 29 | #include "webrtc/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: |
| 36 | Subtractor(ApmDataDumper* data_dumper, Aec3Optimization optimization); |
| 37 | ~Subtractor(); |
| 38 | |
| 39 | // Performs the echo subtraction. |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 40 | void Process(const RenderBuffer& render_buffer, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 41 | const rtc::ArrayView<const float> capture, |
| 42 | const RenderSignalAnalyzer& render_signal_analyzer, |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 43 | const AecState& aec_state, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 44 | SubtractorOutput* output); |
| 45 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 46 | void HandleEchoPathChange(const EchoPathVariability& echo_path_variability); |
| 47 | |
peah | 2910357 | 2017-07-11 02:54:02 -0700 | [diff] [blame] | 48 | // Returns the block-wise frequency response for the main adaptive filter. |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 49 | const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
| 50 | FilterFrequencyResponse() const { |
| 51 | return main_filter_.FilterFrequencyResponse(); |
| 52 | } |
| 53 | |
peah | 2910357 | 2017-07-11 02:54:02 -0700 | [diff] [blame] | 54 | // Returns the estimate of the impulse response for the main adaptive filter. |
| 55 | const std::array<float, kAdaptiveFilterTimeDomainLength>& |
| 56 | FilterImpulseResponse() const { |
| 57 | return main_filter_.FilterImpulseResponse(); |
| 58 | } |
| 59 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 60 | private: |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 61 | const Aec3Fft fft_; |
| 62 | ApmDataDumper* data_dumper_; |
| 63 | const Aec3Optimization optimization_; |
| 64 | AdaptiveFirFilter main_filter_; |
| 65 | AdaptiveFirFilter shadow_filter_; |
| 66 | MainFilterUpdateGain G_main_; |
| 67 | ShadowFilterUpdateGain G_shadow_; |
| 68 | |
| 69 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Subtractor); |
| 70 | }; |
| 71 | |
| 72 | } // namespace webrtc |
| 73 | |
| 74 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_ |