blob: c77ad2f5bf4ff694222d3348f5e0bb9133aef6d9 [file] [log] [blame]
Gregory Maxwellae231142011-07-30 08:18:48 -04001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
Jean-Marc Valinae00e602012-04-20 16:31:04 -04004modification, are permitted provided that the following conditions
5are met:
Gregory Maxwellae231142011-07-30 08:18:48 -04006- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
Jean-Marc Valinae00e602012-04-20 16:31:04 -040011- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
Gregory Maxwellae231142011-07-30 08:18:48 -040026***********************************************************************/
27
28#ifndef SILK_API_H
29#define SILK_API_H
30
Jean-Marc Valin1c2f5632011-09-16 01:16:53 -070031#include "control.h"
32#include "typedef.h"
33#include "errors.h"
Gregory Maxwellae231142011-07-30 08:18:48 -040034#include "entenc.h"
35#include "entdec.h"
36
37#ifdef __cplusplus
38extern "C"
39{
40#endif
41
42#define SILK_MAX_FRAMES_PER_PACKET 3
43
44/* Struct for TOC (Table of Contents) */
45typedef struct {
Koen Vosacc7a6c2011-10-28 19:44:26 -040046 opus_int VADFlag; /* Voice activity for packet */
47 opus_int VADFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Voice activity for each frame in packet */
48 opus_int inbandFECFlag; /* Flag indicating if packet contains in-band FEC */
Gregory Maxwellae231142011-07-30 08:18:48 -040049} silk_TOC_struct;
50
51/****************************************/
52/* Encoder functions */
53/****************************************/
54
55/***********************************************/
56/* Get size in bytes of the Silk encoder state */
57/***********************************************/
Koen Vosacc7a6c2011-10-28 19:44:26 -040058opus_int silk_Get_Encoder_Size( /* O Returns error code */
59 opus_int *encSizeBytes /* O Number of bytes in SILK encoder state */
Gregory Maxwellae231142011-07-30 08:18:48 -040060);
61
62/*************************/
63/* Init or reset encoder */
64/*************************/
Koen Vosacc7a6c2011-10-28 19:44:26 -040065opus_int silk_InitEncoder( /* O Returns error code */
66 void *encState, /* I/O State */
67 silk_EncControlStruct *encStatus /* O Encoder Status */
Gregory Maxwellae231142011-07-30 08:18:48 -040068);
69
70/***************************************/
71/* Read control structure from encoder */
72/***************************************/
Koen Vosacc7a6c2011-10-28 19:44:26 -040073opus_int silk_QueryEncoder( /* O Returns error code */
74 const void *encState, /* I State */
75 silk_EncControlStruct *encStatus /* O Encoder Status */
Gregory Maxwellae231142011-07-30 08:18:48 -040076);
77
78/**************************/
79/* Encode frame with Silk */
80/**************************/
81/* Note: if prefillFlag is set, the input must contain 10 ms of audio, irrespective of what */
82/* encControl->payloadSize_ms is set to */
Koen Vosacc7a6c2011-10-28 19:44:26 -040083opus_int silk_Encode( /* O Returns error code */
84 void *encState, /* I/O State */
85 silk_EncControlStruct *encControl, /* I Control status */
86 const opus_int16 *samplesIn, /* I Speech sample input vector */
87 opus_int nSamplesIn, /* I Number of samples in input vector */
88 ec_enc *psRangeEnc, /* I/O Compressor data structure */
Jean-Marc Valin59354a72012-03-08 12:19:07 -050089 opus_int32 *nBytesOut, /* I/O Number of bytes in payload (input: Max bytes) */
Koen Vosacc7a6c2011-10-28 19:44:26 -040090 const opus_int prefillFlag /* I Flag to indicate prefilling buffers no coding */
Gregory Maxwellae231142011-07-30 08:18:48 -040091);
92
93/****************************************/
94/* Decoder functions */
95/****************************************/
96
97/***********************************************/
98/* Get size in bytes of the Silk decoder state */
99/***********************************************/
Koen Vosacc7a6c2011-10-28 19:44:26 -0400100opus_int silk_Get_Decoder_Size( /* O Returns error code */
101 opus_int *decSizeBytes /* O Number of bytes in SILK decoder state */
Gregory Maxwellae231142011-07-30 08:18:48 -0400102);
103
104/*************************/
105/* Init or Reset decoder */
106/*************************/
Koen Vosacc7a6c2011-10-28 19:44:26 -0400107opus_int silk_InitDecoder( /* O Returns error code */
108 void *decState /* I/O State */
Gregory Maxwellae231142011-07-30 08:18:48 -0400109);
110
111/******************/
112/* Decode a frame */
113/******************/
Koen Vosacc7a6c2011-10-28 19:44:26 -0400114opus_int silk_Decode( /* O Returns error code */
115 void* decState, /* I/O State */
116 silk_DecControlStruct* decControl, /* I/O Control Structure */
117 opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
118 opus_int newPacketFlag, /* I Indicates first decoder call for this packet */
119 ec_dec *psRangeDec, /* I/O Compressor data structure */
120 opus_int16 *samplesOut, /* O Decoded output speech vector */
121 opus_int32 *nSamplesOut /* O Number of samples decoded */
Gregory Maxwellae231142011-07-30 08:18:48 -0400122);
123
Gregory Maxwell0d57a5d2012-08-06 10:52:27 -0400124#if 0
Gregory Maxwellae231142011-07-30 08:18:48 -0400125/**************************************/
126/* Get table of contents for a packet */
127/**************************************/
128opus_int silk_get_TOC(
Koen Vosacc7a6c2011-10-28 19:44:26 -0400129 const opus_uint8 *payload, /* I Payload data */
130 const opus_int nBytesIn, /* I Number of input bytes */
131 const opus_int nFramesPerPayload, /* I Number of SILK frames per payload */
132 silk_TOC_struct *Silk_TOC /* O Type of content */
Gregory Maxwellae231142011-07-30 08:18:48 -0400133);
Gregory Maxwell0d57a5d2012-08-06 10:52:27 -0400134#endif
Gregory Maxwellae231142011-07-30 08:18:48 -0400135
136#ifdef __cplusplus
137}
138#endif
139
140#endif