blob: 1a6e10a2259ddcecc299ee0a10704a08da2fdd38 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org152c34c2012-01-23 12:36:46 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orgb1c32762012-06-12 08:19:24 +000016#ifndef WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +000017#define WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000018
pbos@webrtc.orgaa30bb72013-05-27 09:49:58 +000019#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21typedef struct WebRtcVadInst VadInst;
22
23#ifdef __cplusplus
bjornv@webrtc.orged700db2012-03-12 12:17:26 +000024extern "C" {
niklase@google.com470e71d2011-07-07 08:21:25 +000025#endif
26
bjornv@webrtc.org26e8a582012-01-31 14:42:50 +000027// 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)
32int WebRtcVad_Create(VadInst** handle);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
bjornv@webrtc.org26e8a582012-01-31 14:42:50 +000034// Frees the dynamic memory of a specified VAD instance.
35//
36// - handle [i] : Pointer to VAD instance that should be freed.
bjornv@webrtc.org2a796722014-04-22 04:45:35 +000037void WebRtcVad_Free(VadInst* handle);
niklase@google.com470e71d2011-07-07 08:21:25 +000038
bjornv@webrtc.orged700db2012-03-12 12:17:26 +000039// Initializes a VAD instance.
40//
41// - handle [i/o] : Instance that should be initialized.
42//
43// returns : 0 - (OK),
bjornv@webrtc.org78f0cdc2012-03-27 11:06:29 +000044// -1 - (NULL pointer or Default mode could not be set).
bjornv@webrtc.orged700db2012-03-12 12:17:26 +000045int WebRtcVad_Init(VadInst* handle);
niklase@google.com470e71d2011-07-07 08:21:25 +000046
bjornv@webrtc.org78f0cdc2012-03-27 11:06:29 +000047// Sets the VAD operating mode. A more aggressive (higher mode) VAD is more
48// restrictive in reporting speech. Put in other words the probability of being
49// speech when the VAD returns 1 is increased with increasing mode. As a
50// consequence also the missed detection rate goes up.
51//
52// - handle [i/o] : VAD instance.
53// - mode [i] : Aggressiveness mode (0, 1, 2, or 3).
54//
55// returns : 0 - (OK),
56// -1 - (NULL pointer, mode could not be set or the VAD instance
57// has not been initialized).
58int WebRtcVad_set_mode(VadInst* handle, int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
bjornv@webrtc.orgb1c32762012-06-12 08:19:24 +000060// Calculates a VAD decision for the |audio_frame|. For valid sampling rates
61// frame lengths, see the description of WebRtcVad_ValidRatesAndFrameLengths().
62//
63// - handle [i/o] : VAD Instance. Needs to be initialized by
64// WebRtcVad_Init() before call.
65// - fs [i] : Sampling frequency (Hz): 8000, 16000, or 32000
66// - audio_frame [i] : Audio frame buffer.
67// - frame_length [i] : Length of audio frame buffer in number of samples.
68//
69// returns : 1 - (Active Voice),
70// 0 - (Non-active Voice),
71// -1 - (Error)
bjornv@webrtc.orgb38fca12012-06-19 11:03:32 +000072int WebRtcVad_Process(VadInst* handle, int fs, int16_t* audio_frame,
73 int frame_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000074
bjornv@webrtc.orgb1c32762012-06-12 08:19:24 +000075// Checks for valid combinations of |rate| and |frame_length|. We support 10,
76// 20 and 30 ms frames and the rates 8000, 16000 and 32000 Hz.
77//
78// - rate [i] : Sampling frequency (Hz).
79// - frame_length [i] : Speech frame buffer length in number of samples.
80//
81// returns : 0 - (valid combination), -1 - (invalid combination)
82int WebRtcVad_ValidRateAndFrameLength(int rate, int frame_length);
83
niklase@google.com470e71d2011-07-07 08:21:25 +000084#ifdef __cplusplus
85}
86#endif
87
bjornv@webrtc.orgb1c32762012-06-12 08:19:24 +000088#endif // WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT