Chromium Code Reviews| 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 #include "webrtc/modules/audio_processing/aec3/fft_buffer.h" | |
| 12 | |
| 13 #include <algorithm> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | |
| 17 | |
| 18 namespace webrtc { | |
| 19 | |
| 20 FftBuffer::FftBuffer(Aec3Optimization optimization, | |
| 21 size_t num_partitions, | |
| 22 const std::vector<size_t> num_ffts_for_spectral_sums) | |
| 23 : optimization_(optimization), | |
| 24 fft_buffer_(num_partitions), | |
| 25 spectrum_buffer_(num_partitions, std::array<float, kFftLengthBy2Plus1>()), | |
| 26 spectral_sums_(num_ffts_for_spectral_sums.size(), | |
| 27 std::array<float, kFftLengthBy2Plus1>()) { | |
| 28 // Current implementation only allows a maximum of one spectral sum lengths. | |
| 29 RTC_DCHECK_EQ(1, num_ffts_for_spectral_sums.size()); | |
| 30 spectral_sums_length_ = num_ffts_for_spectral_sums[0]; | |
| 31 RTC_DCHECK_GE(fft_buffer_.size(), spectral_sums_length_); | |
| 32 | |
| 33 for (auto& sum : spectral_sums_) { | |
| 34 sum.fill(0.f); | |
| 35 } | |
| 36 | |
| 37 for (auto& spectrum : spectrum_buffer_) { | |
| 38 spectrum.fill(0.f); | |
| 39 } | |
| 40 | |
| 41 for (auto& fft : fft_buffer_) { | |
| 42 fft.Clear(); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 FftBuffer::~FftBuffer() = default; | |
| 47 | |
| 48 void FftBuffer::Insert(const FftData& fft) { | |
| 49 // Insert the fft into the buffer. | |
| 50 position_ = (position_ - 1 + fft_buffer_.size()) % fft_buffer_.size(); | |
| 51 fft_buffer_[position_].Assign(fft); | |
| 52 | |
| 53 // Compute and insert the spectrum for the FFT into the spectrum buffer. | |
| 54 fft.Spectrum(optimization_, &spectrum_buffer_[position_]); | |
| 55 | |
| 56 // Pre-compute and cachec the spectral sums. | |
|
aleloi
2017/02/23 15:16:00
cachec -> cache
| |
| 57 std::copy(spectrum_buffer_[position_].begin(), | |
| 58 spectrum_buffer_[position_].end(), spectral_sums_[0].begin()); | |
|
aleloi
2017/02/23 15:16:00
Does this caching really save time? I profiled som
| |
| 59 size_t position = (position_ + 1) % fft_buffer_.size(); | |
| 60 for (size_t j = 1; j < spectral_sums_length_; ++j) { | |
| 61 const std::array<float, kFftLengthBy2Plus1>& spectrum = | |
| 62 spectrum_buffer_[position]; | |
| 63 | |
|
aleloi
2017/02/23 15:16:00
IMO readability improvement (optional): compute th
| |
| 64 for (size_t k = 0; k < spectral_sums_[0].size(); ++k) { | |
| 65 spectral_sums_[0][k] += spectrum[k]; | |
| 66 } | |
| 67 | |
| 68 position = position < (fft_buffer_.size() - 1) ? position + 1 : 0; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 } // namespace webrtc | |
| OLD | NEW |