signal_classifier.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_
  11. #define MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/array_view.h"
  15. #include "common_audio/third_party/ooura/fft_size_128/ooura_fft.h"
  16. #include "modules/audio_processing/agc2/down_sampler.h"
  17. #include "modules/audio_processing/agc2/noise_spectrum_estimator.h"
  18. namespace webrtc {
  19. class ApmDataDumper;
  20. class AudioBuffer;
  21. class SignalClassifier {
  22. public:
  23. enum class SignalType { kNonStationary, kStationary };
  24. explicit SignalClassifier(ApmDataDumper* data_dumper);
  25. SignalClassifier() = delete;
  26. SignalClassifier(const SignalClassifier&) = delete;
  27. SignalClassifier& operator=(const SignalClassifier&) = delete;
  28. ~SignalClassifier();
  29. void Initialize(int sample_rate_hz);
  30. SignalType Analyze(rtc::ArrayView<const float> signal);
  31. private:
  32. class FrameExtender {
  33. public:
  34. FrameExtender(size_t frame_size, size_t extended_frame_size);
  35. FrameExtender() = delete;
  36. FrameExtender(const FrameExtender&) = delete;
  37. FrameExtender& operator=(const FrameExtender&) = delete;
  38. ~FrameExtender();
  39. void ExtendFrame(rtc::ArrayView<const float> x,
  40. rtc::ArrayView<float> x_extended);
  41. private:
  42. std::vector<float> x_old_;
  43. };
  44. ApmDataDumper* const data_dumper_;
  45. DownSampler down_sampler_;
  46. std::unique_ptr<FrameExtender> frame_extender_;
  47. NoiseSpectrumEstimator noise_spectrum_estimator_;
  48. int sample_rate_hz_;
  49. int initialization_frames_left_;
  50. int consistent_classification_counter_;
  51. SignalType last_signal_type_;
  52. const OouraFft ooura_fft_;
  53. };
  54. } // namespace webrtc
  55. #endif // MODULES_AUDIO_PROCESSING_AGC2_SIGNAL_CLASSIFIER_H_