peah | 522d71b | 2017-02-23 05:16:26 -0800 | [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 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_ |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 17 | #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/aec3/fft_data.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame^] | 19 | #include "webrtc/rtc_base/array_view.h" |
| 20 | #include "webrtc/rtc_base/constructormagic.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 24 | // Provides a buffer of the render data for the echo remover. |
| 25 | class RenderBuffer { |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 26 | public: |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 27 | // The constructor takes, besides from the other parameters, a vector |
| 28 | // containing the number of FFTs that will be included in the spectral sums in |
| 29 | // the call to SpectralSum. |
| 30 | RenderBuffer(Aec3Optimization optimization, |
| 31 | size_t num_bands, |
| 32 | size_t size, |
| 33 | const std::vector<size_t> num_ffts_for_spectral_sums); |
| 34 | ~RenderBuffer(); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 35 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 36 | // Clears the buffer. |
| 37 | void Clear(); |
| 38 | |
| 39 | // Insert a block into the buffer. |
| 40 | void Insert(const std::vector<std::vector<float>>& block); |
| 41 | |
| 42 | // Gets the last inserted block. |
| 43 | const std::vector<std::vector<float>>& MostRecentBlock() const { |
| 44 | return last_block_; |
| 45 | } |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 46 | |
| 47 | // Get the spectrum from one of the FFTs in the buffer |
| 48 | const std::array<float, kFftLengthBy2Plus1>& Spectrum( |
| 49 | size_t buffer_offset_ffts) const { |
| 50 | return spectrum_buffer_[(position_ + buffer_offset_ffts) % |
| 51 | fft_buffer_.size()]; |
| 52 | } |
| 53 | |
| 54 | // Returns the sum of the spectrums for a certain number of FFTs. |
| 55 | const std::array<float, kFftLengthBy2Plus1>& SpectralSum( |
| 56 | size_t num_ffts) const { |
| 57 | RTC_DCHECK_EQ(spectral_sums_length_, num_ffts); |
| 58 | return spectral_sums_[0]; |
| 59 | } |
| 60 | |
| 61 | // Returns the circular buffer. |
| 62 | rtc::ArrayView<const FftData> Buffer() const { return fft_buffer_; } |
| 63 | |
| 64 | // Returns the current position in the circular buffer |
| 65 | size_t Position() const { return position_; } |
| 66 | |
| 67 | private: |
| 68 | const Aec3Optimization optimization_; |
| 69 | std::vector<FftData> fft_buffer_; |
| 70 | std::vector<std::array<float, kFftLengthBy2Plus1>> spectrum_buffer_; |
| 71 | size_t spectral_sums_length_; |
| 72 | std::vector<std::array<float, kFftLengthBy2Plus1>> spectral_sums_; |
| 73 | size_t position_ = 0; |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 74 | std::vector<std::vector<float>> last_block_; |
| 75 | const Aec3Fft fft_; |
| 76 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderBuffer); |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace webrtc |
| 80 | |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 81 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_ |