fft_buffer.h 1.8 KB

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