Delaying SILK stereo->mono transitions by two frames
[opus.git] / silk / API.h
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, (subject to the limitations in the disclaimer below)
5 are permitted provided that the following conditions are met:
6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 - Neither the name of Skype Limited, nor the names of specific
12 contributors, may be used to endorse or promote products derived from
13 this software without specific prior written permission.
14 NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15 BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16 CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27
28 #ifndef SILK_API_H
29 #define SILK_API_H
30
31 #include "control.h"
32 #include "typedef.h"
33 #include "errors.h"
34 #include "entenc.h"
35 #include "entdec.h"
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41
42 #define SILK_MAX_FRAMES_PER_PACKET  3
43
44 /* Struct for TOC (Table of Contents) */
45 typedef struct {
46     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       */
49 } silk_TOC_struct;
50
51 /****************************************/
52 /* Encoder functions                    */
53 /****************************************/
54
55 /***********************************************/
56 /* Get size in bytes of the Silk encoder state */
57 /***********************************************/
58 opus_int silk_Get_Encoder_Size(                          /* O:   Returns error code                              */
59     int                                  *encSizeBytes   /* O:   Number of bytes in SILK encoder state           */
60 );
61
62 /*************************/
63 /* Init or reset encoder */
64 /*************************/
65 opus_int silk_InitEncoder(                               /* O:   Returns error code                              */
66     void                                *encState,      /* I/O: State                                           */
67     silk_EncControlStruct               *encStatus      /* O:   Encoder Status                                  */
68 );
69
70 /***************************************/
71 /* Read control structure from encoder */
72 /***************************************/
73 opus_int silk_QueryEncoder(                              /* O:   Returns error code                              */
74     const void                          *encState,      /* I:   State                                           */
75     silk_EncControlStruct               *encStatus      /* O:   Encoder Status                                  */
76 );
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                                                                         */
83 opus_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                       */
89     opus_int                             *nBytesOut,     /* I/O: Number of bytes in payload (input: Max bytes)   */
90     const opus_int                       prefillFlag     /* I:   Flag to indicate prefilling buffers no coding   */
91 );
92
93 /****************************************/
94 /* Decoder functions                    */
95 /****************************************/
96
97 /***********************************************/
98 /* Get size in bytes of the Silk decoder state */
99 /***********************************************/
100 opus_int silk_Get_Decoder_Size(                          /* O:   Returns error code                              */
101     int                                  *decSizeBytes   /* O:   Number of bytes in SILK decoder state           */
102 );
103
104 /*************************/
105 /* Init or Reset decoder */
106 /*************************/
107 opus_int silk_InitDecoder(                               /* O:   Returns error code                              */
108     void                                *decState       /* I/O: State                                           */
109 );
110
111 /******************/
112 /* Decode a frame */
113 /******************/
114 opus_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                       */
122 );
123
124 /**************************************/
125 /* Get table of contents for a packet */
126 /**************************************/
127 opus_int silk_get_TOC(
128     const opus_uint8                     *payload,           /* I    Payload data                                */
129     const opus_int                       nBytesIn,           /* I:   Number of input bytes                       */
130     const opus_int                       nFramesPerPayload,  /* I:   Number of SILK frames per payload           */
131     silk_TOC_struct                     *Silk_TOC           /* O:   Type of content                             */
132 );
133
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif