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