libilbc
0.0.1
|
00001 /* 00002 * iLBC - a library for the iLBC codec 00003 * 00004 * ilbc.h - The iLBC low bit rate speech codec. 00005 * 00006 * Adapted by Steve Underwood <steveu@coppice.org> from the reference 00007 * iLBC code supplied in RFC3951. 00008 * 00009 * Copyright (C) The Internet Society (2004). 00010 * All Rights Reserved. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 * 00021 * $Id: ilbc.h,v 1.2 2008/10/02 12:00:56 steveu Exp $ 00022 */ 00023 00024 #if !defined(_ILBC_ILBC_H_) 00025 #define _ILBC_ILBC_H_ 00026 00027 #define ILBC_BLOCK_LEN_20MS 160 00028 #define ILBC_BLOCK_LEN_30MS 240 00029 #define ILBC_BLOCK_LEN_MAX 240 00030 00031 #define ILBC_NO_OF_BYTES_20MS 38 00032 #define ILBC_NO_OF_BYTES_30MS 50 00033 #define ILBC_NO_OF_BYTES_MAX 50 00034 00035 #define ILBC_NUM_SUB_MAX 6 00036 00037 #define SUBL 40 00038 00039 #define ENH_BLOCKL 80 /* block length */ 00040 #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + ENH_NBLOCKS_EXTRA */ 00041 #define ENH_BUFL (ENH_NBLOCKS_TOT*ENH_BLOCKL) 00042 00043 #define ILBC_LPC_FILTERORDER 10 00044 #define LPC_LOOKBACK 60 00045 00046 #define CB_NSTAGES 3 00047 00048 #define STATE_BITS 3 00049 #define BYTE_LEN 8 00050 #define ILBC_ULP_CLASSES 3 00051 00052 typedef struct 00053 { 00054 int lsf_bits[6][ILBC_ULP_CLASSES + 2]; 00055 int start_bits[ILBC_ULP_CLASSES + 2]; 00056 int startfirst_bits[ILBC_ULP_CLASSES + 2]; 00057 int scale_bits[ILBC_ULP_CLASSES + 2]; 00058 int state_bits[ILBC_ULP_CLASSES + 2]; 00059 int extra_cb_index[CB_NSTAGES][ILBC_ULP_CLASSES + 2]; 00060 int extra_cb_gain[CB_NSTAGES][ILBC_ULP_CLASSES + 2]; 00061 int cb_index[ILBC_NUM_SUB_MAX][CB_NSTAGES][ILBC_ULP_CLASSES + 2]; 00062 int cb_gain[ILBC_NUM_SUB_MAX][CB_NSTAGES][ILBC_ULP_CLASSES + 2]; 00063 } ilbc_ulp_inst_t; 00064 00065 /* Type definition encoder instance */ 00066 typedef struct 00067 { 00068 /* flag for frame size mode */ 00069 int mode; 00070 00071 /* basic parameters for different frame sizes */ 00072 int blockl; 00073 int nsub; 00074 int nasub; 00075 int no_of_bytes; 00076 int lpc_n; 00077 int state_short_len; 00078 const ilbc_ulp_inst_t *ULP_inst; 00079 00080 /* analysis filter state */ 00081 float anaMem[ILBC_LPC_FILTERORDER]; 00082 00083 /* old lsf parameters for interpolation */ 00084 float lsfold[ILBC_LPC_FILTERORDER]; 00085 float lsfdeqold[ILBC_LPC_FILTERORDER]; 00086 00087 /* signal buffer for LP analysis */ 00088 float lpc_buffer[LPC_LOOKBACK + ILBC_BLOCK_LEN_MAX]; 00089 00090 /* state of input HP filter */ 00091 float hpimem[4]; 00092 } ilbc_encode_state_t; 00093 00094 /* Type definition decoder instance */ 00095 typedef struct 00096 { 00097 /* Flag for frame size mode */ 00098 int mode; 00099 00100 /* Basic parameters for different frame sizes */ 00101 int blockl; 00102 int nsub; 00103 int nasub; 00104 int no_of_bytes; 00105 int lpc_n; 00106 int state_short_len; 00107 const ilbc_ulp_inst_t *ULP_inst; 00108 00109 /* Synthesis filter state */ 00110 float syntMem[ILBC_LPC_FILTERORDER]; 00111 00112 /* Old LSF for interpolation */ 00113 float lsfdeqold[ILBC_LPC_FILTERORDER]; 00114 00115 /* Pitch lag estimated in enhancer and used in PLC */ 00116 int last_lag; 00117 00118 /* PLC state information */ 00119 int prevLag, consPLICount, prevPLI, prev_enh_pl; 00120 float prevLpc[ILBC_LPC_FILTERORDER + 1]; 00121 float prevResidual[ILBC_NUM_SUB_MAX*SUBL]; 00122 float per; 00123 unsigned long seed; 00124 00125 /* Previous synthesis filter parameters */ 00126 float old_syntdenum[(ILBC_LPC_FILTERORDER + 1)*ILBC_NUM_SUB_MAX]; 00127 00128 /* State of output HP filter */ 00129 float hpomem[4]; 00130 00131 /* Enhancer state information */ 00132 int use_enhancer; 00133 float enh_buf[ENH_BUFL]; 00134 float enh_period[ENH_NBLOCKS_TOT]; 00135 } ilbc_decode_state_t; 00136 00137 #if defined(__cplusplus) 00138 extern "C" 00139 { 00140 #endif 00141 00142 /*! Initialise an iLBC encode context. 00143 \param s The iLBC encode context. 00144 \param mode The frame size. 00145 \return A pointer to the iLBC encode context, or NULL for error. */ 00146 ilbc_encode_state_t *ilbc_encode_init(ilbc_encode_state_t *s, 00147 int mode); 00148 00149 int ilbc_encode_release(ilbc_encode_state_t *s); 00150 00151 /*! Encode a buffer of linear PCM data to iLBC 00152 \param s The iLBC encode context. 00153 \param bytes The iLBC data produced. 00154 \param amp The audio sample buffer. 00155 \param len The number of samples in the buffer. 00156 \return The number of bytes of iLBC data produced. */ 00157 int ilbc_encode(ilbc_encode_state_t *s, 00158 uint8_t bytes[], 00159 const int16_t amp[], 00160 int len); 00161 00162 /*! Initialise an iLBC decode context. 00163 \param s The iLBC decode context. 00164 \param mode The frame size. 00165 \param use_enhancer TRUE to use the audio enhancer option. 00166 \return A pointer to the iLBC decode context, or NULL for error. */ 00167 ilbc_decode_state_t *ilbc_decode_init(ilbc_decode_state_t *s, 00168 int mode, 00169 int use_enhancer); 00170 00171 int ilbc_decode_release(ilbc_decode_state_t *s); 00172 00173 /*! Decode a buffer of iLBC data to linear PCM. 00174 \param s The iLBC deocde context. 00175 \param amp The audio sample buffer. 00176 \param bytes The excoded data. 00177 \param len The length of the encoded data, in bytes. 00178 \return The number of samples returned. */ 00179 int ilbc_decode(ilbc_decode_state_t *s, 00180 int16_t amp[], 00181 const uint8_t bytes[], 00182 int len); 00183 00184 /*! Produce linear PCM data to fill in where received iLBC data is missing. 00185 \param s The iLBC context. 00186 \param amp The audio sample buffer. 00187 \param len 00188 \return The number of samples returned. */ 00189 int ilbc_fillin(ilbc_decode_state_t *s, 00190 int16_t amp[], 00191 int len); 00192 00193 #if defined(__cplusplus) 00194 } 00195 #endif 00196 00197 #endif 00198 /*- End of file ------------------------------------------------------------*/