OLD | NEW |
| (Empty) |
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 WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_FFT_BUFFER_H_ | |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_FFT_BUFFER_H_ | |
13 | |
14 #include <memory> | |
15 #include <vector> | |
16 | |
17 #include "webrtc/base/array_view.h" | |
18 #include "webrtc/base/constructormagic.h" | |
19 #include "webrtc/modules/audio_processing/aec3/fft_data.h" | |
20 | |
21 namespace webrtc { | |
22 | |
23 // Provides a circular buffer for 128 point real-valued FFT data. | |
24 class FftBuffer { | |
25 public: | |
26 // The constructor takes as parameters the size of the buffer, as well as a | |
27 // vector containing the number of FFTs that will be included in the spectral | |
28 // sums in the call to SpectralSum. | |
29 FftBuffer(Aec3Optimization optimization, | |
30 size_t size, | |
31 const std::vector<size_t> num_ffts_for_spectral_sums); | |
32 ~FftBuffer(); | |
33 | |
34 // Insert an FFT into the buffer. | |
35 void Insert(const FftData& fft); | |
36 | |
37 // Get the spectrum from one of the FFTs in the buffer | |
38 const std::array<float, kFftLengthBy2Plus1>& Spectrum( | |
39 size_t buffer_offset_ffts) const { | |
40 return spectrum_buffer_[(position_ + buffer_offset_ffts) % | |
41 fft_buffer_.size()]; | |
42 } | |
43 | |
44 // Returns the sum of the spectrums for a certain number of FFTs. | |
45 const std::array<float, kFftLengthBy2Plus1>& SpectralSum( | |
46 size_t num_ffts) const { | |
47 RTC_DCHECK_EQ(spectral_sums_length_, num_ffts); | |
48 return spectral_sums_[0]; | |
49 } | |
50 | |
51 // Returns the circular buffer. | |
52 rtc::ArrayView<const FftData> Buffer() const { return fft_buffer_; } | |
53 | |
54 // Returns the current position in the circular buffer | |
55 size_t Position() const { return position_; } | |
56 | |
57 private: | |
58 const Aec3Optimization optimization_; | |
59 std::vector<FftData> fft_buffer_; | |
60 std::vector<std::array<float, kFftLengthBy2Plus1>> spectrum_buffer_; | |
61 size_t spectral_sums_length_; | |
62 std::vector<std::array<float, kFftLengthBy2Plus1>> spectral_sums_; | |
63 size_t position_ = 0; | |
64 | |
65 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FftBuffer); | |
66 }; | |
67 | |
68 } // namespace webrtc | |
69 | |
70 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_FFT_BUFFER_H_ | |
OLD | NEW |