ilbc/ilbc.h

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.1.1.1 2008/02/15 12:15:55 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 ilbc_encode_state_t *ilbc_encode_init(ilbc_encode_state_t *s,    /* (i/o) Encoder instance */
00138                                       int mode);                 /* (i) frame size mode */
00139 
00140 int ilbc_encode(ilbc_encode_state_t *s,         /* (i/o) the general encoder state */
00141                 uint8_t bytes[],                /* (o) encoded data bits iLBC */
00142                 const int16_t amp[],            /* (o) speech vector to encode */
00143                 int len);
00144 
00145 ilbc_decode_state_t *ilbc_decode_init(ilbc_decode_state_t *s,   /* (i/o) Decoder instance */
00146                                       int mode,                 /* (i) frame size mode */
00147                                       int use_enhancer);        /* (i) 1 to use enhancer
00148                                                                        0 to run without enhancer */
00149 
00150 int ilbc_decode(ilbc_decode_state_t *s,     /* (i/o) the decoder state structure */
00151                 int16_t amp[],              /* (o) decoded signal block */
00152                 const uint8_t bytes[],      /* (i) encoded signal bits */
00153                 int len);
00154 
00155 int ilbc_fillin(ilbc_decode_state_t *s,     /* (i/o) the decoder state structure */
00156                 int16_t amp[],              /* (o) decoded signal block */
00157                 int len);
00158 
00159 #endif

Generated on Sat May 23 12:24:23 2009 for libvoipcodecs by  doxygen 1.5.5