Home | History | Annotate | Download | only in interface
      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 /*
     12  * ilbc.h
     13  *
     14  * This header file contains all of the API's for iLBC.
     15  *
     16  */
     17 
     18 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_INTERFACE_ILBC_H_
     19 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_INTERFACE_ILBC_H_
     20 
     21 /*
     22  * Define the fixpoint numeric formats
     23  */
     24 
     25 #include "typedefs.h"
     26 
     27 /*
     28  * Solution to support multiple instances
     29  * Customer has to cast instance to proper type
     30  */
     31 
     32 typedef struct iLBC_encinst_t_ iLBC_encinst_t;
     33 
     34 typedef struct iLBC_decinst_t_ iLBC_decinst_t;
     35 
     36 /*
     37  * Comfort noise constants
     38  */
     39 
     40 #define ILBC_SPEECH 1
     41 #define ILBC_CNG  2
     42 
     43 #ifdef __cplusplus
     44 extern "C" {
     45 #endif
     46 
     47   /****************************************************************************
     48    * WebRtcIlbcfix_XxxAssign(...)
     49    *
     50    * These functions assigns the encoder/decoder instance to the specified
     51    * memory location
     52    *
     53    * Input:
     54    *      - XXX_xxxinst       : Pointer to created instance that should be
     55    *                            assigned
     56    *      - ILBCXXX_inst_Addr : Pointer to the desired memory space
     57    *      - size              : The size that this structure occupies (in Word16)
     58    *
     59    * Return value             :  0 - Ok
     60    *                            -1 - Error
     61    */
     62 
     63   int16_t WebRtcIlbcfix_EncoderAssign(iLBC_encinst_t **iLBC_encinst,
     64                                       int16_t *ILBCENC_inst_Addr,
     65                                       int16_t *size);
     66   int16_t WebRtcIlbcfix_DecoderAssign(iLBC_decinst_t **iLBC_decinst,
     67                                       int16_t *ILBCDEC_inst_Addr,
     68                                       int16_t *size);
     69 
     70 
     71   /****************************************************************************
     72    * WebRtcIlbcfix_XxxAssign(...)
     73    *
     74    * These functions create a instance to the specified structure
     75    *
     76    * Input:
     77    *      - XXX_inst          : Pointer to created instance that should be created
     78    *
     79    * Return value             :  0 - Ok
     80    *                            -1 - Error
     81    */
     82 
     83   int16_t WebRtcIlbcfix_EncoderCreate(iLBC_encinst_t **iLBC_encinst);
     84   int16_t WebRtcIlbcfix_DecoderCreate(iLBC_decinst_t **iLBC_decinst);
     85 
     86   /****************************************************************************
     87    * WebRtcIlbcfix_XxxFree(...)
     88    *
     89    * These functions frees the dynamic memory of a specified instance
     90    *
     91    * Input:
     92    *      - XXX_inst          : Pointer to created instance that should be freed
     93    *
     94    * Return value             :  0 - Ok
     95    *                            -1 - Error
     96    */
     97 
     98   int16_t WebRtcIlbcfix_EncoderFree(iLBC_encinst_t *iLBC_encinst);
     99   int16_t WebRtcIlbcfix_DecoderFree(iLBC_decinst_t *iLBC_decinst);
    100 
    101 
    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    */
    115 
    116   int16_t WebRtcIlbcfix_EncoderInit(iLBC_encinst_t *iLBCenc_inst,
    117                                     int16_t frameLen);
    118 
    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    */
    137 
    138   int16_t WebRtcIlbcfix_Encode(iLBC_encinst_t *iLBCenc_inst,
    139                                const int16_t *speechIn,
    140                                int16_t len,
    141                                int16_t *encoded);
    142 
    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    *      - iLBC_decinst_t    : iLBC instance, i.e. the user that should receive
    152    *                            be initialized
    153    *      - frameLen          : The frame length of the codec 20/30 (ms)
    154    *
    155    * Return value             :  0 - Ok
    156    *                            -1 - Error
    157    */
    158 
    159   int16_t WebRtcIlbcfix_DecoderInit(iLBC_decinst_t *iLBCdec_inst,
    160                                     int16_t frameLen);
    161   int16_t WebRtcIlbcfix_DecoderInit20Ms(iLBC_decinst_t *iLBCdec_inst);
    162   int16_t WebRtcIlbcfix_Decoderinit30Ms(iLBC_decinst_t *iLBCdec_inst);
    163 
    164   /****************************************************************************
    165    * WebRtcIlbcfix_Decode(...)
    166    *
    167    * This function decodes a packet with iLBC frame(s). Output speech length
    168    * will be a multiple of 160 or 240 samples ((160 or 240)*frames/packet).
    169    *
    170    * Input:
    171    *      - iLBCdec_inst      : iLBC instance, i.e. the user that should decode
    172    *                            a packet
    173    *      - encoded           : Encoded iLBC frame(s)
    174    *      - len               : Bytes in encoded vector
    175    *
    176    * Output:
    177    *      - decoded           : The decoded vector
    178    *      - speechType        : 1 normal, 2 CNG
    179    *
    180    * Return value             : >0 - Samples in decoded vector
    181    *                            -1 - Error
    182    */
    183 
    184   int16_t WebRtcIlbcfix_Decode(iLBC_decinst_t *iLBCdec_inst,
    185                                const int16_t* encoded,
    186                                int16_t len,
    187                                int16_t *decoded,
    188                                int16_t *speechType);
    189   int16_t WebRtcIlbcfix_Decode20Ms(iLBC_decinst_t *iLBCdec_inst,
    190                                    const int16_t *encoded,
    191                                    int16_t len,
    192                                    int16_t *decoded,
    193                                    int16_t *speechType);
    194   int16_t WebRtcIlbcfix_Decode30Ms(iLBC_decinst_t *iLBCdec_inst,
    195                                    const int16_t *encoded,
    196                                    int16_t len,
    197                                    int16_t *decoded,
    198                                    int16_t *speechType);
    199 
    200   /****************************************************************************
    201    * WebRtcIlbcfix_DecodePlc(...)
    202    *
    203    * This function conducts PLC for iLBC frame(s). Output speech length
    204    * will be a multiple of 160 or 240 samples.
    205    *
    206    * Input:
    207    *      - iLBCdec_inst      : iLBC instance, i.e. the user that should perform
    208    *                            a PLC
    209    *      - noOfLostFrames    : Number of PLC frames to produce
    210    *
    211    * Output:
    212    *      - decoded           : The "decoded" vector
    213    *
    214    * Return value             : >0 - Samples in decoded PLC vector
    215    *                            -1 - Error
    216    */
    217 
    218   int16_t WebRtcIlbcfix_DecodePlc(iLBC_decinst_t *iLBCdec_inst,
    219                                   int16_t *decoded,
    220                                   int16_t noOfLostFrames);
    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    *
    236    * Return value             : >0 - Samples in decoded PLC vector
    237    *                            -1 - Error
    238    */
    239 
    240   int16_t WebRtcIlbcfix_NetEqPlc(iLBC_decinst_t *iLBCdec_inst,
    241                                  int16_t *decoded,
    242                                  int16_t noOfLostFrames);
    243 
    244   /****************************************************************************
    245    * WebRtcIlbcfix_version(...)
    246    *
    247    * This function returns the version number of iLBC
    248    *
    249    * Output:
    250    *      - version           : Version number of iLBC (maximum 20 char)
    251    */
    252 
    253   void WebRtcIlbcfix_version(char *version);
    254 
    255 #ifdef __cplusplus
    256 }
    257 #endif
    258 
    259 #endif
    260