blob: 42fbb4a623d86efffd65b1aaefc9f3d5bd2c75c5 [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_FFT_BUFFER_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_FFT_BUFFER_H_
13
14#include <vector>
15
16#include "modules/audio_processing/aec3/fft_data.h"
17#include "rtc_base/checks.h"
18
19namespace webrtc {
20
21// Struct for bundling a circular buffer of FftData objects together with the
22// read and write indices.
23struct FftBuffer {
24 explicit FftBuffer(size_t size);
25 ~FftBuffer();
26
27 size_t IncIndex(size_t index) {
28 return index < buffer.size() - 1 ? index + 1 : 0;
29 }
30
31 size_t DecIndex(size_t index) {
32 return index > 0 ? index - 1 : buffer.size() - 1;
33 }
34
35 size_t OffsetIndex(size_t index, int offset) {
36 RTC_DCHECK_GE(buffer.size(), offset);
37 return (buffer.size() + index + offset) % buffer.size();
38 }
39
40 void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); }
41 void IncWriteIndex() { write = IncIndex(write); }
42 void DecWriteIndex() { write = DecIndex(write); }
43 void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); }
44 void IncReadIndex() { read = IncIndex(read); }
45 void DecReadIndex() { read = DecIndex(read); }
46
47 std::vector<FftData> buffer;
48 size_t write = 0;
49 size_t read = 0;
50};
51
52} // namespace webrtc
53
54#endif // MODULES_AUDIO_PROCESSING_AEC3_FFT_BUFFER_H_