blob: 12ae48822253932d76a4e52556d29f7f8e3acfc0 [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
peah29103572017-07-11 02:54:02 -070050 // Returns the block-wise frequency response for the main adaptive filter.
peah522d71b2017-02-23 05:16:26 -080051 const std::vector<std::array<float, kFftLengthBy2Plus1>>&
52 FilterFrequencyResponse() const {
53 return main_filter_.FilterFrequencyResponse();
54 }
55
peah29103572017-07-11 02:54:02 -070056 // Returns the estimate of the impulse response for the main adaptive filter.
Per Åhgren09a718a2017-12-11 22:28:45 +010057 const std::vector<float>& FilterImpulseResponse() const {
peah29103572017-07-11 02:54:02 -070058 return main_filter_.FilterImpulseResponse();
59 }
60
Per Åhgren1b4059e2017-10-15 20:19:21 +020061 bool ConvergedFilter() const { return converged_filter_; }
62
peah522d71b2017-02-23 05:16:26 -080063 private:
peah522d71b2017-02-23 05:16:26 -080064 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 Åhgren1b4059e2017-10-15 20:19:21 +020071 bool converged_filter_ = false;
peah522d71b2017-02-23 05:16:26 -080072 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Subtractor);
73};
74
75} // namespace webrtc
76
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020077#endif // MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_H_