Gustaf Ullberg | 8e467df | 2018-02-05 14:39:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | |
Gustaf Ullberg | fd4ce50 | 2018-02-15 10:09:09 +0100 | [diff] [blame] | 11 | #ifndef API_AUDIO_ECHO_CONTROL_H_ |
| 12 | #define API_AUDIO_ECHO_CONTROL_H_ |
Gustaf Ullberg | 8e467df | 2018-02-05 14:39:38 +0100 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | |
Per Åhgren | 4e5c709 | 2019-11-01 20:44:11 +0100 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
| 17 | |
Gustaf Ullberg | 8e467df | 2018-02-05 14:39:38 +0100 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | |
| 20 | class AudioBuffer; |
| 21 | |
| 22 | // Interface for an acoustic echo cancellation (AEC) submodule. |
| 23 | class EchoControl { |
| 24 | public: |
| 25 | // Analysis (not changing) of the render signal. |
| 26 | virtual void AnalyzeRender(AudioBuffer* render) = 0; |
| 27 | |
| 28 | // Analysis (not changing) of the capture signal. |
| 29 | virtual void AnalyzeCapture(AudioBuffer* capture) = 0; |
| 30 | |
| 31 | // Processes the capture signal in order to remove the echo. |
| 32 | virtual void ProcessCapture(AudioBuffer* capture, bool echo_path_change) = 0; |
| 33 | |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame^] | 34 | // As above, but also returns the linear filter output. |
| 35 | // TODO(peah): Make pure virtual. |
| 36 | virtual void ProcessCapture(AudioBuffer* capture, |
| 37 | AudioBuffer* linear_output, |
| 38 | bool level_change) {} |
| 39 | |
Gustaf Ullberg | 8e467df | 2018-02-05 14:39:38 +0100 | [diff] [blame] | 40 | struct Metrics { |
| 41 | double echo_return_loss; |
| 42 | double echo_return_loss_enhancement; |
| 43 | int delay_ms; |
| 44 | }; |
| 45 | |
| 46 | // Collect current metrics from the echo controller. |
| 47 | virtual Metrics GetMetrics() const = 0; |
| 48 | |
Per Åhgren | d0fa820 | 2018-04-18 09:35:13 +0200 | [diff] [blame] | 49 | // Provides an optional external estimate of the audio buffer delay. |
Gustaf Ullberg | b394a56 | 2019-10-25 09:40:50 +0200 | [diff] [blame] | 50 | virtual void SetAudioBufferDelay(int delay_ms) = 0; |
Per Åhgren | d0fa820 | 2018-04-18 09:35:13 +0200 | [diff] [blame] | 51 | |
Gustaf Ullberg | 8675eee | 2019-10-09 13:34:36 +0200 | [diff] [blame] | 52 | // Returns wheter the signal is altered. |
| 53 | virtual bool ActiveProcessing() const = 0; |
| 54 | |
Gustaf Ullberg | 8e467df | 2018-02-05 14:39:38 +0100 | [diff] [blame] | 55 | virtual ~EchoControl() {} |
| 56 | }; |
| 57 | |
| 58 | // Interface for a factory that creates EchoControllers. |
| 59 | class EchoControlFactory { |
| 60 | public: |
Per Åhgren | 4e5c709 | 2019-11-01 20:44:11 +0100 | [diff] [blame] | 61 | virtual std::unique_ptr<EchoControl> Create(int sample_rate_hz, |
| 62 | int num_render_channels, |
Gustaf Ullberg | 2c6f373 | 2019-11-07 17:15:12 +0100 | [diff] [blame] | 63 | int num_capture_channels) = 0; |
Per Åhgren | 4e5c709 | 2019-11-01 20:44:11 +0100 | [diff] [blame] | 64 | |
Gustaf Ullberg | 8e467df | 2018-02-05 14:39:38 +0100 | [diff] [blame] | 65 | virtual ~EchoControlFactory() = default; |
| 66 | }; |
| 67 | } // namespace webrtc |
| 68 | |
Gustaf Ullberg | fd4ce50 | 2018-02-15 10:09:09 +0100 | [diff] [blame] | 69 | #endif // API_AUDIO_ECHO_CONTROL_H_ |