blob: c91ea3b836f60e85273b94abb68108efbf452746 [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Per Åhgren38e2d952017-11-17 14:54:28 +010015#include <vector>
peahcf02cf12017-04-05 14:18:07 -070016
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
Per Åhgrenc59a5762017-12-11 21:34:19 +010026 int IncIndex(int index) const {
27 RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
28 return index < size - 1 ? index + 1 : 0;
Per Åhgren8ba58612017-12-01 23:01:44 +010029 }
30
Per Åhgrenc59a5762017-12-11 21:34:19 +010031 int DecIndex(int index) const {
32 RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
33 return index > 0 ? index - 1 : size - 1;
Per Åhgren8ba58612017-12-01 23:01:44 +010034 }
35
Per Åhgrenc59a5762017-12-11 21:34:19 +010036 int OffsetIndex(int index, int offset) const {
Per Åhgren8ba58612017-12-01 23:01:44 +010037 RTC_DCHECK_GE(buffer.size(), offset);
Per Åhgrenc59a5762017-12-11 21:34:19 +010038 RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
39 return (size + index + offset) % size;
Per Åhgren8ba58612017-12-01 23:01:44 +010040 }
41
42 void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); }
43 void IncWriteIndex() { write = IncIndex(write); }
44 void DecWriteIndex() { write = DecIndex(write); }
45 void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); }
46 void IncReadIndex() { read = IncIndex(read); }
47 void DecReadIndex() { read = DecIndex(read); }
48
Per Åhgrenc59a5762017-12-11 21:34:19 +010049 const int size;
Per Åhgren38e2d952017-11-17 14:54:28 +010050 std::vector<float> buffer;
Per Åhgren8ba58612017-12-01 23:01:44 +010051 int write = 0;
52 int read = 0;
peahcf02cf12017-04-05 14:18:07 -070053};
54
55} // namespace webrtc
56
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020057#endif // MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_