niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 91b359e | 2012-02-28 17:26:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #ifndef MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_ |
| 19 | #define MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 21 | #include <stddef.h> |
| 22 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | /* |
| 24 | * Define the fixpoint numeric formats |
| 25 | */ |
| 26 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 27 | #include "typedefs.h" // NOLINT(build/include) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Solution to support multiple instances |
| 31 | * Customer has to cast instance to proper type |
| 32 | */ |
| 33 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 34 | typedef struct iLBC_encinst_t_ IlbcEncoderInstance; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 36 | typedef struct iLBC_decinst_t_ IlbcDecoderInstance; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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: |
kjellander@webrtc.org | 3c652b6 | 2015-11-18 23:07:57 +0100 | [diff] [blame] | 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) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | * |
| 61 | * Return value : 0 - Ok |
| 62 | * -1 - Error |
| 63 | */ |
| 64 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 65 | int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance **iLBC_encinst, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 66 | int16_t *ILBCENC_inst_Addr, |
| 67 | int16_t *size); |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 68 | int16_t WebRtcIlbcfix_DecoderAssign(IlbcDecoderInstance **iLBC_decinst, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 69 | int16_t *ILBCDEC_inst_Addr, |
| 70 | int16_t *size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
| 72 | |
| 73 | /**************************************************************************** |
| 74 | * WebRtcIlbcfix_XxxAssign(...) |
| 75 | * |
| 76 | * These functions create a instance to the specified structure |
| 77 | * |
| 78 | * Input: |
kjellander@webrtc.org | 3c652b6 | 2015-11-18 23:07:57 +0100 | [diff] [blame] | 79 | * - XXX_inst : Pointer to created instance that should be created |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | * |
kjellander@webrtc.org | 3c652b6 | 2015-11-18 23:07:57 +0100 | [diff] [blame] | 81 | * Return value : 0 - Ok |
| 82 | * -1 - Error |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | */ |
| 84 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 85 | int16_t WebRtcIlbcfix_EncoderCreate(IlbcEncoderInstance **iLBC_encinst); |
| 86 | int16_t WebRtcIlbcfix_DecoderCreate(IlbcDecoderInstance **iLBC_decinst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 100 | int16_t WebRtcIlbcfix_EncoderFree(IlbcEncoderInstance *iLBC_encinst); |
| 101 | int16_t WebRtcIlbcfix_DecoderFree(IlbcDecoderInstance *iLBC_decinst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 118 | int16_t WebRtcIlbcfix_EncoderInit(IlbcEncoderInstance *iLBCenc_inst, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 119 | int16_t frameLen); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 140 | int WebRtcIlbcfix_Encode(IlbcEncoderInstance *iLBCenc_inst, |
| 141 | const int16_t *speechIn, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 142 | size_t len, |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 143 | uint8_t* encoded); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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: |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 153 | * - IlbcDecoderInstance : iLBC decoder instance |
| 154 | * - frameLen : The frame length of the codec 20/30 (ms) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | * |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 156 | * Return value : 0 - Ok |
| 157 | * -1 - Error |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | */ |
| 159 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 160 | int16_t WebRtcIlbcfix_DecoderInit(IlbcDecoderInstance *iLBCdec_inst, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 161 | int16_t frameLen); |
Karl Wiberg | 4376648 | 2015-08-27 15:22:11 +0200 | [diff] [blame] | 162 | void WebRtcIlbcfix_DecoderInit20Ms(IlbcDecoderInstance* iLBCdec_inst); |
| 163 | void WebRtcIlbcfix_Decoderinit30Ms(IlbcDecoderInstance* iLBCdec_inst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 185 | int WebRtcIlbcfix_Decode(IlbcDecoderInstance* iLBCdec_inst, |
| 186 | const uint8_t* encoded, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 187 | size_t len, |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 188 | int16_t* decoded, |
| 189 | int16_t* speechType); |
| 190 | int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst, |
jmarusic@webrtc.org | 71b35a4 | 2015-02-17 16:02:18 +0000 | [diff] [blame] | 191 | const uint8_t* encoded, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 192 | size_t len, |
jmarusic@webrtc.org | 71b35a4 | 2015-02-17 16:02:18 +0000 | [diff] [blame] | 193 | int16_t* decoded, |
| 194 | int16_t* speechType); |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 195 | int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst, |
| 196 | const uint8_t* encoded, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 197 | size_t len, |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 198 | int16_t* decoded, |
| 199 | int16_t* speechType); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | * |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 215 | * Return value : Samples in decoded PLC vector |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | */ |
| 217 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 218 | size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance *iLBCdec_inst, |
| 219 | int16_t *decoded, |
| 220 | size_t noOfLostFrames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | * |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 236 | * Return value : Samples in decoded PLC vector |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 237 | */ |
| 238 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 239 | size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance *iLBCdec_inst, |
| 240 | int16_t *decoded, |
| 241 | size_t noOfLostFrames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
leozwang@webrtc.org | 91b359e | 2012-02-28 17:26:14 +0000 | [diff] [blame] | 252 | void WebRtcIlbcfix_version(char *version); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | |
| 254 | #ifdef __cplusplus |
| 255 | } |
| 256 | #endif |
| 257 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 258 | #endif // MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_ |