blob: 507c082a625c11ab33cf4a28eb93e90e355d1e0a [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_
peah522d71b2017-02-23 05:16:26 -080013
Per Åhgren8ba58612017-12-01 23:01:44 +010014#include <array>
peah522d71b2017-02-23 05:16:26 -080015#include <memory>
peah522d71b2017-02-23 05:16:26 -080016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/array_view.h"
Per Åhgren8ba58612017-12-01 23:01:44 +010018#include "modules/audio_processing/aec3/fft_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_processing/aec3/fft_data.h"
Per Åhgren8ba58612017-12-01 23:01:44 +010020#include "modules/audio_processing/aec3/matrix_buffer.h"
21#include "modules/audio_processing/aec3/vector_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/constructormagic.h"
peah522d71b2017-02-23 05:16:26 -080023
24namespace webrtc {
25
peahcf02cf12017-04-05 14:18:07 -070026// Provides a buffer of the render data for the echo remover.
27class RenderBuffer {
peah522d71b2017-02-23 05:16:26 -080028 public:
Per Åhgren8ba58612017-12-01 23:01:44 +010029 RenderBuffer(size_t num_ffts_for_spectral_sums,
30 MatrixBuffer* block_buffer,
31 VectorBuffer* spectrum_buffer,
32 FftBuffer* fft_buffer);
peahcf02cf12017-04-05 14:18:07 -070033 ~RenderBuffer();
peah522d71b2017-02-23 05:16:26 -080034
peahcf02cf12017-04-05 14:18:07 -070035 // Clears the buffer.
36 void Clear();
37
38 // Insert a block into the buffer.
Per Åhgren8ba58612017-12-01 23:01:44 +010039 void UpdateSpectralSum();
peahcf02cf12017-04-05 14:18:07 -070040
41 // Gets the last inserted block.
42 const std::vector<std::vector<float>>& MostRecentBlock() const {
Per Åhgren8ba58612017-12-01 23:01:44 +010043 return block_buffer_->buffer[block_buffer_->read];
peahcf02cf12017-04-05 14:18:07 -070044 }
peah522d71b2017-02-23 05:16:26 -080045
Per Åhgren8ba58612017-12-01 23:01:44 +010046 // Get the spectrum from one of the FFTs in the buffer.
47 rtc::ArrayView<const float> Spectrum(size_t buffer_offset_ffts) const {
48 size_t position = spectrum_buffer_->OffsetIndex(spectrum_buffer_->read,
49 buffer_offset_ffts);
50 return spectrum_buffer_->buffer[position];
peah522d71b2017-02-23 05:16:26 -080051 }
52
53 // Returns the sum of the spectrums for a certain number of FFTs.
Per Åhgren8ba58612017-12-01 23:01:44 +010054 rtc::ArrayView<const float> SpectralSum(size_t num_ffts) const {
peah522d71b2017-02-23 05:16:26 -080055 RTC_DCHECK_EQ(spectral_sums_length_, num_ffts);
Per Åhgren8ba58612017-12-01 23:01:44 +010056 return spectral_sums_;
peah522d71b2017-02-23 05:16:26 -080057 }
58
59 // Returns the circular buffer.
Per Åhgren8ba58612017-12-01 23:01:44 +010060 rtc::ArrayView<const FftData> Buffer() const { return fft_buffer_->buffer; }
peah522d71b2017-02-23 05:16:26 -080061
Per Åhgren8ba58612017-12-01 23:01:44 +010062 // Returns the current position in the circular buffer.
63 size_t Position() const { return fft_buffer_->read; }
peah522d71b2017-02-23 05:16:26 -080064
65 private:
Per Åhgren8ba58612017-12-01 23:01:44 +010066 const MatrixBuffer* const block_buffer_;
Per Åhgrenc59a5762017-12-11 21:34:19 +010067 const VectorBuffer* const spectrum_buffer_;
Per Åhgren8ba58612017-12-01 23:01:44 +010068 const FftBuffer* const fft_buffer_;
69 const size_t spectral_sums_length_;
70 std::array<float, kFftLengthBy2Plus1> spectral_sums_;
peahcf02cf12017-04-05 14:18:07 -070071 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderBuffer);
peah522d71b2017-02-23 05:16:26 -080072};
73
74} // namespace webrtc
75
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#endif // MODULES_AUDIO_PROCESSING_AEC3_RENDER_BUFFER_H_