blob: b267abf721e13f67214fb9493ca397c90b6f4cd6 [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_
peah522d71b2017-02-23 05:16:26 -080013
14#include <array>
15#include <algorithm>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#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"
peah522d71b2017-02-23 05:16:26 -080030
31namespace webrtc {
32
33// Proves linear echo cancellation functionality
34class Subtractor {
35 public:
Per Åhgren09a718a2017-12-11 22:28:45 +010036 Subtractor(const EchoCanceller3Config& config,
37 ApmDataDumper* data_dumper,
38 Aec3Optimization optimization);
peah522d71b2017-02-23 05:16:26 -080039 ~Subtractor();
40
41 // Performs the echo subtraction.
peahcf02cf12017-04-05 14:18:07 -070042 void Process(const RenderBuffer& render_buffer,
peah522d71b2017-02-23 05:16:26 -080043 const rtc::ArrayView<const float> capture,
44 const RenderSignalAnalyzer& render_signal_analyzer,
peah86afe9d2017-04-06 15:45:32 -070045 const AecState& aec_state,
peah522d71b2017-02-23 05:16:26 -080046 SubtractorOutput* output);
47
peah522d71b2017-02-23 05:16:26 -080048 void HandleEchoPathChange(const EchoPathVariability& echo_path_variability);
49
Per Åhgrena98c8072018-01-15 19:17:16 +010050 // Exits the initial state.
51 void ExitInitialState();
52
peah29103572017-07-11 02:54:02 -070053 // Returns the block-wise frequency response for the main adaptive filter.
peah522d71b2017-02-23 05:16:26 -080054 const std::vector<std::array<float, kFftLengthBy2Plus1>>&
55 FilterFrequencyResponse() const {
56 return main_filter_.FilterFrequencyResponse();
57 }
58
peah29103572017-07-11 02:54:02 -070059 // Returns the estimate of the impulse response for the main adaptive filter.
Per Åhgren09a718a2017-12-11 22:28:45 +010060 const std::vector<float>& FilterImpulseResponse() const {
peah29103572017-07-11 02:54:02 -070061 return main_filter_.FilterImpulseResponse();
62 }
63
Per Åhgren1b4059e2017-10-15 20:19:21 +020064 bool ConvergedFilter() const { return converged_filter_; }
65
peah522d71b2017-02-23 05:16:26 -080066 private:
peah522d71b2017-02-23 05:16:26 -080067 const Aec3Fft fft_;
68 ApmDataDumper* data_dumper_;
69 const Aec3Optimization optimization_;
Per Åhgrena98c8072018-01-15 19:17:16 +010070 const EchoCanceller3Config config_;
peah522d71b2017-02-23 05:16:26 -080071 AdaptiveFirFilter main_filter_;
72 AdaptiveFirFilter shadow_filter_;
73 MainFilterUpdateGain G_main_;
74 ShadowFilterUpdateGain G_shadow_;
Per Åhgren1b4059e2017-10-15 20:19:21 +020075 bool converged_filter_ = false;
peah522d71b2017-02-23 05:16:26 -080076 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Subtractor);
77};
78
79} // namespace webrtc
80
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020081#endif // MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_