blob: 4c12665db791616f1fc0af530a302a656c1587ba [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org91b359e2012-02-28 17:26:14 +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 * ilbc.h
13 *
14 * This header file contains all of the API's for iLBC.
15 *
16 */
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#ifndef MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
19#define MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000020
Peter Kastingdce40cf2015-08-24 14:52:23 -070021#include <stddef.h>
22
niklase@google.com470e71d2011-07-07 08:21:25 +000023/*
24 * Define the fixpoint numeric formats
25 */
26
Mirko Bonadei71207422017-09-15 13:58:09 +020027#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000028
29/*
30 * Solution to support multiple instances
31 * Customer has to cast instance to proper type
32 */
33
pbos@webrtc.orge728ee02014-12-17 13:43:55 +000034typedef struct iLBC_encinst_t_ IlbcEncoderInstance;
niklase@google.com470e71d2011-07-07 08:21:25 +000035
pbos@webrtc.orge728ee02014-12-17 13:43:55 +000036typedef struct iLBC_decinst_t_ IlbcDecoderInstance;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
38/*
39 * Comfort noise constants
40 */
41
42#define ILBC_SPEECH 1
Yves Gerey665174f2018-06-19 15:03:05 +020043#define ILBC_CNG 2
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45#ifdef __cplusplus
46extern "C" {
47#endif
48
Yves Gerey665174f2018-06-19 15:03:05 +020049/****************************************************************************
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 */
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Yves Gerey665174f2018-06-19 15:03:05 +020065int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance** iLBC_encinst,
66 int16_t* ILBCENC_inst_Addr,
67 int16_t* size);
68int16_t WebRtcIlbcfix_DecoderAssign(IlbcDecoderInstance** iLBC_decinst,
69 int16_t* ILBCDEC_inst_Addr,
70 int16_t* size);
niklase@google.com470e71d2011-07-07 08:21:25 +000071
Yves Gerey665174f2018-06-19 15:03:05 +020072/****************************************************************************
73 * WebRtcIlbcfix_XxxAssign(...)
74 *
75 * These functions create a instance to the specified structure
76 *
77 * Input:
78 * - XXX_inst : Pointer to created instance that should be created
79 *
80 * Return value : 0 - Ok
81 * -1 - Error
82 */
niklase@google.com470e71d2011-07-07 08:21:25 +000083
Yves Gerey665174f2018-06-19 15:03:05 +020084int16_t WebRtcIlbcfix_EncoderCreate(IlbcEncoderInstance** iLBC_encinst);
85int16_t WebRtcIlbcfix_DecoderCreate(IlbcDecoderInstance** iLBC_decinst);
niklase@google.com470e71d2011-07-07 08:21:25 +000086
Yves Gerey665174f2018-06-19 15:03:05 +020087/****************************************************************************
88 * WebRtcIlbcfix_XxxFree(...)
89 *
90 * These functions frees the dynamic memory of a specified instance
91 *
92 * Input:
93 * - XXX_inst : Pointer to created instance that should be freed
94 *
95 * Return value : 0 - Ok
96 * -1 - Error
97 */
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Yves Gerey665174f2018-06-19 15:03:05 +020099int16_t WebRtcIlbcfix_EncoderFree(IlbcEncoderInstance* iLBC_encinst);
100int16_t WebRtcIlbcfix_DecoderFree(IlbcDecoderInstance* iLBC_decinst);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
Yves Gerey665174f2018-06-19 15:03:05 +0200102/****************************************************************************
103 * WebRtcIlbcfix_EncoderInit(...)
104 *
105 * This function initializes a iLBC instance
106 *
107 * Input:
108 * - iLBCenc_inst : iLBC instance, i.e. the user that should receive
109 * be initialized
110 * - frameLen : The frame length of the codec 20/30 (ms)
111 *
112 * Return value : 0 - Ok
113 * -1 - Error
114 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
Yves Gerey665174f2018-06-19 15:03:05 +0200116int16_t WebRtcIlbcfix_EncoderInit(IlbcEncoderInstance* iLBCenc_inst,
117 int16_t frameLen);
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
Yves Gerey665174f2018-06-19 15:03:05 +0200119/****************************************************************************
120 * WebRtcIlbcfix_Encode(...)
121 *
122 * This function encodes one iLBC frame. Input speech length has be a
123 * multiple of the frame length.
124 *
125 * Input:
126 * - iLBCenc_inst : iLBC instance, i.e. the user that should encode
127 * a package
128 * - speechIn : Input speech vector
129 * - len : Samples in speechIn (160, 240, 320 or 480)
130 *
131 * Output:
132 * - encoded : The encoded data vector
133 *
134 * Return value : >0 - Length (in bytes) of coded data
135 * -1 - Error
136 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
Yves Gerey665174f2018-06-19 15:03:05 +0200138int WebRtcIlbcfix_Encode(IlbcEncoderInstance* iLBCenc_inst,
139 const int16_t* speechIn,
140 size_t len,
141 uint8_t* encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
Yves Gerey665174f2018-06-19 15:03:05 +0200143/****************************************************************************
144 * WebRtcIlbcfix_DecoderInit(...)
145 *
146 * This function initializes a iLBC instance with either 20 or 30 ms frames
147 * Alternatively the WebRtcIlbcfix_DecoderInit_XXms can be used. Then it's
148 * not needed to specify the frame length with a variable.
149 *
150 * Input:
151 * - IlbcDecoderInstance : iLBC decoder instance
152 * - frameLen : The frame length of the codec 20/30 (ms)
153 *
154 * Return value : 0 - Ok
155 * -1 - Error
156 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
Yves Gerey665174f2018-06-19 15:03:05 +0200158int16_t WebRtcIlbcfix_DecoderInit(IlbcDecoderInstance* iLBCdec_inst,
159 int16_t frameLen);
160void WebRtcIlbcfix_DecoderInit20Ms(IlbcDecoderInstance* iLBCdec_inst);
161void WebRtcIlbcfix_Decoderinit30Ms(IlbcDecoderInstance* iLBCdec_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
Yves Gerey665174f2018-06-19 15:03:05 +0200163/****************************************************************************
164 * WebRtcIlbcfix_Decode(...)
165 *
166 * This function decodes a packet with iLBC frame(s). Output speech length
167 * will be a multiple of 160 or 240 samples ((160 or 240)*frames/packet).
168 *
169 * Input:
170 * - iLBCdec_inst : iLBC instance, i.e. the user that should decode
171 * a packet
172 * - encoded : Encoded iLBC frame(s)
173 * - len : Bytes in encoded vector
174 *
175 * Output:
176 * - decoded : The decoded vector
177 * - speechType : 1 normal, 2 CNG
178 *
179 * Return value : >0 - Samples in decoded vector
180 * -1 - Error
181 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
Yves Gerey665174f2018-06-19 15:03:05 +0200183int WebRtcIlbcfix_Decode(IlbcDecoderInstance* iLBCdec_inst,
184 const uint8_t* encoded,
185 size_t len,
186 int16_t* decoded,
187 int16_t* speechType);
188int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst,
189 const uint8_t* encoded,
190 size_t len,
191 int16_t* decoded,
192 int16_t* speechType);
193int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst,
194 const uint8_t* encoded,
195 size_t len,
196 int16_t* decoded,
197 int16_t* speechType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
Yves Gerey665174f2018-06-19 15:03:05 +0200199/****************************************************************************
200 * WebRtcIlbcfix_DecodePlc(...)
201 *
202 * This function conducts PLC for iLBC frame(s). Output speech length
203 * will be a multiple of 160 or 240 samples.
204 *
205 * Input:
206 * - iLBCdec_inst : iLBC instance, i.e. the user that should perform
207 * a PLC
208 * - noOfLostFrames : Number of PLC frames to produce
209 *
210 * Output:
211 * - decoded : The "decoded" vector
212 *
213 * Return value : Samples in decoded PLC vector
214 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000215
Yves Gerey665174f2018-06-19 15:03:05 +0200216size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst,
jmarusic@webrtc.org71b35a42015-02-17 16:02:18 +0000217 int16_t* decoded,
Yves Gerey665174f2018-06-19 15:03:05 +0200218 size_t noOfLostFrames);
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
Yves Gerey665174f2018-06-19 15:03:05 +0200220/****************************************************************************
221 * WebRtcIlbcfix_NetEqPlc(...)
222 *
223 * This function updates the decoder when a packet loss has occured, but it
224 * does not produce any PLC data. Function can be used if another PLC method
225 * is used (i.e NetEq).
226 *
227 * Input:
228 * - iLBCdec_inst : iLBC instance that should be updated
229 * - noOfLostFrames : Number of lost frames
230 *
231 * Output:
232 * - decoded : The "decoded" vector (nothing in this case)
233 *
234 * Return value : Samples in decoded PLC vector
235 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
Yves Gerey665174f2018-06-19 15:03:05 +0200237size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst,
238 int16_t* decoded,
239 size_t noOfLostFrames);
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
Yves Gerey665174f2018-06-19 15:03:05 +0200241/****************************************************************************
242 * WebRtcIlbcfix_version(...)
243 *
244 * This function returns the version number of iLBC
245 *
246 * Output:
247 * - version : Version number of iLBC (maximum 20 char)
248 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000249
Yves Gerey665174f2018-06-19 15:03:05 +0200250void WebRtcIlbcfix_version(char* version);
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
252#ifdef __cplusplus
253}
254#endif
255
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200256#endif // MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_