blob: bc88767b93406e4daa0d6ed68a8e26a0f54f4543 [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
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
peahcf02cf12017-04-05 14:18:07 -070011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_
peah522d71b2017-02-23 05:16:26 -080013
14#include <memory>
15#include <vector>
16
kwiberg529662a2017-09-04 05:43:17 -070017#include "webrtc/api/array_view.h"
peahcf02cf12017-04-05 14:18:07 -070018#include "webrtc/modules/audio_processing/aec3/aec3_fft.h"
peah522d71b2017-02-23 05:16:26 -080019#include "webrtc/modules/audio_processing/aec3/fft_data.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020020#include "webrtc/rtc_base/constructormagic.h"
peah522d71b2017-02-23 05:16:26 -080021
22namespace webrtc {
23
peahcf02cf12017-04-05 14:18:07 -070024// Provides a buffer of the render data for the echo remover.
25class RenderBuffer {
peah522d71b2017-02-23 05:16:26 -080026 public:
peahcf02cf12017-04-05 14:18:07 -070027 // 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();
peah522d71b2017-02-23 05:16:26 -080035
peahcf02cf12017-04-05 14:18:07 -070036 // 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 }
peah522d71b2017-02-23 05:16:26 -080046
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;
peahcf02cf12017-04-05 14:18:07 -070074 std::vector<std::vector<float>> last_block_;
75 const Aec3Fft fft_;
76 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderBuffer);
peah522d71b2017-02-23 05:16:26 -080077};
78
79} // namespace webrtc
80
peahcf02cf12017-04-05 14:18:07 -070081#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_