blob: 2b57ebb50812be9ee90a6d7894c1c7dafc313859 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +000011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000014#include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
16namespace webrtc {
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000017
andrew@webrtc.org1760a172013-09-25 23:17:38 +000018// Use to enable the delay correction feature. This now engages an extended
19// filter mode in the AEC, along with robustness measures around the reported
20// system delays. It comes with a significant increase in AEC complexity, but is
21// much more robust to unreliable reported delays.
22//
23// Detailed changes to the algorithm:
24// - The filter length is changed from 48 to 128 ms. This comes with tuning of
25// several parameters: i) filter adaptation stepsize and error threshold;
26// ii) non-linear processing smoothing and overdrive.
27// - Option to ignore the reported delays on platforms which we deem
28// sufficiently unreliable. See WEBRTC_UNTRUSTED_DELAY in echo_cancellation.c.
29// - Faster startup times by removing the excessive "startup phase" processing
30// of reported delays.
31// - Much more conservative adjustments to the far-end read pointer. We smooth
32// the delay difference more heavily, and back off from the difference more.
33// Adjustments force a readaptation of the filter, so they should be avoided
34// except when really necessary.
35struct DelayCorrection {
36 DelayCorrection() : enabled(false) {}
37 DelayCorrection(bool enabled) : enabled(enabled) {}
38
39 bool enabled;
40};
41
niklase@google.com470e71d2011-07-07 08:21:25 +000042class AudioProcessingImpl;
43class AudioBuffer;
44
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000045class EchoCancellationImpl : public EchoCancellationImplWrapper {
niklase@google.com470e71d2011-07-07 08:21:25 +000046 public:
47 explicit EchoCancellationImpl(const AudioProcessingImpl* apm);
48 virtual ~EchoCancellationImpl();
49
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000050 // EchoCancellationImplWrapper implementation.
pbos@webrtc.org91620802013-08-02 11:44:11 +000051 virtual int ProcessRenderAudio(const AudioBuffer* audio) OVERRIDE;
52 virtual int ProcessCaptureAudio(AudioBuffer* audio) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
54 // EchoCancellation implementation.
pbos@webrtc.org91620802013-08-02 11:44:11 +000055 virtual bool is_enabled() const OVERRIDE;
56 virtual int device_sample_rate_hz() const OVERRIDE;
57 virtual int stream_drift_samples() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59 // ProcessingComponent implementation.
pbos@webrtc.org91620802013-08-02 11:44:11 +000060 virtual int Initialize() OVERRIDE;
andrew@webrtc.org1760a172013-09-25 23:17:38 +000061 virtual void SetExtraOptions(const Config& config) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
63 private:
64 // EchoCancellation implementation.
pbos@webrtc.org91620802013-08-02 11:44:11 +000065 virtual int Enable(bool enable) OVERRIDE;
66 virtual int enable_drift_compensation(bool enable) OVERRIDE;
67 virtual bool is_drift_compensation_enabled() const OVERRIDE;
68 virtual int set_device_sample_rate_hz(int rate) OVERRIDE;
69 virtual void set_stream_drift_samples(int drift) OVERRIDE;
70 virtual int set_suppression_level(SuppressionLevel level) OVERRIDE;
71 virtual SuppressionLevel suppression_level() const OVERRIDE;
72 virtual int enable_metrics(bool enable) OVERRIDE;
73 virtual bool are_metrics_enabled() const OVERRIDE;
74 virtual bool stream_has_echo() const OVERRIDE;
75 virtual int GetMetrics(Metrics* metrics) OVERRIDE;
76 virtual int enable_delay_logging(bool enable) OVERRIDE;
77 virtual bool is_delay_logging_enabled() const OVERRIDE;
78 virtual int GetDelayMetrics(int* median, int* std) OVERRIDE;
79 virtual struct AecCore* aec_core() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
81 // ProcessingComponent implementation.
pbos@webrtc.org91620802013-08-02 11:44:11 +000082 virtual void* CreateHandle() const OVERRIDE;
83 virtual int InitializeHandle(void* handle) const OVERRIDE;
84 virtual int ConfigureHandle(void* handle) const OVERRIDE;
85 virtual int DestroyHandle(void* handle) const OVERRIDE;
86 virtual int num_handles_required() const OVERRIDE;
87 virtual int GetHandleError(void* handle) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
89 const AudioProcessingImpl* apm_;
90 bool drift_compensation_enabled_;
91 bool metrics_enabled_;
92 SuppressionLevel suppression_level_;
93 int device_sample_rate_hz_;
94 int stream_drift_samples_;
95 bool was_stream_drift_set_;
96 bool stream_has_echo_;
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +000097 bool delay_logging_enabled_;
andrew@webrtc.org1760a172013-09-25 23:17:38 +000098 bool delay_correction_enabled_;
niklase@google.com470e71d2011-07-07 08:21:25 +000099};
andrew@webrtc.org61e596f2013-07-25 18:28:29 +0000100
niklase@google.com470e71d2011-07-07 08:21:25 +0000101} // namespace webrtc
102
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +0000103#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_