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 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 43 | #define ILBC_CNG 2 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
| 45 | #ifdef __cplusplus |
| 46 | extern "C" { |
| 47 | #endif |
| 48 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 | */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 72 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 84 | int16_t WebRtcIlbcfix_EncoderCreate(IlbcEncoderInstance** iLBC_encinst); |
| 85 | int16_t WebRtcIlbcfix_DecoderCreate(IlbcDecoderInstance** iLBC_decinst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 87 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 99 | int16_t WebRtcIlbcfix_EncoderFree(IlbcEncoderInstance* iLBC_encinst); |
| 100 | int16_t WebRtcIlbcfix_DecoderFree(IlbcDecoderInstance* iLBC_decinst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 102 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 116 | int16_t WebRtcIlbcfix_EncoderInit(IlbcEncoderInstance* iLBCenc_inst, |
| 117 | int16_t frameLen); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 119 | /**************************************************************************** |
| 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.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 | int WebRtcIlbcfix_Encode(IlbcEncoderInstance* iLBCenc_inst, |
| 139 | const int16_t* speechIn, |
| 140 | size_t len, |
| 141 | uint8_t* encoded); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 143 | /**************************************************************************** |
| 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.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 | int16_t WebRtcIlbcfix_DecoderInit(IlbcDecoderInstance* iLBCdec_inst, |
| 159 | int16_t frameLen); |
| 160 | void WebRtcIlbcfix_DecoderInit20Ms(IlbcDecoderInstance* iLBCdec_inst); |
| 161 | void WebRtcIlbcfix_Decoderinit30Ms(IlbcDecoderInstance* iLBCdec_inst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 163 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 183 | int WebRtcIlbcfix_Decode(IlbcDecoderInstance* iLBCdec_inst, |
| 184 | const uint8_t* encoded, |
| 185 | size_t len, |
| 186 | int16_t* decoded, |
| 187 | int16_t* speechType); |
| 188 | int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst, |
| 189 | const uint8_t* encoded, |
| 190 | size_t len, |
| 191 | int16_t* decoded, |
| 192 | int16_t* speechType); |
| 193 | int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst, |
| 194 | const uint8_t* encoded, |
| 195 | size_t len, |
| 196 | int16_t* decoded, |
| 197 | int16_t* speechType); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 199 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 215 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 216 | size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst, |
jmarusic@webrtc.org | 71b35a4 | 2015-02-17 16:02:18 +0000 | [diff] [blame] | 217 | int16_t* decoded, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 218 | size_t noOfLostFrames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 219 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 220 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 237 | size_t WebRtcIlbcfix_NetEqPlc(IlbcDecoderInstance* iLBCdec_inst, |
| 238 | int16_t* decoded, |
| 239 | size_t noOfLostFrames); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 240 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 241 | /**************************************************************************** |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 249 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 250 | void WebRtcIlbcfix_version(char* version); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 251 | |
| 252 | #ifdef __cplusplus |
| 253 | } |
| 254 | #endif |
| 255 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 256 | #endif // MODULES_AUDIO_CODING_CODECS_ILBC_ILBC_H_ |