speech_probability_estimator.h (1840B)
1 /* 2 * Copyright (c) 2019 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_NS_SPEECH_PROBABILITY_ESTIMATOR_H_ 12 #define MODULES_AUDIO_PROCESSING_NS_SPEECH_PROBABILITY_ESTIMATOR_H_ 13 14 #include <array> 15 #include <cstdint> 16 17 #include "api/array_view.h" 18 #include "modules/audio_processing/ns/ns_common.h" 19 #include "modules/audio_processing/ns/signal_model_estimator.h" 20 21 namespace webrtc { 22 23 // Class for estimating the probability of speech. 24 class SpeechProbabilityEstimator { 25 public: 26 SpeechProbabilityEstimator(); 27 SpeechProbabilityEstimator(const SpeechProbabilityEstimator&) = delete; 28 SpeechProbabilityEstimator& operator=(const SpeechProbabilityEstimator&) = 29 delete; 30 31 // Compute speech probability. 32 void Update( 33 int32_t num_analyzed_frames, 34 ArrayView<const float, kFftSizeBy2Plus1> prior_snr, 35 ArrayView<const float, kFftSizeBy2Plus1> post_snr, 36 ArrayView<const float, kFftSizeBy2Plus1> conservative_noise_spectrum, 37 ArrayView<const float, kFftSizeBy2Plus1> signal_spectrum, 38 float signal_spectral_sum, 39 float signal_energy); 40 41 float get_prior_probability() const { return prior_speech_prob_; } 42 ArrayView<const float> get_probability() { return speech_probability_; } 43 44 private: 45 SignalModelEstimator signal_model_estimator_; 46 float prior_speech_prob_ = .5f; 47 std::array<float, kFftSizeBy2Plus1> speech_probability_; 48 }; 49 50 } // namespace webrtc 51 52 #endif // MODULES_AUDIO_PROCESSING_NS_SPEECH_PROBABILITY_ESTIMATOR_H_