96 lines
3.1 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/aec3/render_buffer.h"
#include <algorithm>
#include "modules/audio_processing/aec3/aec3_common.h"
#include "rtc_base/checks.h"
namespace webrtc {
RenderBuffer::RenderBuffer(Aec3Optimization optimization,
size_t num_bands,
size_t num_partitions,
const std::vector<size_t> num_ffts_for_spectral_sums)
: optimization_(optimization),
fft_buffer_(num_partitions),
spectrum_buffer_(num_partitions, std::array<float, kFftLengthBy2Plus1>()),
spectral_sums_(num_ffts_for_spectral_sums.size(),
std::array<float, kFftLengthBy2Plus1>()),
Reland of Fixed error for missing explict class initialization error on iOS WebRTC buildbots (patchset #1 id:1 of https://codereview.webrtc.org/2803933002/ ) Reason for revert: The revert did not fix the issue. Apparently this was actually the fix. Original issue's description: > Revert of Fixed error for missing explict class initialization error on iOS WebRTC buildbots (patchset #1 id:1 of https://codereview.webrtc.org/2799813002/ ) > > Reason for revert: > Causes compile error on iOS. > export DEVELOPER_DIR=/b/build/slave/ios-device-xcode-clang/build/src/build/ios_files/Xcode.app; /b/build/slave/cache/goma_client/gomacc clang++ -MMD -MF obj/third_party/webrtc/modules/audio_processing/audio_processing/render_buffer.o.d -DWEBRTC_APM_DEBUG_DUMP=0 -DWEBRTC_AUDIOPROC_DEBUG_DUMP -DWEBRTC_INTELLIGIBILITY_ENHANCER=0 -DWEBRTC_NS_FIXED -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC -DDISABLE_NACL -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -DCR_CLANG_REVISION=\"298539-1\" -DCR_XCODE_VERSION=0821 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DNS_BLOCK_ASSERTIONS=1 -DWEBRTC_RESTRICT_LOGGING -DEXPAT_RELATIVE_PATH -DHAVE_SCTP -DENABLE_EXTERNAL_AUTH -DHAVE_WEBRTC_VIDEO -DHAVE_WEBRTC_VOICE -DLOGGING_INSIDE_WEBRTC -DUSE_WEBRTC_DEV_BRANCH -DWEBRTC_ARCH_ARM -DWEBRTC_ARCH_ARM_V7 -DWEBRTC_HAS_NEON -DFEATURE_ENABLE_VOICEMAIL -DEXPAT_RELATIVE_PATH -DGTEST_RELATIVE_PATH -DNO_SOUND_SYSTEM -DWEBRTC_CHROMIUM_BUILD -DWEBRTC_POSIX -DWEBRTC_MAC -DWEBRTC_IOS -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -DHAVE_PTHREAD -I../.. -Igen -I../../third_party/webrtc_overrides -I../../third_party -I../../third_party -I../../third_party/webrtc/modules/audio_coding/codecs/isac/main/include -I../../third_party/protobuf/src -Igen/protoc_out -I../../third_party/protobuf/src -I../../third_party/webrtc/common_audio/resampler/include -I../../third_party/webrtc/common_audio/signal_processing/include -I../../third_party/webrtc/common_audio/vad/include -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fcolor-diagnostics -arch armv7 -Wall -Werror -Wextra -Wundeclared-selector -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Os -gdwarf-2 -isysroot /b/build/slave/ios-device-xcode-clang/build/src/build/ios_files/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk -stdlib=libc++ -miphoneos-version-min=9.0 -fvisibility=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -fvisibility-inlines-hidden -std=c++11 -fno-rtti -fno-exceptions -c ../../third_party/webrtc/modules/audio_processing/aec3/render_buffer.cc -o obj/third_party/webrtc/modules/audio_processing/audio_processing/render_buffer.o > ../../third_party/webrtc/modules/audio_processing/aec3/render_buffer.cc:20:15: error: constructor for 'webrtc::RenderBuffer' must explicitly initialize the const member 'fft_' > RenderBuffer::RenderBuffer(Aec3Optimization optimization, > ^ > ../../third_party/webrtc/modules/audio_processing/aec3/render_buffer.h:75:17: note: 'fft_' declared here > const Aec3Fft fft_; > ^ > > See https://luci-logdog.appspot.com/v/?s=chromium%2Fbb%2Ftryserver.chromium.mac%2Fios-device-xcode-clang%2F70027%2F%2B%2Frecipes%2Fsteps%2Fcompile__with_patch_%2F0%2Fstdout > > Original issue's description: > > Fixed error for missing explicit class initialization error on iOS buildbots > > > > TBR=henrik.lundin@webrtc.org > > > > BUG=webrtc:6018 > > > > Review-Url: https://codereview.webrtc.org/2799813002 > > Cr-Commit-Position: refs/heads/master@{#17549} > > Committed: https://chromium.googlesource.com/external/webrtc/+/5ac18af71b0805678fcf78b32b3c7d6aa62bea71 > > TBR=henrik.lundin@webrtc.org,peah@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:6018 > > Review-Url: https://codereview.webrtc.org/2803933002 > Cr-Commit-Position: refs/heads/master@{#17550} > Committed: https://chromium.googlesource.com/external/webrtc/+/854e5078537f9c94ad67db157427344d4c14d11f TBR=henrik.lundin@webrtc.org,peah@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:6018 Review-Url: https://codereview.webrtc.org/2798913003 Cr-Commit-Position: refs/heads/master@{#17551}
2017-04-05 22:06:36 -07:00
last_block_(num_bands, std::vector<float>(kBlockSize, 0.f)),
fft_() {
// Current implementation only allows a maximum of one spectral sum lengths.
RTC_DCHECK_EQ(1, num_ffts_for_spectral_sums.size());
spectral_sums_length_ = num_ffts_for_spectral_sums[0];
RTC_DCHECK_GE(fft_buffer_.size(), spectral_sums_length_);
Clear();
}
RenderBuffer::~RenderBuffer() = default;
void RenderBuffer::Clear() {
position_ = 0;
for (auto& sum : spectral_sums_) {
sum.fill(0.f);
}
for (auto& spectrum : spectrum_buffer_) {
spectrum.fill(0.f);
}
for (auto& fft : fft_buffer_) {
fft.Clear();
}
for (auto& b : last_block_) {
std::fill(b.begin(), b.end(), 0.f);
}
}
void RenderBuffer::Insert(const std::vector<std::vector<float>>& block) {
// Compute the FFT of the data in the lowest band.
FftData X;
fft_.PaddedFft(block[0], last_block_[0], &X);
// Copy the last render frame.
RTC_DCHECK_EQ(last_block_.size(), block.size());
for (size_t k = 0; k < block.size(); ++k) {
RTC_DCHECK_EQ(last_block_[k].size(), block[k].size());
std::copy(block[k].begin(), block[k].end(), last_block_[k].begin());
}
// Insert X into the buffer.
position_ = position_ > 0 ? position_ - 1 : fft_buffer_.size() - 1;
fft_buffer_[position_].Assign(X);
// Compute and insert the spectrum for the FFT into the spectrum buffer.
X.Spectrum(optimization_, &spectrum_buffer_[position_]);
// Pre-compute and cache the spectral sums.
std::copy(spectrum_buffer_[position_].begin(),
spectrum_buffer_[position_].end(), spectral_sums_[0].begin());
size_t position = (position_ + 1) % fft_buffer_.size();
for (size_t j = 1; j < spectral_sums_length_; ++j) {
const std::array<float, kFftLengthBy2Plus1>& spectrum =
spectrum_buffer_[position];
for (size_t k = 0; k < spectral_sums_[0].size(); ++k) {
spectral_sums_[0][k] += spectrum[k];
}
position = position < (fft_buffer_.size() - 1) ? position + 1 : 0;
}
}
} // namespace webrtc