peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_ |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 13 | |
Per Åhgren | 38e2d95 | 2017-11-17 14:54:28 +0100 | [diff] [blame] | 14 | #include <vector> |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/audio_processing/aec3/aec3_common.h" |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame^] | 17 | #include "rtc_base/checks.h" |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // Holds the circular buffer of the downsampled render data. |
| 22 | struct DownsampledRenderBuffer { |
Per Åhgren | 38e2d95 | 2017-11-17 14:54:28 +0100 | [diff] [blame] | 23 | explicit DownsampledRenderBuffer(size_t downsampled_buffer_size); |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 24 | ~DownsampledRenderBuffer(); |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame^] | 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; |
Per Åhgren | 38e2d95 | 2017-11-17 14:54:28 +0100 | [diff] [blame] | 47 | std::vector<float> buffer; |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame^] | 48 | int write = 0; |
| 49 | int read = 0; |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | } // namespace webrtc |
| 53 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 54 | #endif // MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_ |