From 80b301255ef8aea52fa6cab4e2c569bf2d0d7048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Tue, 2 Jun 2020 14:28:25 +0200 Subject: [PATCH] Reland "Change to using the new Ooura constructor" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a reland of a6c70741e76f2278bde5c7eab9d37984fe41dcf0 Original change's description: > Change to using the new Ooura constructor > > > Bug: b/155316201 > Change-Id: I40000e30df7a495a0937885abea19caeb599e00a > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176378 > Reviewed-by: Mirko Bonadei > Commit-Queue: Per Åhgren > Cr-Commit-Position: refs/heads/master@{#31411} Bug: b/155316201 Change-Id: Iba9748509d66b9ad4b210be83d515db684c5d5e0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176410 Reviewed-by: Mirko Bonadei Commit-Queue: Per Åhgren Cr-Commit-Position: refs/heads/master@{#31422} --- modules/audio_processing/aec3/aec3_fft.cc | 11 +++++++++++ modules/audio_processing/aec3/aec3_fft.h | 3 ++- modules/audio_processing/agc2/BUILD.gn | 1 + modules/audio_processing/agc2/signal_classifier.cc | 12 +++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/audio_processing/aec3/aec3_fft.cc b/modules/audio_processing/aec3/aec3_fft.cc index 1832101855..d1d4f7da06 100644 --- a/modules/audio_processing/aec3/aec3_fft.cc +++ b/modules/audio_processing/aec3/aec3_fft.cc @@ -15,6 +15,7 @@ #include #include "rtc_base/checks.h" +#include "system_wrappers/include/cpu_features_wrapper.h" namespace webrtc { @@ -70,8 +71,18 @@ const float kSqrtHanning128[kFftLength] = { 0.19509032201613f, 0.17096188876030f, 0.14673047445536f, 0.12241067519922f, 0.09801714032956f, 0.07356456359967f, 0.04906767432742f, 0.02454122852291f}; +bool IsSse2Available() { +#if defined(WEBRTC_ARCH_X86_FAMILY) + return WebRtc_GetCPUInfo(kSSE2) != 0; +#else + return false; +#endif +} + } // namespace +Aec3Fft::Aec3Fft() : ooura_fft_(IsSse2Available()) {} + // TODO(peah): Change x to be std::array once the rest of the code allows this. void Aec3Fft::ZeroPaddedFft(rtc::ArrayView x, Window window, diff --git a/modules/audio_processing/aec3/aec3_fft.h b/modules/audio_processing/aec3/aec3_fft.h index 7a2e024d75..6f7fbe4d0e 100644 --- a/modules/audio_processing/aec3/aec3_fft.h +++ b/modules/audio_processing/aec3/aec3_fft.h @@ -28,7 +28,8 @@ class Aec3Fft { public: enum class Window { kRectangular, kHanning, kSqrtHanning }; - Aec3Fft() = default; + Aec3Fft(); + // Computes the FFT. Note that both the input and output are modified. void Fft(std::array* x, FftData* X) const { RTC_DCHECK(x); diff --git a/modules/audio_processing/agc2/BUILD.gn b/modules/audio_processing/agc2/BUILD.gn index 8d9bb14731..bfef2252c3 100644 --- a/modules/audio_processing/agc2/BUILD.gn +++ b/modules/audio_processing/agc2/BUILD.gn @@ -153,6 +153,7 @@ rtc_library("noise_level_estimator") { "../../../common_audio/third_party/ooura:fft_size_128", "../../../rtc_base:checks", "../../../rtc_base:macromagic", + "../../../system_wrappers:cpu_features_api", ] configs += [ "..:apm_debug_dump" ] diff --git a/modules/audio_processing/agc2/signal_classifier.cc b/modules/audio_processing/agc2/signal_classifier.cc index 8778c49426..38334f7ec5 100644 --- a/modules/audio_processing/agc2/signal_classifier.cc +++ b/modules/audio_processing/agc2/signal_classifier.cc @@ -19,10 +19,19 @@ #include "modules/audio_processing/agc2/noise_spectrum_estimator.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" +#include "system_wrappers/include/cpu_features_wrapper.h" namespace webrtc { namespace { +bool IsSse2Available() { +#if defined(WEBRTC_ARCH_X86_FAMILY) + return WebRtc_GetCPUInfo(kSSE2) != 0; +#else + return false; +#endif +} + void RemoveDcLevel(rtc::ArrayView x) { RTC_DCHECK_LT(0, x.size()); float mean = std::accumulate(x.data(), x.data() + x.size(), 0.f); @@ -109,7 +118,8 @@ void SignalClassifier::FrameExtender::ExtendFrame( SignalClassifier::SignalClassifier(ApmDataDumper* data_dumper) : data_dumper_(data_dumper), down_sampler_(data_dumper_), - noise_spectrum_estimator_(data_dumper_) { + noise_spectrum_estimator_(data_dumper_), + ooura_fft_(IsSse2Available()) { Initialize(48000); } SignalClassifier::~SignalClassifier() {}