1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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  * ilbc.h
13  *
14  * This header file contains all of the API's for iLBC.
15  *
16  */
17 
18 #ifndef MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
19 #define MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
20 
21 #include <stddef.h>
22 #include <stdint.h>
23 
24 /*
25  * Solution to support multiple instances
26  * Customer has to cast instance to proper type
27  */
28 
29 typedef struct iLBC_encinst_t_ IlbcEncoderInstance;
30 
31 typedef struct iLBC_decinst_t_ IlbcDecoderInstance;
32 
33 /*
34  * Comfort noise constants
35  */
36 
37 #define ILBC_SPEECH 1
38 #define ILBC_CNG 2
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /****************************************************************************
45  * WebRtcIlbcfix_XxxAssign(...)
46  *
47  * These functions assigns the encoder/decoder instance to the specified
48  * memory location
49  *
50  * Input:
51  *     - XXX_xxxinst       : Pointer to created instance that should be
52  *                           assigned
53  *     - ILBCXXX_inst_Addr : Pointer to the desired memory space
54  *     - size              : The size that this structure occupies (in Word16)
55  *
56  * Return value             :  0 - Ok
57  *                            -1 - Error
58  */
59 
60 int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance** iLBC_encinst,
61                                     int16_t* ILBCENC_inst_Addr,
62                                     int16_t* size);
63 int16_t WebRtcIlbcfix_DecoderAssign(IlbcDecoderInstance** iLBC_decinst,
64                                     int16_t* ILBCDEC_inst_Addr,
65                                     int16_t* size);
66 
67 /****************************************************************************
68  * WebRtcIlbcfix_XxxAssign(...)
69  *
70  * These functions create a instance to the specified structure
71  *
72  * Input:
73  *      - XXX_inst        : Pointer to created instance that should be created
74  *
75  * Return value           :  0 - Ok
76  *                          -1 - Error
77  */
78 
79 int16_t WebRtcIlbcfix_EncoderCreate(IlbcEncoderInstance** iLBC_encinst);
80 int16_t WebRtcIlbcfix_DecoderCreate(IlbcDecoderInstance** iLBC_decinst);
81 
82 /****************************************************************************
83  * WebRtcIlbcfix_XxxFree(...)
84  *
85  * These functions frees the dynamic memory of a specified instance
86  *
87  * Input:
88  *      - XXX_inst          : Pointer to created instance that should be freed
89  *
90  * Return value             :  0 - Ok
91  *                            -1 - Error
92  */
93 
94 int16_t WebRtcIlbcfix_EncoderFree(IlbcEncoderInstance* iLBC_encinst);
95 int16_t WebRtcIlbcfix_DecoderFree(IlbcDecoderInstance* iLBC_decinst);
96 
97 /****************************************************************************
98  * WebRtcIlbcfix_EncoderInit(...)
99  *
100  * This function initializes a iLBC instance
101  *
102  * Input:
103  *      - iLBCenc_inst      : iLBC instance, i.e. the user that should receive
104  *                            be initialized
105  *      - frameLen          : The frame length of the codec 20/30 (ms)
106  *
107  * Return value             :  0 - Ok
108  *                            -1 - Error
109  */
110 
111 int16_t WebRtcIlbcfix_EncoderInit(IlbcEncoderInstance* iLBCenc_inst,
112                                   int16_t frameLen);
113 
114 /****************************************************************************
115  * WebRtcIlbcfix_Encode(...)
116  *
117  * This function encodes one iLBC frame. Input speech length has be a
118  * multiple of the frame length.
119  *
120  * Input:
121  *      - iLBCenc_inst      : iLBC instance, i.e. the user that should encode
122  *                            a package
123  *      - speechIn          : Input speech vector
124  *      - len               : Samples in speechIn (160, 240, 320 or 480)
125  *
126  * Output:
127  *  - encoded               : The encoded data vector
128  *
129  * Return value             : >0 - Length (in bytes) of coded data
130  *                            -1 - Error
131  */
132 
133 int WebRtcIlbcfix_Encode(IlbcEncoderInstance* iLBCenc_inst,
134                          const int16_t* speechIn,
135                          size_t len,
136                          uint8_t* encoded);
137 
138 /****************************************************************************
139  * WebRtcIlbcfix_DecoderInit(...)
140  *
141  * This function initializes a iLBC instance with either 20 or 30 ms frames
142  * Alternatively the WebRtcIlbcfix_DecoderInit_XXms can be used. Then it's
143  * not needed to specify the frame length with a variable.
144  *
145  * Input:
146  *      - IlbcDecoderInstance : iLBC decoder instance
147  *      - frameLen            : The frame length of the codec 20/30 (ms)
148  *
149  * Return value               :  0 - Ok
150  *                              -1 - Error
151  */
152 
153 int16_t WebRtcIlbcfix_DecoderInit(IlbcDecoderInstance* iLBCdec_inst,
154                                   int16_t frameLen);
155 void WebRtcIlbcfix_DecoderInit20Ms(IlbcDecoderInstance* iLBCdec_inst);
156 void WebRtcIlbcfix_Decoderinit30Ms(IlbcDecoderInstance* iLBCdec_inst);
157 
158 /****************************************************************************
159  * WebRtcIlbcfix_Decode(...)
160  *
161  * This function decodes a packet with iLBC frame(s). Output speech length
162  * will be a multiple of 160 or 240 samples ((160 or 240)*frames/packet).
163  *
164  * Input:
165  *      - iLBCdec_inst      : iLBC instance, i.e. the user that should decode
166  *                            a packet
167  *      - encoded           : Encoded iLBC frame(s)
168  *      - len               : Bytes in encoded vector
169  *
170  * Output:
171  *      - decoded           : The decoded vector
172  *      - speechType        : 1 normal, 2 CNG
173  *
174  * Return value             : >0 - Samples in decoded vector
175  *                            -1 - Error
176  */
177 
178 int WebRtcIlbcfix_Decode(IlbcDecoderInstance* iLBCdec_inst,
179                          const uint8_t* encoded,
180                          size_t len,
181                          int16_t* decoded,
182                          int16_t* speechType);
183 int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst,
184                              const uint8_t* encoded,
185                              size_t len,
186                              int16_t* decoded,
187                              int16_t* speechType);
188 int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst,
189                              const uint8_t* encoded,
190                              size_t len,
191                              int16_t* decoded,
192                              int16_t* speechType);
193 
194 /****************************************************************************
195  * WebRtcIlbcfix_DecodePlc(...)
196  *
197  * This function conducts PLC for iLBC frame(s). Output speech length
198  * will be a multiple of 160 or 240 samples.
199  *
200  * Input:
201  *      - iLBCdec_inst      : iLBC instance, i.e. the user that should perform
202  *                            a PLC
203  *      - noOfLostFrames    : Number of PLC frames to produce
204  *
205  * Output:
206  *      - decoded           : The "decoded" vector
207  *
208  * Return value             : Samples in decoded PLC vector
209  */
210 
211 size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst,
212                                int16_t* decoded,
213                                size_t noOfLostFrames);
214 
215 /****************************************************************************
216  * WebRtcIlbcfix_NetEqPlc(...)
217  *
218  * This function updates the decoder when a packet loss has occured, but it
219  * does not produce any PLC data. Function can be used if another PLC method
220  * is used (i.e NetEq).
221  *
222  * Input:
223  *      - iLBCdec_inst      : iLBC instance that should be updated
224  *      - noOfLostFrames    : Number of lost frames
225  *
226  * Output:
227  *      - decoded           : The "decoded" vector (nothing in this case)
228  *
229  * Return value             : Samples in decoded PLC vector
230  */
231 
232 size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst,
233                               int16_t* decoded,
234                               size_t noOfLostFrames);
235 
236 /****************************************************************************
237  * WebRtcIlbcfix_version(...)
238  *
239  * This function returns the version number of iLBC
240  *
241  * Output:
242  *      - version           : Version number of iLBC (maximum 20 char)
243  */
244 
245 void WebRtcIlbcfix_version(char* version);
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif  // MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
252