niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 15 | |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/audio_processing/include/audio_processing.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/constructor_magic.h" |
| 20 | #include "rtc_base/critical_section.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 21 | #include "rtc_base/thread_annotations.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 24 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | class AudioBuffer; |
| 26 | |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 27 | class VoiceDetectionImpl : public VoiceDetection { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | public: |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 29 | explicit VoiceDetectionImpl(rtc::CriticalSection* crit); |
| 30 | ~VoiceDetectionImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 32 | // TODO(peah): Fold into ctor, once public API is removed. |
| 33 | void Initialize(int sample_rate_hz); |
| 34 | void ProcessCaptureAudio(AudioBuffer* audio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
| 36 | // VoiceDetection implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 37 | int Enable(bool enable) override; |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 38 | bool is_enabled() const override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 39 | int set_stream_has_voice(bool has_voice) override; |
| 40 | bool stream_has_voice() const override; |
| 41 | int set_likelihood(Likelihood likelihood) override; |
| 42 | Likelihood likelihood() const override; |
| 43 | int set_frame_size_ms(int size) override; |
| 44 | int frame_size_ms() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 46 | private: |
| 47 | class Vad; |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 48 | |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 49 | rtc::CriticalSection* const crit_; |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 50 | bool enabled_ RTC_GUARDED_BY(crit_) = false; |
| 51 | bool stream_has_voice_ RTC_GUARDED_BY(crit_) = false; |
| 52 | bool using_external_vad_ RTC_GUARDED_BY(crit_) = false; |
| 53 | Likelihood likelihood_ RTC_GUARDED_BY(crit_) = kLowLikelihood; |
| 54 | int frame_size_ms_ RTC_GUARDED_BY(crit_) = 10; |
| 55 | size_t frame_size_samples_ RTC_GUARDED_BY(crit_) = 0; |
| 56 | int sample_rate_hz_ RTC_GUARDED_BY(crit_) = 0; |
| 57 | std::unique_ptr<Vad> vad_ RTC_GUARDED_BY(crit_); |
solenberg | a29386c | 2015-12-16 03:31:12 -0800 | [diff] [blame] | 58 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(VoiceDetectionImpl); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | }; |
| 60 | } // namespace webrtc |
| 61 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 62 | #endif // MODULES_AUDIO_PROCESSING_VOICE_DETECTION_IMPL_H_ |