| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef MODULES_AUDIO_PROCESSING_AEC3_BLOCK_BUFFER_H_ |
| 12 |
#define MODULES_AUDIO_PROCESSING_AEC3_BLOCK_BUFFER_H_ |
| 13 |
|
| 14 |
#include <stddef.h> |
| 15 |
|
| 16 |
#include <vector> |
| 17 |
|
| 18 |
#include "rtc_base/checks.h" |
| 19 |
|
| 20 |
namespace webrtc { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
struct BlockBuffer { |
| 25 |
BlockBuffer(size_t size, |
| 26 |
size_t num_bands, |
| 27 |
size_t num_channels, |
| 28 |
size_t frame_length); |
| 29 |
~BlockBuffer(); |
| 30 |
|
| 31 |
int IncIndex(int index) const { |
| 32 |
RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size)); |
| 33 |
return index < size - 1 ? index + 1 : 0; |
| 34 |
} |
| 35 |
|
| 36 |
int DecIndex(int index) const { |
| 37 |
RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size)); |
| 38 |
return index > 0 ? index - 1 : size - 1; |
| 39 |
} |
| 40 |
|
| 41 |
int OffsetIndex(int index, int offset) const { |
| 42 |
RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size)); |
| 43 |
RTC_DCHECK_GE(size, offset); |
| 44 |
return (size + index + offset) % size; |
| 45 |
} |
| 46 |
|
| 47 |
void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); } |
| 48 |
void IncWriteIndex() { write = IncIndex(write); } |
| 49 |
void DecWriteIndex() { write = DecIndex(write); } |
| 50 |
void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); } |
| 51 |
void IncReadIndex() { read = IncIndex(read); } |
| 52 |
void DecReadIndex() { read = DecIndex(read); } |
| 53 |
|
| 54 |
const int size; |
| 55 |
std::vector<std::vector<std::vector<std::vector<float>>>> buffer; |
| 56 |
int write = 0; |
| 57 |
int read = 0; |
| 58 |
}; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
#endif |