Home | History | Annotate | Download | only in include
      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 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INTERFACE_WEBRTC_CNG_H_
     13 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INTERFACE_WEBRTC_CNG_H_
     14 
     15 #include "webrtc/typedefs.h"
     16 
     17 #ifdef __cplusplus
     18 extern "C" {
     19 #endif
     20 
     21 #define WEBRTC_CNG_MAX_LPC_ORDER 12
     22 #define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640
     23 
     24 /* Define Error codes. */
     25 
     26 /* 6100 Encoder */
     27 #define CNG_ENCODER_NOT_INITIATED               6120
     28 #define CNG_DISALLOWED_LPC_ORDER                6130
     29 #define CNG_DISALLOWED_FRAME_SIZE               6140
     30 #define CNG_DISALLOWED_SAMPLING_FREQUENCY       6150
     31 /* 6200 Decoder */
     32 #define CNG_DECODER_NOT_INITIATED               6220
     33 
     34 typedef struct WebRtcCngEncInst CNG_enc_inst;
     35 typedef struct WebRtcCngDecInst CNG_dec_inst;
     36 
     37 /****************************************************************************
     38  * WebRtcCng_CreateEnc/Dec(...)
     39  *
     40  * These functions create an instance to the specified structure
     41  *
     42  * Input:
     43  *    - XXX_inst      : Pointer to created instance that should be created
     44  *
     45  * Return value       :  0 - Ok
     46  *                      -1 - Error
     47  */
     48 int16_t WebRtcCng_CreateEnc(CNG_enc_inst** cng_inst);
     49 int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst);
     50 
     51 /****************************************************************************
     52  * WebRtcCng_InitEnc/Dec(...)
     53  *
     54  * This function initializes a instance
     55  *
     56  * Input:
     57  *    - cng_inst      : Instance that should be initialized
     58  *
     59  *    - fs            : 8000 for narrowband and 16000 for wideband
     60  *    - interval      : generate SID data every interval ms
     61  *    - quality       : Number of refl. coefs, maximum allowed is 12
     62  *
     63  * Output:
     64  *    - cng_inst      : Initialized instance
     65  *
     66  * Return value       :  0 - Ok
     67  *                      -1 - Error
     68  */
     69 
     70 int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval,
     71                           int16_t quality);
     72 int16_t WebRtcCng_InitDec(CNG_dec_inst* cng_inst);
     73 
     74 /****************************************************************************
     75  * WebRtcCng_FreeEnc/Dec(...)
     76  *
     77  * These functions frees the dynamic memory of a specified instance
     78  *
     79  * Input:
     80  *    - cng_inst      : Pointer to created instance that should be freed
     81  *
     82  * Return value       :  0 - Ok
     83  *                      -1 - Error
     84  */
     85 int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst);
     86 int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst);
     87 
     88 /****************************************************************************
     89  * WebRtcCng_Encode(...)
     90  *
     91  * These functions analyzes background noise
     92  *
     93  * Input:
     94  *    - cng_inst      : Pointer to created instance
     95  *    - speech        : Signal to be analyzed
     96  *    - nrOfSamples   : Size of speech vector
     97  *    - forceSID      : not zero to force SID frame and reset
     98  *
     99  * Output:
    100  *    - bytesOut      : Nr of bytes to transmit, might be 0
    101  *
    102  * Return value       :  0 - Ok
    103  *                      -1 - Error
    104  */
    105 int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech,
    106                          int16_t nrOfSamples, uint8_t* SIDdata,
    107                          int16_t* bytesOut, int16_t forceSID);
    108 
    109 /****************************************************************************
    110  * WebRtcCng_UpdateSid(...)
    111  *
    112  * These functions updates the CN state, when a new SID packet arrives
    113  *
    114  * Input:
    115  *    - cng_inst      : Pointer to created instance that should be freed
    116  *    - SID           : SID packet, all headers removed
    117  *    - length        : Length in bytes of SID packet
    118  *
    119  * Return value       :  0 - Ok
    120  *                      -1 - Error
    121  */
    122 int16_t WebRtcCng_UpdateSid(CNG_dec_inst* cng_inst, uint8_t* SID,
    123                             int16_t length);
    124 
    125 /****************************************************************************
    126  * WebRtcCng_Generate(...)
    127  *
    128  * These functions generates CN data when needed
    129  *
    130  * Input:
    131  *    - cng_inst      : Pointer to created instance that should be freed
    132  *    - outData       : pointer to area to write CN data
    133  *    - nrOfSamples   : How much data to generate
    134  *    - new_period    : >0 if a new period of CNG, will reset history
    135  *
    136  * Return value       :  0 - Ok
    137  *                      -1 - Error
    138  */
    139 int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData,
    140                            int16_t nrOfSamples, int16_t new_period);
    141 
    142 /*****************************************************************************
    143  * WebRtcCng_GetErrorCodeEnc/Dec(...)
    144  *
    145  * This functions can be used to check the error code of a CNG instance. When
    146  * a function returns -1 a error code will be set for that instance. The
    147  * function below extract the code of the last error that occurred in the
    148  * specified instance.
    149  *
    150  * Input:
    151  *    - CNG_inst    : CNG enc/dec instance
    152  *
    153  * Return value     : Error code
    154  */
    155 int16_t WebRtcCng_GetErrorCodeEnc(CNG_enc_inst* cng_inst);
    156 int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst);
    157 
    158 #ifdef __cplusplus
    159 }
    160 #endif
    161 
    162 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_INTERFACE_WEBRTC_CNG_H_
    163