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 
11 #ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
12 #define MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
13 
14 #include <stddef.h>
15 #include <array>
16 #include <vector>
17 
18 #include "api/array_view.h"
19 #include "modules/audio_processing/aec3/aec3_common.h"
20 #include "modules/audio_processing/aec3/downsampled_render_buffer.h"
21 #include "modules/audio_processing/aec3/fft_data.h"
22 #include "modules/audio_processing/aec3/render_buffer.h"
23 
24 namespace webrtc {
25 
26 // Class for buffering the incoming render blocks such that these may be
27 // extracted with a specified delay.
28 class RenderDelayBuffer {
29  public:
30   static RenderDelayBuffer* Create(size_t num_bands,
31                                    size_t down_sampling_factor,
32                                    size_t downsampled_render_buffer_size,
33                                    size_t render_delay_buffer_size);
34   virtual ~RenderDelayBuffer() = default;
35 
36   // Resets the buffer data.
37   virtual void Reset() = 0;
38 
39   // Inserts a block into the buffer and returns true if the insert is
40   // successful.
41   virtual bool Insert(const std::vector<std::vector<float>>& block) = 0;
42 
43   // Updates the buffers one step based on the specified buffer delay. Returns
44   // true if there was no overrun, otherwise returns false.
45   virtual bool UpdateBuffers() = 0;
46 
47   // Sets the buffer delay.
48   virtual void SetDelay(size_t delay) = 0;
49 
50   // Gets the buffer delay.
51   virtual size_t Delay() const = 0;
52 
53   // Returns the render buffer for the echo remover.
54   virtual const RenderBuffer& GetRenderBuffer() const = 0;
55 
56   // Returns the downsampled render buffer.
57   virtual const DownsampledRenderBuffer& GetDownsampledRenderBuffer() const = 0;
58 };
59 
60 }  // namespace webrtc
61 
62 #endif  // MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_BUFFER_H_
63