niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 17 | |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame^] | 18 | // 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. |
| 35 | struct DelayCorrection { |
| 36 | DelayCorrection() : enabled(false) {} |
| 37 | DelayCorrection(bool enabled) : enabled(enabled) {} |
| 38 | |
| 39 | bool enabled; |
| 40 | }; |
| 41 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | class AudioProcessingImpl; |
| 43 | class AudioBuffer; |
| 44 | |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 45 | class EchoCancellationImpl : public EchoCancellationImplWrapper { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | public: |
| 47 | explicit EchoCancellationImpl(const AudioProcessingImpl* apm); |
| 48 | virtual ~EchoCancellationImpl(); |
| 49 | |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 50 | // EchoCancellationImplWrapper implementation. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 51 | virtual int ProcessRenderAudio(const AudioBuffer* audio) OVERRIDE; |
| 52 | virtual int ProcessCaptureAudio(AudioBuffer* audio) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
| 54 | // EchoCancellation implementation. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 55 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
| 59 | // ProcessingComponent implementation. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 60 | virtual int Initialize() OVERRIDE; |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame^] | 61 | virtual void SetExtraOptions(const Config& config) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | // EchoCancellation implementation. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 65 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
| 81 | // ProcessingComponent implementation. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 82 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | |
| 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.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 97 | bool delay_logging_enabled_; |
andrew@webrtc.org | 1760a17 | 2013-09-25 23:17:38 +0000 | [diff] [blame^] | 98 | bool delay_correction_enabled_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | }; |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 100 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | } // namespace webrtc |
| 102 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 103 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ |