• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef MODULES_AUDIO_PROCESSING_AEC3_SPECTRUM_BUFFER_H_
12 #define MODULES_AUDIO_PROCESSING_AEC3_SPECTRUM_BUFFER_H_
13 
14 #include <stddef.h>
15 
16 #include <array>
17 #include <vector>
18 
19 #include "modules/audio_processing/aec3/aec3_common.h"
20 #include "rtc_base/checks.h"
21 
22 namespace webrtc {
23 
24 // Struct for bundling a circular buffer of one dimensional vector objects
25 // together with the read and write indices.
26 struct SpectrumBuffer {
27   SpectrumBuffer(size_t size, size_t num_channels);
28   ~SpectrumBuffer();
29 
IncIndexSpectrumBuffer30   int IncIndex(int index) const {
31     RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
32     return index < size - 1 ? index + 1 : 0;
33   }
34 
DecIndexSpectrumBuffer35   int DecIndex(int index) const {
36     RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
37     return index > 0 ? index - 1 : size - 1;
38   }
39 
OffsetIndexSpectrumBuffer40   int OffsetIndex(int index, int offset) const {
41     RTC_DCHECK_GE(size, offset);
42     RTC_DCHECK_EQ(buffer.size(), static_cast<size_t>(size));
43     RTC_DCHECK_GE(size + index + offset, 0);
44     return (size + index + offset) % size;
45   }
46 
UpdateWriteIndexSpectrumBuffer47   void UpdateWriteIndex(int offset) { write = OffsetIndex(write, offset); }
IncWriteIndexSpectrumBuffer48   void IncWriteIndex() { write = IncIndex(write); }
DecWriteIndexSpectrumBuffer49   void DecWriteIndex() { write = DecIndex(write); }
UpdateReadIndexSpectrumBuffer50   void UpdateReadIndex(int offset) { read = OffsetIndex(read, offset); }
IncReadIndexSpectrumBuffer51   void IncReadIndex() { read = IncIndex(read); }
DecReadIndexSpectrumBuffer52   void DecReadIndex() { read = DecIndex(read); }
53 
54   const int size;
55   std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>> buffer;
56   int write = 0;
57   int read = 0;
58 };
59 
60 }  // namespace webrtc
61 
62 #endif  // MODULES_AUDIO_PROCESSING_AEC3_SPECTRUM_BUFFER_H_
63