blob: 67980bab0c1f14ef2f4057ee82868dd75bfc1bc5 [file] [log] [blame]
Per Ã…hgren8ba58612017-12-01 23:01:44 +01001/*
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_MATRIX_BUFFER_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_MATRIX_BUFFER_H_
13
14#include <vector>
15
16#include "rtc_base/checks.h"
17
18namespace webrtc {
19
20// Struct for bundling a circular buffer of two dimensional vector objects
21// together with the read and write indices.
22struct MatrixBuffer {
23 MatrixBuffer(size_t size, size_t height, size_t width);
24 ~MatrixBuffer();
25
26 size_t IncIndex(size_t index) {
27 return index < buffer.size() - 1 ? index + 1 : 0;
28 }
29
30 size_t DecIndex(size_t index) {
31 return index > 0 ? index - 1 : buffer.size() - 1;
32 }
33
34 size_t OffsetIndex(size_t index, int offset) {
35 RTC_DCHECK_GE(buffer.size(), offset);
36 return (buffer.size() + index + offset) % buffer.size();
37 }
38
39 void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); }
40 void IncWriteIndex() { write = IncIndex(write); }
41 void DecWriteIndex() { write = DecIndex(write); }
42 void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); }
43 void IncReadIndex() { read = IncIndex(read); }
44 void DecReadIndex() { read = DecIndex(read); }
45
46 size_t size;
47 std::vector<std::vector<std::vector<float>>> buffer;
48 size_t write = 0;
49 size_t read = 0;
50};
51
52} // namespace webrtc
53
54#endif // MODULES_AUDIO_PROCESSING_AEC3_MATRIX_BUFFER_H_