downsampled_render_buffer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #ifndef MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_
  12. #include <stddef.h>
  13. #include <vector>
  14. #include "rtc_base/checks.h"
  15. namespace webrtc {
  16. // Holds the circular buffer of the downsampled render data.
  17. struct DownsampledRenderBuffer {
  18. explicit DownsampledRenderBuffer(size_t downsampled_buffer_size);
  19. ~DownsampledRenderBuffer();
  20. int IncIndex(int index) const {
  21. RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
  22. return index < size - 1 ? index + 1 : 0;
  23. }
  24. int DecIndex(int index) const {
  25. RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
  26. return index > 0 ? index - 1 : size - 1;
  27. }
  28. int OffsetIndex(int index, int offset) const {
  29. RTC_DCHECK_GE(buffer.size(), offset);
  30. RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
  31. return (size + index + offset) % size;
  32. }
  33. void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); }
  34. void IncWriteIndex() { write = IncIndex(write); }
  35. void DecWriteIndex() { write = DecIndex(write); }
  36. void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); }
  37. void IncReadIndex() { read = IncIndex(read); }
  38. void DecReadIndex() { read = DecIndex(read); }
  39. const int size;
  40. std::vector<float> buffer;
  41. int write = 0;
  42. int read = 0;
  43. };
  44. } // namespace webrtc
  45. #endif // MODULES_AUDIO_PROCESSING_AEC3_DOWNSAMPLED_RENDER_BUFFER_H_