peah 81b9291dfd The FFT functionality in aec_rdft* is based on legacy C
code which is not thread-safe in the sense that the
rdft_init method can only be run in a single-threaded.

Currently, inside WebRTC multiple instances of the audio-
processing module are set up which means that the init
method may be run concurrently.

In order to avoid having to protect the init method with
a lock to ensure single-threaded behavior that, this CL
places the FFT functionality inside a class so that there
is no global component of the FFT functionality.

Note that:
1) The nonstandard header for the ooura_fft.cc was copied
   from the aec_rdft.cc header, and augmented with a
   description of the changes introduced in this CL.
2) The clang warnings for the ooura_fft_sse2.cc,
   ooura_fft_neon.cc and ooura_fft_mips.cc were not
   addressed as this code was kept as it was before this CL
3) Clang-format was run on all files apart from
   ooura_fft_mips.cc (as that would change the format of
   the inline assempbly code).

Adding bypass of presubmit to avoid code style and header errors caused by the fact that files with legacy code are being renamed.

NOPRESUBMIT=true

BUG=chromium:638583

Review-Url: https://codereview.webrtc.org/2348213002
Cr-Commit-Position: refs/heads/master@{#14554}
2016-10-06 13:46:27 +00:00

68 lines
2.1 KiB
C++

/*
* Copyright (c) 2016 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.
*/
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_CONTROLLER_SIGNAL_CLASSIFIER_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_CONTROLLER_SIGNAL_CLASSIFIER_H_
#include <memory>
#include <vector>
#include "webrtc/base/array_view.h"
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/audio_processing/level_controller/down_sampler.h"
#include "webrtc/modules/audio_processing/level_controller/noise_spectrum_estimator.h"
#include "webrtc/modules/audio_processing/utility/ooura_fft.h"
namespace webrtc {
class ApmDataDumper;
class AudioBuffer;
class SignalClassifier {
public:
enum class SignalType { kHighlyNonStationary, kNonStationary, kStationary };
explicit SignalClassifier(ApmDataDumper* data_dumper);
~SignalClassifier();
void Initialize(int sample_rate_hz);
void Analyze(const AudioBuffer& audio, SignalType* signal_type);
private:
class FrameExtender {
public:
FrameExtender(size_t frame_size, size_t extended_frame_size);
~FrameExtender();
void ExtendFrame(rtc::ArrayView<const float> x,
rtc::ArrayView<float> x_extended);
private:
std::vector<float> x_old_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FrameExtender);
};
ApmDataDumper* const data_dumper_;
DownSampler down_sampler_;
std::unique_ptr<FrameExtender> frame_extender_;
NoiseSpectrumEstimator noise_spectrum_estimator_;
int sample_rate_hz_;
int initialization_frames_left_;
int consistent_classification_counter_;
SignalType last_signal_type_;
const OouraFft ooura_fft_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SignalClassifier);
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_CONTROLLER_SIGNAL_CLASSIFIER_H_