Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "api/array_view.h" |
Mirko Bonadei | f0d64a5 | 2020-04-17 12:25:19 +0200 | [diff] [blame] | 18 | #include "common_audio/third_party/ooura/fft_size_128/ooura_fft.h" |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 19 | #include "modules/audio_processing/agc2/down_sampler.h" |
| 20 | #include "modules/audio_processing/agc2/noise_spectrum_estimator.h" |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class ApmDataDumper; |
| 25 | class AudioBuffer; |
| 26 | |
| 27 | class SignalClassifier { |
| 28 | public: |
| 29 | enum class SignalType { kNonStationary, kStationary }; |
| 30 | |
| 31 | explicit SignalClassifier(ApmDataDumper* data_dumper); |
Niels Möller | de95329 | 2020-09-29 09:46:21 +0200 | [diff] [blame] | 32 | |
| 33 | SignalClassifier() = delete; |
| 34 | SignalClassifier(const SignalClassifier&) = delete; |
| 35 | SignalClassifier& operator=(const SignalClassifier&) = delete; |
| 36 | |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 37 | ~SignalClassifier(); |
| 38 | |
| 39 | void Initialize(int sample_rate_hz); |
| 40 | SignalType Analyze(rtc::ArrayView<const float> signal); |
| 41 | |
| 42 | private: |
| 43 | class FrameExtender { |
| 44 | public: |
| 45 | FrameExtender(size_t frame_size, size_t extended_frame_size); |
Niels Möller | de95329 | 2020-09-29 09:46:21 +0200 | [diff] [blame] | 46 | |
| 47 | FrameExtender() = delete; |
| 48 | FrameExtender(const FrameExtender&) = delete; |
| 49 | FrameExtender& operator=(const FrameExtender&) = delete; |
| 50 | |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 51 | ~FrameExtender(); |
| 52 | |
| 53 | void ExtendFrame(rtc::ArrayView<const float> x, |
| 54 | rtc::ArrayView<float> x_extended); |
| 55 | |
| 56 | private: |
| 57 | std::vector<float> x_old_; |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | ApmDataDumper* const data_dumper_; |
| 61 | DownSampler down_sampler_; |
| 62 | std::unique_ptr<FrameExtender> frame_extender_; |
| 63 | NoiseSpectrumEstimator noise_spectrum_estimator_; |
| 64 | int sample_rate_hz_; |
| 65 | int initialization_frames_left_; |
| 66 | int consistent_classification_counter_; |
| 67 | SignalType last_signal_type_; |
| 68 | const OouraFft ooura_fft_; |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace webrtc |
| 72 | |
| 73 | #endif // MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_ |