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_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 // Struct for bundling a circular buffer of two dimensional vector objects 23 // together with the read and write indices. 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 IncIndexBlockBuffer31 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 DecIndexBlockBuffer36 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 OffsetIndexBlockBuffer41 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 UpdateWriteIndexBlockBuffer47 void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); } IncWriteIndexBlockBuffer48 void IncWriteIndex() { write = IncIndex(write); } DecWriteIndexBlockBuffer49 void DecWriteIndex() { write = DecIndex(write); } UpdateReadIndexBlockBuffer50 void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); } IncReadIndexBlockBuffer51 void IncReadIndex() { read = IncIndex(read); } DecReadIndexBlockBuffer52 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 } // namespace webrtc 61 62 #endif // MODULES_AUDIO_PROCESSING_AEC3_BLOCK_BUFFER_H_ 63