blob: 7d71b9b327c03c2323ef1976a284f36bdae6427e [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#ifndef COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT
17#define COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Peter Kastingdce40cf2015-08-24 14:52:23 -070019#include <stddef.h>
20
Mirko Bonadei71207422017-09-15 13:58:09 +020021#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23typedef struct WebRtcVadInst VadInst;
24
25#ifdef __cplusplus
bjornv@webrtc.orged700db2012-03-12 12:17:26 +000026extern "C" {
niklase@google.com470e71d2011-07-07 08:21:25 +000027#endif
28
bjornv@webrtc.org26e8a582012-01-31 14:42:50 +000029// Creates an instance to the VAD structure.
Bjorn Volckerde4703c2015-05-27 07:22:58 +020030VadInst* WebRtcVad_Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000031
bjornv@webrtc.org26e8a582012-01-31 14:42:50 +000032// Frees the dynamic memory of a specified VAD instance.
33//
34// - handle [i] : Pointer to VAD instance that should be freed.
bjornv@webrtc.org2a796722014-04-22 04:45:35 +000035void WebRtcVad_Free(VadInst* handle);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
bjornv@webrtc.orged700db2012-03-12 12:17:26 +000037// Initializes a VAD instance.
38//
39// - handle [i/o] : Instance that should be initialized.
40//
41// returns : 0 - (OK),
deadbeef922246a2017-02-26 04:18:12 -080042// -1 - (null pointer or Default mode could not be set).
bjornv@webrtc.orged700db2012-03-12 12:17:26 +000043int WebRtcVad_Init(VadInst* handle);
niklase@google.com470e71d2011-07-07 08:21:25 +000044
bjornv@webrtc.org78f0cdc2012-03-27 11:06:29 +000045// Sets the VAD operating mode. A more aggressive (higher mode) VAD is more
46// restrictive in reporting speech. Put in other words the probability of being
47// speech when the VAD returns 1 is increased with increasing mode. As a
48// consequence also the missed detection rate goes up.
49//
50// - handle [i/o] : VAD instance.
51// - mode [i] : Aggressiveness mode (0, 1, 2, or 3).
52//
53// returns : 0 - (OK),
deadbeef922246a2017-02-26 04:18:12 -080054// -1 - (null pointer, mode could not be set or the VAD instance
bjornv@webrtc.org78f0cdc2012-03-27 11:06:29 +000055// has not been initialized).
56int WebRtcVad_set_mode(VadInst* handle, int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
bjornv@webrtc.orgb1c32762012-06-12 08:19:24 +000058// Calculates a VAD decision for the |audio_frame|. For valid sampling rates
59// frame lengths, see the description of WebRtcVad_ValidRatesAndFrameLengths().
60//
61// - handle [i/o] : VAD Instance. Needs to be initialized by
62// WebRtcVad_Init() before call.
63// - fs [i] : Sampling frequency (Hz): 8000, 16000, or 32000
64// - audio_frame [i] : Audio frame buffer.
65// - frame_length [i] : Length of audio frame buffer in number of samples.
66//
67// returns : 1 - (Active Voice),
68// 0 - (Non-active Voice),
69// -1 - (Error)
andrew@webrtc.org65f93382014-04-30 16:44:13 +000070int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
Peter Kastingdce40cf2015-08-24 14:52:23 -070071 size_t frame_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000072
bjornv@webrtc.orgb1c32762012-06-12 08:19:24 +000073// Checks for valid combinations of |rate| and |frame_length|. We support 10,
74// 20 and 30 ms frames and the rates 8000, 16000 and 32000 Hz.
75//
76// - rate [i] : Sampling frequency (Hz).
77// - frame_length [i] : Speech frame buffer length in number of samples.
78//
79// returns : 0 - (valid combination), -1 - (invalid combination)
Peter Kastingdce40cf2015-08-24 14:52:23 -070080int WebRtcVad_ValidRateAndFrameLength(int rate, size_t frame_length);
bjornv@webrtc.orgb1c32762012-06-12 08:19:24 +000081
niklase@google.com470e71d2011-07-07 08:21:25 +000082#ifdef __cplusplus
83}
84#endif
85
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020086#endif // COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT