ilbc.h 8.2 KB

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