Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [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 | |
Sam Zackrisson | f3f6159 | 2019-09-05 11:30:49 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_BLOCK_BUFFER_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_BLOCK_BUFFER_H_ |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 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. |
Sam Zackrisson | f3f6159 | 2019-09-05 11:30:49 +0200 | [diff] [blame] | 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(); |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 30 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 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; |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 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; |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 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; |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 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 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 54 | const int size; |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame] | 55 | std::vector<std::vector<std::vector<std::vector<float>>>> buffer; |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 56 | int write = 0; |
| 57 | int read = 0; |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } // namespace webrtc |
| 61 | |
Sam Zackrisson | f3f6159 | 2019-09-05 11:30:49 +0200 | [diff] [blame] | 62 | #endif // MODULES_AUDIO_PROCESSING_AEC3_BLOCK_BUFFER_H_ |