niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 152c34c | 2012-01-23 12:36:46 +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 | |
| 11 | |
| 12 | /* |
| 13 | * This header file includes the VAD API calls. Specific function calls are given below. |
| 14 | */ |
| 15 | |
bjornv@webrtc.org | b1c3276 | 2012-06-12 08:19:24 +0000 | [diff] [blame] | 16 | #ifndef WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 17 | #define WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
pbos@webrtc.org | aa30bb7 | 2013-05-27 09:49:58 +0000 | [diff] [blame^] | 19 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | typedef struct WebRtcVadInst VadInst; |
| 22 | |
| 23 | #ifdef __cplusplus |
bjornv@webrtc.org | ed700db | 2012-03-12 12:17:26 +0000 | [diff] [blame] | 24 | extern "C" { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | #endif |
| 26 | |
bjornv@webrtc.org | 26e8a58 | 2012-01-31 14:42:50 +0000 | [diff] [blame] | 27 | // Creates an instance to the VAD structure. |
| 28 | // |
| 29 | // - handle [o] : Pointer to the VAD instance that should be created. |
| 30 | // |
| 31 | // returns : 0 - (OK), -1 - (Error) |
| 32 | int WebRtcVad_Create(VadInst** handle); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
bjornv@webrtc.org | 26e8a58 | 2012-01-31 14:42:50 +0000 | [diff] [blame] | 34 | // Frees the dynamic memory of a specified VAD instance. |
| 35 | // |
| 36 | // - handle [i] : Pointer to VAD instance that should be freed. |
| 37 | // |
| 38 | // returns : 0 - (OK), -1 - (NULL pointer in) |
| 39 | int WebRtcVad_Free(VadInst* handle); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
bjornv@webrtc.org | ed700db | 2012-03-12 12:17:26 +0000 | [diff] [blame] | 41 | // Initializes a VAD instance. |
| 42 | // |
| 43 | // - handle [i/o] : Instance that should be initialized. |
| 44 | // |
| 45 | // returns : 0 - (OK), |
bjornv@webrtc.org | 78f0cdc | 2012-03-27 11:06:29 +0000 | [diff] [blame] | 46 | // -1 - (NULL pointer or Default mode could not be set). |
bjornv@webrtc.org | ed700db | 2012-03-12 12:17:26 +0000 | [diff] [blame] | 47 | int WebRtcVad_Init(VadInst* handle); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
bjornv@webrtc.org | 78f0cdc | 2012-03-27 11:06:29 +0000 | [diff] [blame] | 49 | // Sets the VAD operating mode. A more aggressive (higher mode) VAD is more |
| 50 | // restrictive in reporting speech. Put in other words the probability of being |
| 51 | // speech when the VAD returns 1 is increased with increasing mode. As a |
| 52 | // consequence also the missed detection rate goes up. |
| 53 | // |
| 54 | // - handle [i/o] : VAD instance. |
| 55 | // - mode [i] : Aggressiveness mode (0, 1, 2, or 3). |
| 56 | // |
| 57 | // returns : 0 - (OK), |
| 58 | // -1 - (NULL pointer, mode could not be set or the VAD instance |
| 59 | // has not been initialized). |
| 60 | int WebRtcVad_set_mode(VadInst* handle, int mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
bjornv@webrtc.org | b1c3276 | 2012-06-12 08:19:24 +0000 | [diff] [blame] | 62 | // Calculates a VAD decision for the |audio_frame|. For valid sampling rates |
| 63 | // frame lengths, see the description of WebRtcVad_ValidRatesAndFrameLengths(). |
| 64 | // |
| 65 | // - handle [i/o] : VAD Instance. Needs to be initialized by |
| 66 | // WebRtcVad_Init() before call. |
| 67 | // - fs [i] : Sampling frequency (Hz): 8000, 16000, or 32000 |
| 68 | // - audio_frame [i] : Audio frame buffer. |
| 69 | // - frame_length [i] : Length of audio frame buffer in number of samples. |
| 70 | // |
| 71 | // returns : 1 - (Active Voice), |
| 72 | // 0 - (Non-active Voice), |
| 73 | // -1 - (Error) |
bjornv@webrtc.org | b38fca1 | 2012-06-19 11:03:32 +0000 | [diff] [blame] | 74 | int WebRtcVad_Process(VadInst* handle, int fs, int16_t* audio_frame, |
| 75 | int frame_length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
bjornv@webrtc.org | b1c3276 | 2012-06-12 08:19:24 +0000 | [diff] [blame] | 77 | // Checks for valid combinations of |rate| and |frame_length|. We support 10, |
| 78 | // 20 and 30 ms frames and the rates 8000, 16000 and 32000 Hz. |
| 79 | // |
| 80 | // - rate [i] : Sampling frequency (Hz). |
| 81 | // - frame_length [i] : Speech frame buffer length in number of samples. |
| 82 | // |
| 83 | // returns : 0 - (valid combination), -1 - (invalid combination) |
| 84 | int WebRtcVad_ValidRateAndFrameLength(int rate, int frame_length); |
| 85 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | #ifdef __cplusplus |
| 87 | } |
| 88 | #endif |
| 89 | |
bjornv@webrtc.org | b1c3276 | 2012-06-12 08:19:24 +0000 | [diff] [blame] | 90 | #endif // WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT |