blob: 20cce920f0fa758006148a5b2375e33f5e0af336 [file] [log] [blame]
Alex Loiko4ed47d02018-04-04 15:05:57 +02001/*
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 Bonadeif0d64a52020-04-17 12:25:19 +020018#include "common_audio/third_party/ooura/fft_size_128/ooura_fft.h"
Alex Loiko4ed47d02018-04-04 15:05:57 +020019#include "modules/audio_processing/agc2/down_sampler.h"
20#include "modules/audio_processing/agc2/noise_spectrum_estimator.h"
Alex Loiko4ed47d02018-04-04 15:05:57 +020021
22namespace webrtc {
23
24class ApmDataDumper;
25class AudioBuffer;
26
27class SignalClassifier {
28 public:
29 enum class SignalType { kNonStationary, kStationary };
30
31 explicit SignalClassifier(ApmDataDumper* data_dumper);
Niels Möllerde953292020-09-29 09:46:21 +020032
33 SignalClassifier() = delete;
34 SignalClassifier(const SignalClassifier&) = delete;
35 SignalClassifier& operator=(const SignalClassifier&) = delete;
36
Alex Loiko4ed47d02018-04-04 15:05:57 +020037 ~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öllerde953292020-09-29 09:46:21 +020046
47 FrameExtender() = delete;
48 FrameExtender(const FrameExtender&) = delete;
49 FrameExtender& operator=(const FrameExtender&) = delete;
50
Alex Loiko4ed47d02018-04-04 15:05:57 +020051 ~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 Loiko4ed47d02018-04-04 15:05:57 +020058 };
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 Loiko4ed47d02018-04-04 15:05:57 +020069};
70
71} // namespace webrtc
72
73#endif // MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_