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> |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 22 | #include <stdint.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Solution to support multiple instances |
| 26 | * Customer has to cast instance to proper type |
| 27 | */ |
| 28 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 29 | typedef struct iLBC_encinst_t_ IlbcEncoderInstance; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
pbos@webrtc.org | e728ee0 | 2014-12-17 13:43:55 +0000 | [diff] [blame] | 31 | typedef struct iLBC_decinst_t_ IlbcDecoderInstance; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Comfort noise constants |
| 35 | */ |
| 36 | |
| 37 | #define ILBC_SPEECH 1 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 38 | #define ILBC_CNG 2 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 79 | int16_t WebRtcIlbcfix_EncoderCreate(IlbcEncoderInstance** iLBC_encinst); |
| 80 | int16_t WebRtcIlbcfix_DecoderCreate(IlbcDecoderInstance** iLBC_decinst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 94 | int16_t WebRtcIlbcfix_EncoderFree(IlbcEncoderInstance* iLBC_encinst); |
| 95 | int16_t WebRtcIlbcfix_DecoderFree(IlbcDecoderInstance* iLBC_decinst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 111 | int16_t WebRtcIlbcfix_EncoderInit(IlbcEncoderInstance* iLBCenc_inst, |
| 112 | int16_t frameLen); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 133 | int WebRtcIlbcfix_Encode(IlbcEncoderInstance* iLBCenc_inst, |
| 134 | const int16_t* speechIn, |
| 135 | size_t len, |
| 136 | uint8_t* encoded); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 193 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 211 | size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst, |
jmarusic@webrtc.org | 71b35a4 | 2015-02-17 16:02:18 +0000 | [diff] [blame] | 212 | int16_t* decoded, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 213 | size_t noOfLostFrames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 232 | size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst, |
| 233 | int16_t* decoded, |
| 234 | size_t noOfLostFrames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 235 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 244 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 245 | void WebRtcIlbcfix_version(char* version); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 246 | |
| 247 | #ifdef __cplusplus |
| 248 | } |
| 249 | #endif |
| 250 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 251 | #endif // MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_ |