blob: c656846960c2aceecc4ef36dd333e57070a38cd7 [file] [log] [blame]
peahcf02cf12017-04-05 14:18:07 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_
peahcf02cf12017-04-05 14:18:07 -070013
Per Åhgren38e2d952017-11-17 14:54:28 +010014#include <vector>
peahcf02cf12017-04-05 14:18:07 -070015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_processing/aec3/aec3_common.h"
Per Åhgren8ba58612017-12-01 23:01:44 +010017#include "rtc_base/checks.h"
peahcf02cf12017-04-05 14:18:07 -070018
19namespace webrtc {
20
21// Holds the circular buffer of the downsampled render data.
22struct DownsampledRenderBuffer {
Per Åhgren38e2d952017-11-17 14:54:28 +010023 explicit DownsampledRenderBuffer(size_t downsampled_buffer_size);
peahcf02cf12017-04-05 14:18:07 -070024 ~DownsampledRenderBuffer();
Per Åhgren8ba58612017-12-01 23:01:44 +010025
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;
Per Åhgren38e2d952017-11-17 14:54:28 +010047 std::vector<float> buffer;
Per Åhgren8ba58612017-12-01 23:01:44 +010048 int write = 0;
49 int read = 0;
peahcf02cf12017-04-05 14:18:07 -070050};
51
52} // namespace webrtc
53
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#endif // MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_