henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef COMMON_AUDIO_VAD_INCLUDE_VAD_H_ |
| 12 | #define COMMON_AUDIO_VAD_INCLUDE_VAD_H_ |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 91d9756 | 2016-02-14 01:10:03 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "common_audio/vad/include/webrtc_vad.h" |
| 17 | #include "rtc_base/checks.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 18 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 22 | class Vad { |
| 23 | public: |
| 24 | enum Aggressiveness { |
| 25 | kVadNormal = 0, |
| 26 | kVadLowBitrate = 1, |
| 27 | kVadAggressive = 2, |
| 28 | kVadVeryAggressive = 3 |
| 29 | }; |
| 30 | |
| 31 | enum Activity { kPassive = 0, kActive = 1, kError = -1 }; |
| 32 | |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 33 | virtual ~Vad() = default; |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 34 | |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 35 | // Calculates a VAD decision for the given audio frame. Valid sample rates |
| 36 | // are 8000, 16000, and 32000 Hz; the number of samples must be such that the |
| 37 | // frame is 10, 20, or 30 ms long. |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 +0000 | [diff] [blame] | 38 | virtual Activity VoiceActivity(const int16_t* audio, |
| 39 | size_t num_samples, |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 40 | int sample_rate_hz) = 0; |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 41 | |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 42 | // Resets VAD state. |
| 43 | virtual void Reset() = 0; |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 46 | // Returns a Vad instance that's implemented on top of WebRtcVad. |
kwiberg | 91d9756 | 2016-02-14 01:10:03 -0800 | [diff] [blame] | 47 | std::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness); |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 48 | |
henrik.lundin@webrtc.org | 8aa4d2d | 2014-10-30 13:23:25 +0000 | [diff] [blame] | 49 | } // namespace webrtc |
kwiberg | e9e7896 | 2015-09-08 23:04:51 -0700 | [diff] [blame] | 50 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 51 | #endif // COMMON_AUDIO_VAD_INCLUDE_VAD_H_ |