peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_ |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 13 | |
| 14 | #include <stddef.h> |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 15 | #include <array> |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/array_view.h" |
Gustaf Ullberg | 3646f97 | 2018-02-14 15:19:04 +0100 | [diff] [blame] | 19 | #include "api/audio/echo_canceller3_config.h" |
| 20 | #include "api/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/aec3/aec3_common.h" |
| 22 | #include "modules/audio_processing/aec3/downsampled_render_buffer.h" |
| 23 | #include "modules/audio_processing/aec3/fft_data.h" |
| 24 | #include "modules/audio_processing/aec3/render_buffer.h" |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 25 | |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 26 | namespace webrtc { |
| 27 | |
| 28 | // Class for buffering the incoming render blocks such that these may be |
| 29 | // extracted with a specified delay. |
| 30 | class RenderDelayBuffer { |
| 31 | public: |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 32 | enum class BufferingEvent { |
| 33 | kNone, |
| 34 | kRenderUnderrun, |
| 35 | kRenderOverrun, |
| 36 | kApiCallSkew, |
| 37 | kRenderDataLost |
| 38 | }; |
| 39 | |
| 40 | static RenderDelayBuffer* Create(const EchoCanceller3Config& config, |
| 41 | size_t num_bands); |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 42 | virtual ~RenderDelayBuffer() = default; |
| 43 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 44 | // Resets the buffer alignment. |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 45 | virtual void Reset() = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 46 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 47 | // Inserts a block into the buffer. |
| 48 | virtual BufferingEvent Insert( |
| 49 | const std::vector<std::vector<float>>& block) = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 50 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 51 | // Updates the buffers one step based on the specified buffer delay. Returns |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 52 | // an enum indicating whether there was a special event that occurred. |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 53 | virtual BufferingEvent PrepareCaptureProcessing() = 0; |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 54 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 55 | // Sets the buffer delay and returns a bool indicating whether the delay |
| 56 | // changed. |
| 57 | virtual bool SetDelay(size_t delay) = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 58 | |
| 59 | // Gets the buffer delay. |
Per Åhgren | 5c532d3 | 2018-03-22 00:29:25 +0100 | [diff] [blame] | 60 | virtual size_t Delay() const = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 61 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 62 | // Gets the buffer delay. |
| 63 | virtual size_t MaxDelay() const = 0; |
| 64 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 65 | // Returns the render buffer for the echo remover. |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 66 | virtual RenderBuffer* GetRenderBuffer() = 0; |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 67 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 68 | // Returns the downsampled render buffer. |
| 69 | virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0; |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 70 | |
| 71 | // Returns whether the current delay is noncausal. |
Per Åhgren | a76ef9d | 2018-01-25 07:01:34 +0100 | [diff] [blame] | 72 | virtual bool CausalDelay(size_t delay) const = 0; |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 73 | |
| 74 | // Returns the maximum non calusal offset that can occur in the delay buffer. |
| 75 | static int DelayEstimatorOffset(const EchoCanceller3Config& config); |
peah | 69221db | 2017-01-27 03:28:19 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace webrtc |
| 79 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 80 | #endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_ |