Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: webrtc/modules/audio_processing/aec3/render_buffer.cc

Issue 2784023002: Major AEC3 render pipeline changes (Closed)
Patch Set: Disabled one more DEATH test that caused issues due to bug on bots Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_processing/aec3/fft_buffer.h" 11 #include "webrtc/modules/audio_processing/aec3/render_buffer.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" 16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 FftBuffer::FftBuffer(Aec3Optimization optimization, 20 RenderBuffer::RenderBuffer(Aec3Optimization optimization,
21 size_t num_partitions, 21 size_t num_bands,
22 const std::vector<size_t> num_ffts_for_spectral_sums) 22 size_t num_partitions,
23 const std::vector<size_t> num_ffts_for_spectral_sums)
23 : optimization_(optimization), 24 : optimization_(optimization),
24 fft_buffer_(num_partitions), 25 fft_buffer_(num_partitions),
25 spectrum_buffer_(num_partitions, std::array<float, kFftLengthBy2Plus1>()), 26 spectrum_buffer_(num_partitions, std::array<float, kFftLengthBy2Plus1>()),
26 spectral_sums_(num_ffts_for_spectral_sums.size(), 27 spectral_sums_(num_ffts_for_spectral_sums.size(),
27 std::array<float, kFftLengthBy2Plus1>()) { 28 std::array<float, kFftLengthBy2Plus1>()),
29 last_block_(num_bands, std::vector<float>(kBlockSize, 0.f)) {
28 // Current implementation only allows a maximum of one spectral sum lengths. 30 // Current implementation only allows a maximum of one spectral sum lengths.
29 RTC_DCHECK_EQ(1, num_ffts_for_spectral_sums.size()); 31 RTC_DCHECK_EQ(1, num_ffts_for_spectral_sums.size());
30 spectral_sums_length_ = num_ffts_for_spectral_sums[0]; 32 spectral_sums_length_ = num_ffts_for_spectral_sums[0];
31 RTC_DCHECK_GE(fft_buffer_.size(), spectral_sums_length_); 33 RTC_DCHECK_GE(fft_buffer_.size(), spectral_sums_length_);
32 34
35 Clear();
36 }
37
38 RenderBuffer::~RenderBuffer() = default;
39
40 void RenderBuffer::Clear() {
41 position_ = 0;
33 for (auto& sum : spectral_sums_) { 42 for (auto& sum : spectral_sums_) {
34 sum.fill(0.f); 43 sum.fill(0.f);
35 } 44 }
36 45
37 for (auto& spectrum : spectrum_buffer_) { 46 for (auto& spectrum : spectrum_buffer_) {
38 spectrum.fill(0.f); 47 spectrum.fill(0.f);
39 } 48 }
40 49
41 for (auto& fft : fft_buffer_) { 50 for (auto& fft : fft_buffer_) {
42 fft.Clear(); 51 fft.Clear();
43 } 52 }
53
54 for (auto& b : last_block_) {
55 std::fill(b.begin(), b.end(), 0.f);
56 }
44 } 57 }
45 58
46 FftBuffer::~FftBuffer() = default; 59 void RenderBuffer::Insert(const std::vector<std::vector<float>>& block) {
60 // Compute the FFT of the data in the lowest band.
61 FftData X;
62 fft_.PaddedFft(block[0], last_block_[0], &X);
47 63
48 void FftBuffer::Insert(const FftData& fft) { 64 // Copy the last render frame.
49 // Insert the fft into the buffer. 65 RTC_DCHECK_EQ(last_block_.size(), block.size());
50 position_ = (position_ - 1 + fft_buffer_.size()) % fft_buffer_.size(); 66 for (size_t k = 0; k < block.size(); ++k) {
51 fft_buffer_[position_].Assign(fft); 67 RTC_DCHECK_EQ(last_block_[k].size(), block[k].size());
68 std::copy(block[k].begin(), block[k].end(), last_block_[k].begin());
69 }
70
71 // Insert X into the buffer.
72 position_ = position_ > 0 ? position_ - 1 : fft_buffer_.size() - 1;
73 fft_buffer_[position_].Assign(X);
52 74
53 // Compute and insert the spectrum for the FFT into the spectrum buffer. 75 // Compute and insert the spectrum for the FFT into the spectrum buffer.
54 fft.Spectrum(optimization_, &spectrum_buffer_[position_]); 76 X.Spectrum(optimization_, &spectrum_buffer_[position_]);
55 77
56 // Pre-compute and cachec the spectral sums. 78 // Pre-compute and cache the spectral sums.
57 std::copy(spectrum_buffer_[position_].begin(), 79 std::copy(spectrum_buffer_[position_].begin(),
58 spectrum_buffer_[position_].end(), spectral_sums_[0].begin()); 80 spectrum_buffer_[position_].end(), spectral_sums_[0].begin());
59 size_t position = (position_ + 1) % fft_buffer_.size(); 81 size_t position = (position_ + 1) % fft_buffer_.size();
60 for (size_t j = 1; j < spectral_sums_length_; ++j) { 82 for (size_t j = 1; j < spectral_sums_length_; ++j) {
61 const std::array<float, kFftLengthBy2Plus1>& spectrum = 83 const std::array<float, kFftLengthBy2Plus1>& spectrum =
62 spectrum_buffer_[position]; 84 spectrum_buffer_[position];
63 85
64 for (size_t k = 0; k < spectral_sums_[0].size(); ++k) { 86 for (size_t k = 0; k < spectral_sums_[0].size(); ++k) {
65 spectral_sums_[0][k] += spectrum[k]; 87 spectral_sums_[0][k] += spectrum[k];
66 } 88 }
67 89
68 position = position < (fft_buffer_.size() - 1) ? position + 1 : 0; 90 position = position < (fft_buffer_.size() - 1) ? position + 1 : 0;
69 } 91 }
70 } 92 }
71 93
72 } // namespace webrtc 94 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec3/render_buffer.h ('k') | webrtc/modules/audio_processing/aec3/render_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698