]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update ilbc and lpc10 codecs from openh323 sources.
authorMichael Jerris <mike@jerris.com>
Tue, 27 Dec 2005 18:42:30 +0000 (18:42 +0000)
committerMichael Jerris <mike@jerris.com>
Tue, 27 Dec 2005 18:42:30 +0000 (18:42 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@211 d0543943-73ff-0310-b7d9-9358b9ac24b2

87 files changed:
libs/codec/ilbc/FrameClassify.c
libs/codec/ilbc/FrameClassify.h
libs/codec/ilbc/LPCdecode.c
libs/codec/ilbc/LPCdecode.h
libs/codec/ilbc/LPCencode.c
libs/codec/ilbc/LPCencode.h
libs/codec/ilbc/StateConstructW.c
libs/codec/ilbc/StateConstructW.h
libs/codec/ilbc/StateSearchW.c
libs/codec/ilbc/StateSearchW.h
libs/codec/ilbc/anaFilter.c
libs/codec/ilbc/anaFilter.h
libs/codec/ilbc/constants.c
libs/codec/ilbc/constants.h
libs/codec/ilbc/createCB.c
libs/codec/ilbc/createCB.h
libs/codec/ilbc/doCPLC.c
libs/codec/ilbc/doCPLC.h
libs/codec/ilbc/draft-ietf-avt-ilbc-codec-05.txt [new file with mode: 0644]
libs/codec/ilbc/enhancer.c
libs/codec/ilbc/enhancer.h
libs/codec/ilbc/extract-cfile.awk [new file with mode: 0644]
libs/codec/ilbc/filter.c
libs/codec/ilbc/filter.h
libs/codec/ilbc/gainquant.c
libs/codec/ilbc/gainquant.h
libs/codec/ilbc/getCBvec.c
libs/codec/ilbc/getCBvec.h
libs/codec/ilbc/helpfun.c
libs/codec/ilbc/helpfun.h
libs/codec/ilbc/hpInput.c
libs/codec/ilbc/hpInput.h
libs/codec/ilbc/hpOutput.c
libs/codec/ilbc/hpOutput.h
libs/codec/ilbc/iCBConstruct.c
libs/codec/ilbc/iCBConstruct.h
libs/codec/ilbc/iCBSearch.c
libs/codec/ilbc/iCBSearch.h
libs/codec/ilbc/iLBC_decode.c
libs/codec/ilbc/iLBC_decode.h
libs/codec/ilbc/iLBC_define.h
libs/codec/ilbc/iLBC_encode.c
libs/codec/ilbc/iLBC_encode.h
libs/codec/ilbc/lsf.c
libs/codec/ilbc/lsf.h
libs/codec/ilbc/packing.c
libs/codec/ilbc/packing.h
libs/codec/ilbc/syntFilter.c
libs/codec/ilbc/syntFilter.h
libs/codec/lpc10/Makefile
libs/codec/lpc10/analys.c
libs/codec/lpc10/bsynz.c
libs/codec/lpc10/chanwr.c
libs/codec/lpc10/dcbias.c
libs/codec/lpc10/decode.c
libs/codec/lpc10/deemp.c
libs/codec/lpc10/difmag.c
libs/codec/lpc10/dyptrk.c
libs/codec/lpc10/encode.c
libs/codec/lpc10/energy.c
libs/codec/lpc10/f2c.h
libs/codec/lpc10/f2clib.c
libs/codec/lpc10/ham84.c
libs/codec/lpc10/hp100.c
libs/codec/lpc10/invert.c
libs/codec/lpc10/irc2pc.c
libs/codec/lpc10/ivfilt.c
libs/codec/lpc10/liblpc10.vcproj
libs/codec/lpc10/lpc10.h
libs/codec/lpc10/lpcdec.c
libs/codec/lpc10/lpcenc.c
libs/codec/lpc10/lpcini.c
libs/codec/lpc10/lpfilt.c
libs/codec/lpc10/median.c
libs/codec/lpc10/mload.c
libs/codec/lpc10/onset.c
libs/codec/lpc10/pitsyn.c
libs/codec/lpc10/placea.c
libs/codec/lpc10/placev.c
libs/codec/lpc10/preemp.c
libs/codec/lpc10/prepro.c
libs/codec/lpc10/random.c
libs/codec/lpc10/rcchk.c
libs/codec/lpc10/synths.c
libs/codec/lpc10/tbdm.c
libs/codec/lpc10/voicin.c
libs/codec/lpc10/vparms.c

index 9a6f0293692dc5bd3e87c349a614b8e152b6dc9c..1bb1f2fbf6a5ca589f936a5bd5955ad96382c764 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    FrameClassify.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include "iLBC_define.h"\r
-#include "FrameClassify.h"\r
-\r
-/*---------------------------------------------------------------*\r
- *  Classification of subframes to localize start state\r
- *--------------------------------------------------------------*/\r
-\r
-int FrameClassify(      /* index to the max-energy sub-frame */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst, \r
-                        /* (i/o) the encoder state structure */\r
-    float *residual     /* (i) lpc residual signal */\r
-) {\r
-    float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;\r
-    int n, l, max_ssqEn_n;\r
-    const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,\r
-        (float)1.0,(float)0.9,(float)0.8};\r
-    const float sampEn_win[5]={(float)1.0/(float)6.0, \r
-        (float)2.0/(float)6.0, (float)3.0/(float)6.0,\r
-        (float)4.0/(float)6.0, (float)5.0/(float)6.0};\r
-    \r
-    /* init the front and back energies to zero */\r
-\r
-    memset(fssqEn, 0, NSUB_MAX*sizeof(float));\r
-    memset(bssqEn, 0, NSUB_MAX*sizeof(float));\r
-\r
-    /* Calculate front of first seqence */\r
-\r
-    n=0;\r
-    pp=residual;\r
-\r
-\r
-    for (l=0; l<5; l++) {\r
-        fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
-        pp++;\r
-    }\r
-    for (l=5; l<SUBL; l++) {\r
-        fssqEn[n] += (*pp) * (*pp);\r
-        pp++;\r
-    }\r
-\r
-    /* Calculate front and back of all middle sequences */\r
-\r
-    for (n=1; n<iLBCenc_inst->nsub-1; n++) {\r
-        pp=residual+n*SUBL;\r
-        for (l=0; l<5; l++) {\r
-            fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
-            bssqEn[n] += (*pp) * (*pp);\r
-            pp++;\r
-        }\r
-        for (l=5; l<SUBL-5; l++) {\r
-            fssqEn[n] += (*pp) * (*pp);\r
-            bssqEn[n] += (*pp) * (*pp);\r
-            pp++;\r
-        }\r
-        for (l=SUBL-5; l<SUBL; l++) {\r
-            fssqEn[n] += (*pp) * (*pp);\r
-            bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
-            pp++;\r
-        }\r
-    }\r
-\r
-    /* Calculate back of last seqence */\r
-\r
-    n=iLBCenc_inst->nsub-1;\r
-    pp=residual+n*SUBL;\r
-    for (l=0; l<SUBL-5; l++) {\r
-        bssqEn[n] += (*pp) * (*pp);\r
-        pp++;\r
-    }\r
-    for (l=SUBL-5; l<SUBL; l++) {\r
-        bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
-        pp++;\r
-    }\r
-\r
-    /* find the index to the weighted 80 sample with \r
-       most energy */\r
-\r
-    if (iLBCenc_inst->mode==20) l=1;\r
-    else                        l=0;\r
-\r
-    max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];\r
-    max_ssqEn_n=1;\r
-    for (n=2; n<iLBCenc_inst->nsub; n++) {\r
-\r
-        l++;\r
-\r
-\r
-        if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {\r
-            max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *\r
-                            ssqEn_win[l];\r
-            max_ssqEn_n=n;\r
-        }\r
-    }\r
-\r
-    return max_ssqEn_n;\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       FrameClassify.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  Classification of subframes to localize start state\r
+    *--------------------------------------------------------------*/\r
+   \r
+   int FrameClassify(      /* index to the max-energy sub-frame */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i/o) the encoder state structure */\r
+       float *residual     /* (i) lpc residual signal */\r
+   ) {\r
+       float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;\r
+       int n, l, max_ssqEn_n;\r
+       const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,\r
+           (float)1.0,(float)0.9,(float)0.8};\r
+       const float sampEn_win[5]={(float)1.0/(float)6.0, \r
+           (float)2.0/(float)6.0, (float)3.0/(float)6.0,\r
+           (float)4.0/(float)6.0, (float)5.0/(float)6.0};\r
+       \r
+       /* init the front and back energies to zero */\r
+   \r
+       memset(fssqEn, 0, NSUB_MAX*sizeof(float));\r
+       memset(bssqEn, 0, NSUB_MAX*sizeof(float));\r
+   \r
+       /* Calculate front of first seqence */\r
+   \r
+       n=0;\r
+       pp=residual;\r
+   \r
+   \r
+       for (l=0; l<5; l++) {\r
+           fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+       for (l=5; l<SUBL; l++) {\r
+           fssqEn[n] += (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+   \r
+       /* Calculate front and back of all middle sequences */\r
+   \r
+       for (n=1; n<iLBCenc_inst->nsub-1; n++) {\r
+           pp=residual+n*SUBL;\r
+           for (l=0; l<5; l++) {\r
+               fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
+               bssqEn[n] += (*pp) * (*pp);\r
+               pp++;\r
+           }\r
+           for (l=5; l<SUBL-5; l++) {\r
+               fssqEn[n] += (*pp) * (*pp);\r
+               bssqEn[n] += (*pp) * (*pp);\r
+               pp++;\r
+           }\r
+           for (l=SUBL-5; l<SUBL; l++) {\r
+               fssqEn[n] += (*pp) * (*pp);\r
+               bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
+               pp++;\r
+           }\r
+       }\r
+   \r
+       /* Calculate back of last seqence */\r
+   \r
+       n=iLBCenc_inst->nsub-1;\r
+       pp=residual+n*SUBL;\r
+       for (l=0; l<SUBL-5; l++) {\r
+           bssqEn[n] += (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+       for (l=SUBL-5; l<SUBL; l++) {\r
+           bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+   \r
+       /* find the index to the weighted 80 sample with \r
+          most energy */\r
+   \r
+       if (iLBCenc_inst->mode==20) l=1;\r
+       else                        l=0;\r
+   \r
+       max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];\r
+       max_ssqEn_n=1;\r
+       for (n=2; n<iLBCenc_inst->nsub; n++) {\r
+   \r
+           l++;\r
+   \r
+   \r
+           if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {\r
+               max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *\r
+                               ssqEn_win[l];\r
+               max_ssqEn_n=n;\r
+           }\r
+       }\r
+   \r
+       return max_ssqEn_n;\r
+   }\r
+   \r
+   \r
index 6b583703ab05c5450c12d5e5501a157c41d7710a..c718de1c3149cf70cb91aa5bb16132653bde079c 100644 (file)
@@ -1,26 +1,26 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    FrameClassify.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-\r
-\r
-#ifndef __iLBC_FRAMECLASSIFY_H\r
-#define __iLBC_FRAMECLASSIFY_H\r
-\r
-int FrameClassify(      /* index to the max-energy sub-frame */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst, \r
-                        /* (i/o) the encoder state structure */\r
-    float *residual     /* (i) lpc residual signal */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       FrameClassify.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   \r
+   \r
+   #ifndef __iLBC_FRAMECLASSIFY_H\r
+   #define __iLBC_FRAMECLASSIFY_H\r
+   \r
+   int FrameClassify(      /* index to the max-energy sub-frame */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i/o) the encoder state structure */\r
+       float *residual     /* (i) lpc residual signal */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 741c731c415aee5e68911e34cbdbf47fe37f851f..d671237322527284c28461585ad15b963588471a 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    LPC_decode.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <string.h>\r
-\r
-#include "helpfun.h"\r
-#include "lsf.h"\r
-#include "iLBC_define.h"\r
-#include "LPCdecode.h"\r
-#include "constants.h"\r
-\r
-/*---------------------------------------------------------------*\r
- *  interpolation of lsf coefficients for the decoder\r
- *--------------------------------------------------------------*/\r
-\r
-void LSFinterpolate2a_dec( \r
-    float *a,           /* (o) lpc coefficients for a sub-frame */\r
-    float *lsf1,    /* (i) first lsf coefficient vector */\r
-\r
-\r
-    float *lsf2,    /* (i) second lsf coefficient vector */\r
-    float coef,         /* (i) interpolation weight */\r
-    int length          /* (i) length of lsf vectors */\r
-){\r
-    float  lsftmp[LPC_FILTERORDER];\r
-    \r
-    interpolate(lsftmp, lsf1, lsf2, coef, length);\r
-    lsf2a(a, lsftmp);\r
-}\r
-\r
-/*---------------------------------------------------------------*\r
- *  obtain dequantized lsf coefficients from quantization index \r
- *--------------------------------------------------------------*/\r
-\r
-void SimplelsfDEQ(\r
-    float *lsfdeq,    /* (o) dequantized lsf coefficients */\r
-    int *index,         /* (i) quantization index */\r
-    int lpc_n           /* (i) number of LPCs */\r
-){  \r
-    int i, j, pos, cb_pos;\r
-\r
-    /* decode first LSF */\r
-    \r
-    pos = 0;\r
-    cb_pos = 0;\r
-    for (i = 0; i < LSF_NSPLIT; i++) {\r
-        for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
-            lsfdeq[pos + j] = lsfCbTbl[cb_pos + \r
-                (long)(index[i])*dim_lsfCbTbl[i] + j];\r
-        }       \r
-        pos += dim_lsfCbTbl[i];\r
-        cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
-    }\r
-\r
-    if (lpc_n>1) {\r
-\r
-        /* decode last LSF */\r
-\r
-        pos = 0;\r
-        cb_pos = 0;\r
-        for (i = 0; i < LSF_NSPLIT; i++) {\r
-            for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
-                lsfdeq[LPC_FILTERORDER + pos + j] = \r
-                    lsfCbTbl[cb_pos + \r
-                    (long)(index[LSF_NSPLIT + i])*\r
-                    dim_lsfCbTbl[i] + j];\r
-            }       \r
-            pos += dim_lsfCbTbl[i];\r
-            cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
-\r
-\r
- *  obtain synthesis and weighting filters form lsf coefficients \r
- *---------------------------------------------------------------*/\r
-\r
-void DecoderInterpolateLSF( \r
-    float *syntdenum, /* (o) synthesis filter coefficients */\r
-    float *weightdenum, /* (o) weighting denumerator \r
-                               coefficients */\r
-    float *lsfdeq,       /* (i) dequantized lsf coefficients */\r
-    int length,         /* (i) length of lsf coefficient vector */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst \r
-                        /* (i) the decoder state structure */\r
-){\r
-    int    i, pos, lp_length;\r
-    float  lp[LPC_FILTERORDER + 1], *lsfdeq2;\r
-        \r
-    lsfdeq2 = lsfdeq + length;\r
-    lp_length = length + 1;\r
-    \r
-    if (iLBCdec_inst->mode==30) {\r
-        /* sub-frame 1: Interpolation between old and first */\r
-\r
-        LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, \r
-            lsf_weightTbl_30ms[0], length);\r
-        memcpy(syntdenum,lp,lp_length*sizeof(float));\r
-        bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, \r
-            lp_length);\r
-\r
-        /* sub-frames 2 to 6: interpolation between first \r
-           and last LSF */\r
-    \r
-        pos = lp_length;\r
-        for (i = 1; i < 6; i++) {\r
-            LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, \r
-                lsf_weightTbl_30ms[i], length);\r
-            memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
-            bwexpand(weightdenum + pos, lp, \r
-                LPC_CHIRP_WEIGHTDENUM, lp_length);\r
-            pos += lp_length;\r
-        }\r
-    }\r
-    else {\r
-        pos = 0;\r
-        for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
-            LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, \r
-                lsfdeq, lsf_weightTbl_20ms[i], length);\r
-            memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
-            bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, \r
-                lp_length);\r
-            pos += lp_length;\r
-        }\r
-    }\r
-    \r
-    /* update memory */\r
-\r
-\r
-\r
-    if (iLBCdec_inst->mode==30)\r
-        memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, \r
-                    length*sizeof(float));\r
-    else\r
-        memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, \r
-                    length*sizeof(float));\r
-\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPC_decode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   \r
+   #include "helpfun.h"\r
+   #include "lsf.h"\r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  interpolation of lsf coefficients for the decoder\r
+    *--------------------------------------------------------------*/\r
+   \r
+   void LSFinterpolate2a_dec( \r
+       float *a,           /* (o) lpc coefficients for a sub-frame */\r
+       float *lsf1,    /* (i) first lsf coefficient vector */\r
+   \r
+   \r
+       float *lsf2,    /* (i) second lsf coefficient vector */\r
+       float coef,         /* (i) interpolation weight */\r
+       int length          /* (i) length of lsf vectors */\r
+   ){\r
+       float  lsftmp[LPC_FILTERORDER];\r
+       \r
+       interpolate(lsftmp, lsf1, lsf2, coef, length);\r
+       lsf2a(a, lsftmp);\r
+   }\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  obtain dequantized lsf coefficients from quantization index \r
+    *--------------------------------------------------------------*/\r
+   \r
+   void SimplelsfDEQ(\r
+       float *lsfdeq,    /* (o) dequantized lsf coefficients */\r
+       int *index,         /* (i) quantization index */\r
+       int lpc_n           /* (i) number of LPCs */\r
+   ){  \r
+       int i, j, pos, cb_pos;\r
+   \r
+       /* decode first LSF */\r
+       \r
+       pos = 0;\r
+       cb_pos = 0;\r
+       for (i = 0; i < LSF_NSPLIT; i++) {\r
+           for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
+               lsfdeq[pos + j] = lsfCbTbl[cb_pos + \r
+                   (long)(index[i])*dim_lsfCbTbl[i] + j];\r
+           }       \r
+           pos += dim_lsfCbTbl[i];\r
+           cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
+       }\r
+   \r
+       if (lpc_n>1) {\r
+   \r
+           /* decode last LSF */\r
+   \r
+           pos = 0;\r
+           cb_pos = 0;\r
+           for (i = 0; i < LSF_NSPLIT; i++) {\r
+               for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
+                   lsfdeq[LPC_FILTERORDER + pos + j] = \r
+                       lsfCbTbl[cb_pos + \r
+                       (long)(index[LSF_NSPLIT + i])*\r
+                       dim_lsfCbTbl[i] + j];\r
+               }       \r
+               pos += dim_lsfCbTbl[i];\r
+               cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+   \r
+   \r
+    *  obtain synthesis and weighting filters form lsf coefficients \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void DecoderInterpolateLSF( \r
+       float *syntdenum, /* (o) synthesis filter coefficients */\r
+       float *weightdenum, /* (o) weighting denumerator \r
+                                  coefficients */\r
+       float *lsfdeq,       /* (i) dequantized lsf coefficients */\r
+       int length,         /* (i) length of lsf coefficient vector */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i) the decoder state structure */\r
+   ){\r
+       int    i, pos, lp_length;\r
+       float  lp[LPC_FILTERORDER + 1], *lsfdeq2;\r
+           \r
+       lsfdeq2 = lsfdeq + length;\r
+       lp_length = length + 1;\r
+       \r
+       if (iLBCdec_inst->mode==30) {\r
+           /* sub-frame 1: Interpolation between old and first */\r
+   \r
+           LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, \r
+               lsf_weightTbl_30ms[0], length);\r
+           memcpy(syntdenum,lp,lp_length*sizeof(float));\r
+           bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, \r
+               lp_length);\r
+   \r
+           /* sub-frames 2 to 6: interpolation between first \r
+              and last LSF */\r
+       \r
+           pos = lp_length;\r
+           for (i = 1; i < 6; i++) {\r
+               LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, \r
+                   lsf_weightTbl_30ms[i], length);\r
+               memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
+               bwexpand(weightdenum + pos, lp, \r
+                   LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       else {\r
+           pos = 0;\r
+           for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
+               LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, \r
+                   lsfdeq, lsf_weightTbl_20ms[i], length);\r
+               memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
+               bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, \r
+                   lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       \r
+       /* update memory */\r
+   \r
+   \r
+   \r
+       if (iLBCdec_inst->mode==30)\r
+           memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, \r
+                       length*sizeof(float));\r
+       else\r
+           memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, \r
+                       length*sizeof(float));\r
+   \r
+   }\r
+   \r
+   \r
index 84116e08f227d054ae808545f8871f59c92736a6..01c3f2c4c6aaa526054c79fd05c79b412b3a2687 100644 (file)
@@ -1,44 +1,44 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    LPC_decode.h     \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_LPC_DECODE_H\r
-#define __iLBC_LPC_DECODE_H\r
-\r
-void LSFinterpolate2a_dec( \r
-\r
-\r
-    float *a,           /* (o) lpc coefficients for a sub-frame */\r
-    float *lsf1,    /* (i) first lsf coefficient vector */\r
-    float *lsf2,    /* (i) second lsf coefficient vector */\r
-    float coef,         /* (i) interpolation weight */\r
-    int length          /* (i) length of lsf vectors */\r
-);\r
-      \r
-void SimplelsfDEQ( \r
-    float *lsfdeq,      /* (o) dequantized lsf coefficients */\r
-    int *index,         /* (i) quantization index */\r
-    int lpc_n           /* (i) number of LPCs */\r
-);\r
-\r
-void DecoderInterpolateLSF( \r
-    float *syntdenum,   /* (o) synthesis filter coefficients */\r
-    float *weightdenum, /* (o) weighting denumerator \r
-                               coefficients */\r
-    float *lsfdeq,      /* (i) dequantized lsf coefficients */\r
-    int length,         /* (i) length of lsf coefficient vector */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst \r
-                        /* (i) the decoder state structure */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPC_decode.h     \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_LPC_DECODE_H\r
+   #define __iLBC_LPC_DECODE_H\r
+   \r
+   void LSFinterpolate2a_dec( \r
+   \r
+   \r
+       float *a,           /* (o) lpc coefficients for a sub-frame */\r
+       float *lsf1,    /* (i) first lsf coefficient vector */\r
+       float *lsf2,    /* (i) second lsf coefficient vector */\r
+       float coef,         /* (i) interpolation weight */\r
+       int length          /* (i) length of lsf vectors */\r
+   );\r
+         \r
+   void SimplelsfDEQ( \r
+       float *lsfdeq,      /* (o) dequantized lsf coefficients */\r
+       int *index,         /* (i) quantization index */\r
+       int lpc_n           /* (i) number of LPCs */\r
+   );\r
+   \r
+   void DecoderInterpolateLSF( \r
+       float *syntdenum,   /* (o) synthesis filter coefficients */\r
+       float *weightdenum, /* (o) weighting denumerator \r
+                                  coefficients */\r
+       float *lsfdeq,      /* (i) dequantized lsf coefficients */\r
+       int length,         /* (i) length of lsf coefficient vector */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i) the decoder state structure */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index d1286e2199bd4e8b6173034678bb0d310ebd1736..d190c84926375c707858b8b0123630447aeffe1f 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    LPCencode.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <string.h>\r
-\r
-\r
-\r
-#include "iLBC_define.h"\r
-#include "LPCencode.h"\r
-#include "helpfun.h"\r
-#include "lsf.h"\r
-#include "constants.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  lpc analysis (subrutine to LPCencode)\r
- *---------------------------------------------------------------*/\r
-\r
-static void SimpleAnalysis(\r
-    float *lsf,         /* (o) lsf coefficients */\r
-    float *data,    /* (i) new data vector */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst \r
-                        /* (i/o) the encoder state structure */\r
-){\r
-    int k, is;\r
-    float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];\r
-    float lp2[LPC_FILTERORDER + 1];\r
-    float r[LPC_FILTERORDER + 1];\r
-\r
-    is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
-    memcpy(iLBCenc_inst->lpc_buffer+is,data,\r
-        iLBCenc_inst->blockl*sizeof(float));\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPCencode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   \r
+   \r
+   \r
+   #include "iLBC_define.h"\r
+   #include "helpfun.h"\r
+   #include "lsf.h"\r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lpc analysis (subrutine to LPCencode)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SimpleAnalysis(\r
+       float *lsf,         /* (o) lsf coefficients */\r
+       float *data,    /* (i) new data vector */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   ){\r
+       int k, is;\r
+       float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];\r
+       float lp2[LPC_FILTERORDER + 1];\r
+       float r[LPC_FILTERORDER + 1];\r
+   \r
+       is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
+       memcpy(iLBCenc_inst->lpc_buffer+is,data,\r
+           iLBCenc_inst->blockl*sizeof(float));\r
+       \r
+       /* No lookahead, last window is asymmetric */\r
+       \r
+       for (k = 0; k < iLBCenc_inst->lpc_n; k++) {\r
+           \r
+           is = LPC_LOOKBACK;\r
+   \r
+           if (k < (iLBCenc_inst->lpc_n - 1)) {\r
+               window(temp, lpc_winTbl, \r
+                   iLBCenc_inst->lpc_buffer, BLOCKL_MAX);\r
+           } else {\r
+               window(temp, lpc_asymwinTbl, \r
+                   iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);\r
+           }\r
+           \r
+           autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);\r
+           window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);\r
+           \r
+           levdurb(lp, temp, r, LPC_FILTERORDER);\r
+           bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);\r
+   \r
+           a2lsf(lsf + k*LPC_FILTERORDER, lp2);\r
+       }\r
+       is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
+       memmove(iLBCenc_inst->lpc_buffer, \r
+           iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, \r
+           is*sizeof(float));\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+   \r
+   \r
+    *  lsf interpolator and conversion from lsf to a coefficients\r
+    *  (subrutine to SimpleInterpolateLSF)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void LSFinterpolate2a_enc(\r
+       float *a,       /* (o) lpc coefficients */ \r
+       float *lsf1,/* (i) first set of lsf coefficients */\r
+       float *lsf2,/* (i) second set of lsf coefficients */\r
+       float coef,     /* (i) weighting coefficient to use between \r
+                              lsf1 and lsf2 */\r
+       long length      /* (i) length of coefficient vectors */\r
+   ){  \r
+       float  lsftmp[LPC_FILTERORDER];\r
+       \r
+       interpolate(lsftmp, lsf1, lsf2, coef, length);\r
+       lsf2a(a, lsftmp);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lsf interpolator (subrutine to LPCencode)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SimpleInterpolateLSF(\r
+       float *syntdenum,   /* (o) the synthesis filter denominator \r
+                                  resulting from the quantized \r
+                                  interpolated lsf */\r
+       float *weightdenum, /* (o) the weighting filter denominator \r
+                                  resulting from the unquantized \r
+                                  interpolated lsf */\r
+       float *lsf,         /* (i) the unquantized lsf coefficients */\r
+       float *lsfdeq,      /* (i) the dequantized lsf coefficients */\r
+       float *lsfold,      /* (i) the unquantized lsf coefficients of \r
+                                  the previous signal frame */\r
+       float *lsfdeqold, /* (i) the dequantized lsf coefficients of \r
+                                  the previous signal frame */\r
+       int length,         /* (i) should equate LPC_FILTERORDER */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   ){\r
+       int    i, pos, lp_length;\r
+       float  lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;\r
+       \r
+       lsf2 = lsf + length;\r
+       lsfdeq2 = lsfdeq + length;\r
+       lp_length = length + 1; \r
     \r
-    /* No lookahead, last window is asymmetric */\r
-    \r
-    for (k = 0; k < iLBCenc_inst->lpc_n; k++) {\r
-        \r
-        is = LPC_LOOKBACK;\r
-\r
-        if (k < (iLBCenc_inst->lpc_n - 1)) {\r
-            window(temp, lpc_winTbl, \r
-                iLBCenc_inst->lpc_buffer, BLOCKL_MAX);\r
-        } else {\r
-            window(temp, lpc_asymwinTbl, \r
-                iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);\r
-        }\r
-        \r
-        autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);\r
-        window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);\r
-        \r
-        levdurb(lp, temp, r, LPC_FILTERORDER);\r
-        bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);\r
-\r
-        a2lsf(lsf + k*LPC_FILTERORDER, lp2);\r
-    }\r
-    is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
-    memmove(iLBCenc_inst->lpc_buffer, \r
-        iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, \r
-        is*sizeof(float));\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
-\r
-\r
- *  lsf interpolator and conversion from lsf to a coefficients\r
- *  (subrutine to SimpleInterpolateLSF)\r
- *---------------------------------------------------------------*/\r
-\r
-static void LSFinterpolate2a_enc(\r
-    float *a,       /* (o) lpc coefficients */ \r
-    float *lsf1,/* (i) first set of lsf coefficients */\r
-    float *lsf2,/* (i) second set of lsf coefficients */\r
-    float coef,     /* (i) weighting coefficient to use between \r
-                           lsf1 and lsf2 */\r
-    long length      /* (i) length of coefficient vectors */\r
-){  \r
-    float  lsftmp[LPC_FILTERORDER];\r
-    \r
-    interpolate(lsftmp, lsf1, lsf2, coef, length);\r
-    lsf2a(a, lsftmp);\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  lsf interpolator (subrutine to LPCencode)\r
- *---------------------------------------------------------------*/\r
-\r
-static void SimpleInterpolateLSF(\r
-    float *syntdenum,   /* (o) the synthesis filter denominator \r
-                               resulting from the quantized \r
-                               interpolated lsf */\r
-    float *weightdenum, /* (o) the weighting filter denominator \r
-                               resulting from the unquantized \r
-                               interpolated lsf */\r
-    float *lsf,         /* (i) the unquantized lsf coefficients */\r
-    float *lsfdeq,      /* (i) the dequantized lsf coefficients */\r
-    float *lsfold,      /* (i) the unquantized lsf coefficients of \r
-                               the previous signal frame */\r
-    float *lsfdeqold, /* (i) the dequantized lsf coefficients of \r
-                               the previous signal frame */\r
-    int length,         /* (i) should equate LPC_FILTERORDER */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst \r
-                        /* (i/o) the encoder state structure */\r
-){\r
-    int    i, pos, lp_length;\r
-    float  lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;\r
-    \r
-    lsf2 = lsf + length;\r
-    lsfdeq2 = lsfdeq + length;\r
-    lp_length = length + 1; \r
\r
-    if (iLBCenc_inst->mode==30) {\r
-        /* sub-frame 1: Interpolation between old and first \r
-           set of lsf coefficients */\r
-\r
-        LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
-            lsf_weightTbl_30ms[0], length);\r
-        memcpy(syntdenum,lp,lp_length*sizeof(float));\r
-        LSFinterpolate2a_enc(lp, lsfold, lsf, \r
-\r
-\r
-            lsf_weightTbl_30ms[0], length);\r
-        bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);\r
-\r
-        /* sub-frame 2 to 6: Interpolation between first \r
-           and second set of lsf coefficients */\r
-    \r
-        pos = lp_length;\r
-        for (i = 1; i < iLBCenc_inst->nsub; i++) {\r
-            LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, \r
-                lsf_weightTbl_30ms[i], length);\r
-            memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
-        \r
-            LSFinterpolate2a_enc(lp, lsf, lsf2, \r
-                lsf_weightTbl_30ms[i], length);\r
-            bwexpand(weightdenum + pos, lp, \r
-                LPC_CHIRP_WEIGHTDENUM, lp_length);\r
-            pos += lp_length;\r
-        }\r
-    }\r
-    else {\r
-        pos = 0;\r
-        for (i = 0; i < iLBCenc_inst->nsub; i++) {\r
-            LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
-                lsf_weightTbl_20ms[i], length);\r
-            memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
-            LSFinterpolate2a_enc(lp, lsfold, lsf, \r
-                lsf_weightTbl_20ms[i], length);\r
-            bwexpand(weightdenum+pos, lp, \r
-                LPC_CHIRP_WEIGHTDENUM, lp_length);\r
-            pos += lp_length;\r
-        }\r
-    }\r
-    \r
-    /* update memory */\r
-\r
-    if (iLBCenc_inst->mode==30) {\r
-        memcpy(lsfold, lsf2, length*sizeof(float));\r
-        memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));\r
-    }\r
-    else {\r
-        memcpy(lsfold, lsf, length*sizeof(float));\r
-        memcpy(lsfdeqold, lsfdeq, length*sizeof(float));\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  lsf quantizer (subrutine to LPCencode)\r
- *---------------------------------------------------------------*/\r
-\r
-static void SimplelsfQ(\r
-    float *lsfdeq,    /* (o) dequantized lsf coefficients\r
-                           (dimension FILTERORDER) */\r
-    int *index,     /* (o) quantization index */\r
-    float *lsf,      /* (i) the lsf coefficient vector to be \r
-\r
-\r
-                           quantized (dimension FILTERORDER ) */\r
-    int lpc_n     /* (i) number of lsf sets to quantize */\r
-){    \r
-    /* Quantize first LSF with memoryless split VQ */\r
-    SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, \r
-        dim_lsfCbTbl, size_lsfCbTbl);\r
-\r
-    if (lpc_n==2) {\r
-        /* Quantize second LSF with memoryless split VQ */\r
-        SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, \r
-            lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, \r
-            dim_lsfCbTbl, size_lsfCbTbl);\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  lpc encoder\r
- *---------------------------------------------------------------*/\r
-\r
-void LPCencode( \r
-    float *syntdenum, /* (i/o) synthesis filter coefficients \r
-                               before/after encoding */\r
-    float *weightdenum, /* (i/o) weighting denumerator \r
-                               coefficients before/after \r
-                               encoding */\r
-    int *lsf_index,     /* (o) lsf quantization index */\r
-    float *data,    /* (i) lsf coefficients to quantize */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst \r
-                        /* (i/o) the encoder state structure */\r
-){\r
-    float lsf[LPC_FILTERORDER * LPC_N_MAX];\r
-    float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];\r
-    int change=0;\r
-    \r
-    SimpleAnalysis(lsf, data, iLBCenc_inst);\r
-    SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);\r
-    change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);\r
-    SimpleInterpolateLSF(syntdenum, weightdenum, \r
-        lsf, lsfdeq, iLBCenc_inst->lsfold, \r
-        iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);\r
-}\r
-\r
-\r
-\r
+       if (iLBCenc_inst->mode==30) {\r
+           /* sub-frame 1: Interpolation between old and first \r
+              set of lsf coefficients */\r
+   \r
+           LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
+               lsf_weightTbl_30ms[0], length);\r
+           memcpy(syntdenum,lp,lp_length*sizeof(float));\r
+           LSFinterpolate2a_enc(lp, lsfold, lsf, \r
+   \r
+   \r
+               lsf_weightTbl_30ms[0], length);\r
+           bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+   \r
+           /* sub-frame 2 to 6: Interpolation between first \r
+              and second set of lsf coefficients */\r
+       \r
+           pos = lp_length;\r
+           for (i = 1; i < iLBCenc_inst->nsub; i++) {\r
+               LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, \r
+                   lsf_weightTbl_30ms[i], length);\r
+               memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
+           \r
+               LSFinterpolate2a_enc(lp, lsf, lsf2, \r
+                   lsf_weightTbl_30ms[i], length);\r
+               bwexpand(weightdenum + pos, lp, \r
+                   LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       else {\r
+           pos = 0;\r
+           for (i = 0; i < iLBCenc_inst->nsub; i++) {\r
+               LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
+                   lsf_weightTbl_20ms[i], length);\r
+               memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
+               LSFinterpolate2a_enc(lp, lsfold, lsf, \r
+                   lsf_weightTbl_20ms[i], length);\r
+               bwexpand(weightdenum+pos, lp, \r
+                   LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       \r
+       /* update memory */\r
+   \r
+       if (iLBCenc_inst->mode==30) {\r
+           memcpy(lsfold, lsf2, length*sizeof(float));\r
+           memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));\r
+       }\r
+       else {\r
+           memcpy(lsfold, lsf, length*sizeof(float));\r
+           memcpy(lsfdeqold, lsfdeq, length*sizeof(float));\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lsf quantizer (subrutine to LPCencode)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SimplelsfQ(\r
+       float *lsfdeq,    /* (o) dequantized lsf coefficients\r
+                              (dimension FILTERORDER) */\r
+       int *index,     /* (o) quantization index */\r
+       float *lsf,      /* (i) the lsf coefficient vector to be \r
+   \r
+   \r
+                              quantized (dimension FILTERORDER ) */\r
+       int lpc_n     /* (i) number of lsf sets to quantize */\r
+   ){    \r
+       /* Quantize first LSF with memoryless split VQ */\r
+       SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, \r
+           dim_lsfCbTbl, size_lsfCbTbl);\r
+   \r
+       if (lpc_n==2) {\r
+           /* Quantize second LSF with memoryless split VQ */\r
+           SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, \r
+               lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, \r
+               dim_lsfCbTbl, size_lsfCbTbl);\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lpc encoder\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void LPCencode( \r
+       float *syntdenum, /* (i/o) synthesis filter coefficients \r
+                                  before/after encoding */\r
+       float *weightdenum, /* (i/o) weighting denumerator \r
+                                  coefficients before/after \r
+                                  encoding */\r
+       int *lsf_index,     /* (o) lsf quantization index */\r
+       float *data,    /* (i) lsf coefficients to quantize */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   ){\r
+       float lsf[LPC_FILTERORDER * LPC_N_MAX];\r
+       float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];\r
+       int change=0;\r
+       \r
+       SimpleAnalysis(lsf, data, iLBCenc_inst);\r
+       SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);\r
+       change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);\r
+       SimpleInterpolateLSF(syntdenum, weightdenum, \r
+           lsf, lsfdeq, iLBCenc_inst->lsfold, \r
+           iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);\r
+   }\r
+   \r
+   \r
+   \r
index 464282e62984f176b2088333a8b89a7a9a22b5d4..f0b7816976938331915f4ec645d6a7467bb98396 100644 (file)
@@ -1,29 +1,29 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    LPCencode.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_LPCENCOD_H\r
-#define __iLBC_LPCENCOD_H\r
-\r
-void LPCencode( \r
-    float *syntdenum,   /* (i/o) synthesis filter coefficients \r
-                               before/after encoding */\r
-    float *weightdenum, /* (i/o) weighting denumerator coefficients\r
-                               before/after encoding */\r
-    int *lsf_index,     /* (o) lsf quantization index */\r
-    float *data,    /* (i) lsf coefficients to quantize */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst \r
-                        /* (i/o) the encoder state structure */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPCencode.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_LPCENCOD_H\r
+   #define __iLBC_LPCENCOD_H\r
+   \r
+   void LPCencode( \r
+       float *syntdenum,   /* (i/o) synthesis filter coefficients \r
+                                  before/after encoding */\r
+       float *weightdenum, /* (i/o) weighting denumerator coefficients\r
+                                  before/after encoding */\r
+       int *lsf_index,     /* (o) lsf quantization index */\r
+       float *data,    /* (i) lsf coefficients to quantize */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 31d997dfe44bd2255907ea85f6b264baae9796d2..953c9a0a7b40e20bdf2c420e7eceee00934938d6 100644 (file)
@@ -1,76 +1,75 @@
-\r
-/******************************************************************\r
-\r
-\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    StateConstructW.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h> \r
-#include <string.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "StateConstructW.h"\r
-#include "constants.h"\r
-#include "filter.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  decoding of the start state\r
- *---------------------------------------------------------------*/\r
-\r
-void StateConstructW( \r
-    int idxForMax,      /* (i) 6-bit index for the quantization of \r
-                               max amplitude */\r
-    int *idxVec,    /* (i) vector of quantization indexes */\r
-    float *syntDenum,   /* (i) synthesis filter denumerator */\r
-    float *out,         /* (o) the decoded state vector */\r
-    int len             /* (i) length of a state vector */\r
-){\r
-    float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, \r
-        numerator[LPC_FILTERORDER+1];\r
-    float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;\r
-    int k,tmpi;\r
-    \r
-    /* decoding of the maximum value */\r
-\r
-    maxVal = state_frgqTbl[idxForMax];\r
-    maxVal = (float)pow(10,maxVal)/(float)4.5;\r
-        \r
-    /* initialization of buffers and coefficients */\r
-    \r
-    memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
-    memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
-    for (k=0; k<LPC_FILTERORDER; k++) {\r
-        numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
-    }\r
-    numerator[LPC_FILTERORDER]=syntDenum[0];\r
-    tmp = &tmpbuf[LPC_FILTERORDER];\r
-    fout = &foutbuf[LPC_FILTERORDER];\r
-\r
-    /* decoding of the sample values */\r
-    \r
-    for (k=0; k<len; k++) {\r
-        tmpi = len-1-k;\r
-        /* maxVal = 1/scal */\r
-\r
-\r
-        tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];\r
-    }\r
-\r
-    /* circular convolution with all-pass filter */\r
-\r
-    memset(tmp+len, 0, len*sizeof(float));\r
-    ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
-        LPC_FILTERORDER, fout);\r
-    for (k=0;k<len;k++) {\r
-        out[k] = fout[len-1-k]+fout[2*len-1-k];\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+   \r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateConstructW.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h> \r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  decoding of the start state\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void StateConstructW( \r
+       int idxForMax,      /* (i) 6-bit index for the quantization of \r
+                                  max amplitude */\r
+       int *idxVec,    /* (i) vector of quantization indexes */\r
+       float *syntDenum,   /* (i) synthesis filter denumerator */\r
+       float *out,         /* (o) the decoded state vector */\r
+       int len             /* (i) length of a state vector */\r
+   ){\r
+       float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, \r
+           numerator[LPC_FILTERORDER+1];\r
+       float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;\r
+       int k,tmpi;\r
+       \r
+       /* decoding of the maximum value */\r
+   \r
+       maxVal = state_frgqTbl[idxForMax];\r
+       maxVal = (float)pow(10,maxVal)/(float)4.5;\r
+           \r
+       /* initialization of buffers and coefficients */\r
+       \r
+       memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       for (k=0; k<LPC_FILTERORDER; k++) {\r
+           numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
+       }\r
+       numerator[LPC_FILTERORDER]=syntDenum[0];\r
+       tmp = &tmpbuf[LPC_FILTERORDER];\r
+       fout = &foutbuf[LPC_FILTERORDER];\r
+   \r
+       /* decoding of the sample values */\r
+       \r
+       for (k=0; k<len; k++) {\r
+           tmpi = len-1-k;\r
+           /* maxVal = 1/scal */\r
+   \r
+   \r
+           tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];\r
+       }\r
+   \r
+       /* circular convolution with all-pass filter */\r
+   \r
+       memset(tmp+len, 0, len*sizeof(float));\r
+       ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
+           LPC_FILTERORDER, fout);\r
+       for (k=0;k<len;k++) {\r
+           out[k] = fout[len-1-k]+fout[2*len-1-k];\r
+       }\r
+   }\r
+   \r
+   \r
index b8727dea17140e89f3d79b194fa8396ef548b55b..354d73ca5156c2eddbe7c3f93d2bbd2135a9e378 100644 (file)
@@ -1,27 +1,27 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    StateConstructW.h  \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_STATECONSTRUCTW_H\r
-#define __iLBC_STATECONSTRUCTW_H\r
-\r
-void StateConstructW( \r
-    int idxForMax,      /* (i) 6-bit index for the quantization of \r
-                               max amplitude */\r
-    int *idxVec,    /* (i) vector of quantization indexes */\r
-    float *syntDenum,   /* (i) synthesis filter denumerator */\r
-    float *out,         /* (o) the decoded state vector */\r
-    int len             /* (i) length of a state vector */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateConstructW.h  \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_STATECONSTRUCTW_H\r
+   #define __iLBC_STATECONSTRUCTW_H\r
+   \r
+   void StateConstructW( \r
+       int idxForMax,      /* (i) 6-bit index for the quantization of \r
+                                  max amplitude */\r
+       int *idxVec,    /* (i) vector of quantization indexes */\r
+       float *syntDenum,   /* (i) synthesis filter denumerator */\r
+       float *out,         /* (o) the decoded state vector */\r
+       int len             /* (i) length of a state vector */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index fd63916ece58401192e1f28c5e0f09ff87d27ba0..49b04b0429d58c9f66f2e25602986317a166b436 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    StateSearchW.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h> \r
-#include <string.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "StateSearchW.h"\r
-#include "constants.h"\r
-#include "filter.h"\r
-#include "helpfun.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  predictive noise shaping encoding of scaled start state \r
- *  (subrutine for StateSearchW) \r
- *---------------------------------------------------------------*/\r
-\r
-void AbsQuantW(\r
-    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
-                        /* (i) Encoder instance */\r
-    float *in,          /* (i) vector to encode */\r
-    float *syntDenum,   /* (i) denominator of synthesis filter */\r
-    float *weightDenum, /* (i) denominator of weighting filter */\r
-    int *out,           /* (o) vector of quantizer indexes */\r
-    int len,        /* (i) length of vector to encode and \r
-                               vector of quantizer indexes */\r
-    int state_first     /* (i) position of start state in the \r
-                               80 vec */\r
-){\r
-    float *syntOut;\r
-    float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];\r
-    float toQ, xq;\r
-    int n;\r
-    int index;\r
-\r
-    /* initialization of buffer for filtering */\r
-            \r
-    memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));\r
-\r
-\r
-\r
-    /* initialization of pointer for filtering */\r
-\r
-    syntOut = &syntOutBuf[LPC_FILTERORDER];\r
-    \r
-    /* synthesis and weighting filters on input */\r
-    \r
-    if (state_first) {\r
-        AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);\r
-    } else {\r
-        AllPoleFilter (in, weightDenum, \r
-            iLBCenc_inst->state_short_len-SUBL, \r
-            LPC_FILTERORDER);\r
-    }\r
-\r
-    /* encoding loop */\r
-\r
-    for (n=0; n<len; n++) {\r
-        \r
-        /* time update of filter coefficients */  \r
-        \r
-        if ((state_first)&&(n==SUBL)){\r
-            syntDenum += (LPC_FILTERORDER+1);\r
-            weightDenum += (LPC_FILTERORDER+1);\r
-\r
-            /* synthesis and weighting filters on input */\r
-            AllPoleFilter (&in[n], weightDenum, len-n, \r
-                LPC_FILTERORDER);\r
-\r
-        } else if ((state_first==0)&&\r
-            (n==(iLBCenc_inst->state_short_len-SUBL))) {\r
-            syntDenum += (LPC_FILTERORDER+1);\r
-            weightDenum += (LPC_FILTERORDER+1);\r
-\r
-            /* synthesis and weighting filters on input */\r
-            AllPoleFilter (&in[n], weightDenum, len-n, \r
-                LPC_FILTERORDER);\r
-            \r
-        }\r
-        \r
-        /* prediction of synthesized and weighted input */\r
-\r
-        syntOut[n] = 0.0;\r
-        AllPoleFilter (&syntOut[n], weightDenum, 1, \r
-            LPC_FILTERORDER);\r
-        \r
-        /* quantization */      \r
-\r
-        toQ = in[n]-syntOut[n];\r
-        sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);\r
-        out[n]=index;\r
-        syntOut[n] = state_sq3Tbl[out[n]];\r
-\r
-        /* update of the prediction filter */\r
-\r
-\r
-\r
-        AllPoleFilter(&syntOut[n], weightDenum, 1, \r
-            LPC_FILTERORDER);\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  encoding of start state                          \r
- *---------------------------------------------------------------*/\r
-\r
-void StateSearchW( \r
-    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
-                        /* (i) Encoder instance */\r
-    float *residual,/* (i) target residual vector */\r
-    float *syntDenum,   /* (i) lpc synthesis filter */\r
-    float *weightDenum, /* (i) weighting filter denuminator */\r
-    int *idxForMax,     /* (o) quantizer index for maximum \r
-                               amplitude */\r
-    int *idxVec,    /* (o) vector of quantization indexes */\r
-    int len,        /* (i) length of all vectors */\r
-    int state_first     /* (i) position of start state in the \r
-                               80 vec */\r
-){  \r
-    float dtmp, maxVal;\r
-    float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];\r
-    float *tmp, numerator[1+LPC_FILTERORDER]; \r
-    float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;\r
-    int k;\r
-    float qmax, scal;\r
-    \r
-    /* initialization of buffers and filter coefficients */\r
-\r
-    memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
-    memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
-    for (k=0; k<LPC_FILTERORDER; k++) {\r
-        numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
-    }\r
-    numerator[LPC_FILTERORDER]=syntDenum[0];\r
-    tmp = &tmpbuf[LPC_FILTERORDER];\r
-    fout = &foutbuf[LPC_FILTERORDER];\r
-\r
-    /* circular convolution with the all-pass filter */\r
-    \r
-    memcpy(tmp, residual, len*sizeof(float));\r
-    memset(tmp+len, 0, len*sizeof(float));\r
-    ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
-        LPC_FILTERORDER, fout);\r
-    for (k=0; k<len; k++) {\r
-        fout[k] += fout[k+len];\r
-    }   \r
-        \r
-    /* identification of the maximum amplitude value */\r
-    \r
-    maxVal = fout[0];\r
-\r
-\r
-    for (k=1; k<len; k++) {\r
-        \r
-        if (fout[k]*fout[k] > maxVal*maxVal){\r
-            maxVal = fout[k];\r
-        }\r
-    }\r
-    maxVal=(float)fabs(maxVal);\r
-        \r
-    /* encoding of the maximum amplitude value */\r
-    \r
-    if (maxVal < 10.0) {\r
-        maxVal = 10.0;\r
-    }\r
-    maxVal = (float)log10(maxVal);\r
-    sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);\r
-\r
-    /* decoding of the maximum amplitude representation value,\r
-       and corresponding scaling of start state */\r
-\r
-    maxVal=state_frgqTbl[*idxForMax];\r
-    qmax = (float)pow(10,maxVal);\r
-    scal = (float)(4.5)/qmax;\r
-    for (k=0; k<len; k++){\r
-        fout[k] *= scal;\r
-    }\r
-\r
-    /* predictive noise shaping encoding of scaled start state */\r
-\r
-    AbsQuantW(iLBCenc_inst, fout,syntDenum, \r
-        weightDenum,idxVec, len, state_first);\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateSearchW.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h> \r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   #include "helpfun.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  predictive noise shaping encoding of scaled start state \r
+    *  (subrutine for StateSearchW) \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void AbsQuantW(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *in,          /* (i) vector to encode */\r
+       float *syntDenum,   /* (i) denominator of synthesis filter */\r
+       float *weightDenum, /* (i) denominator of weighting filter */\r
+       int *out,           /* (o) vector of quantizer indexes */\r
+       int len,        /* (i) length of vector to encode and \r
+                                  vector of quantizer indexes */\r
+       int state_first     /* (i) position of start state in the \r
+                                  80 vec */\r
+   ){\r
+       float *syntOut;\r
+       float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];\r
+       float toQ, xq;\r
+       int n;\r
+       int index;\r
+   \r
+       /* initialization of buffer for filtering */\r
+               \r
+       memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+   \r
+   \r
+       /* initialization of pointer for filtering */\r
+   \r
+       syntOut = &syntOutBuf[LPC_FILTERORDER];\r
+       \r
+       /* synthesis and weighting filters on input */\r
+       \r
+       if (state_first) {\r
+           AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);\r
+       } else {\r
+           AllPoleFilter (in, weightDenum, \r
+               iLBCenc_inst->state_short_len-SUBL, \r
+               LPC_FILTERORDER);\r
+       }\r
+   \r
+       /* encoding loop */\r
+   \r
+       for (n=0; n<len; n++) {\r
+           \r
+           /* time update of filter coefficients */  \r
+           \r
+           if ((state_first)&&(n==SUBL)){\r
+               syntDenum += (LPC_FILTERORDER+1);\r
+               weightDenum += (LPC_FILTERORDER+1);\r
+   \r
+               /* synthesis and weighting filters on input */\r
+               AllPoleFilter (&in[n], weightDenum, len-n, \r
+                   LPC_FILTERORDER);\r
+   \r
+           } else if ((state_first==0)&&\r
+               (n==(iLBCenc_inst->state_short_len-SUBL))) {\r
+               syntDenum += (LPC_FILTERORDER+1);\r
+               weightDenum += (LPC_FILTERORDER+1);\r
+   \r
+               /* synthesis and weighting filters on input */\r
+               AllPoleFilter (&in[n], weightDenum, len-n, \r
+                   LPC_FILTERORDER);\r
+               \r
+           }\r
+           \r
+           /* prediction of synthesized and weighted input */\r
+   \r
+           syntOut[n] = 0.0;\r
+           AllPoleFilter (&syntOut[n], weightDenum, 1, \r
+               LPC_FILTERORDER);\r
+           \r
+           /* quantization */      \r
+   \r
+           toQ = in[n]-syntOut[n];\r
+           sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);\r
+           out[n]=index;\r
+           syntOut[n] = state_sq3Tbl[out[n]];\r
+   \r
+           /* update of the prediction filter */\r
+   \r
+   \r
+   \r
+           AllPoleFilter(&syntOut[n], weightDenum, 1, \r
+               LPC_FILTERORDER);\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  encoding of start state                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void StateSearchW( \r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *residual,/* (i) target residual vector */\r
+       float *syntDenum,   /* (i) lpc synthesis filter */\r
+       float *weightDenum, /* (i) weighting filter denuminator */\r
+       int *idxForMax,     /* (o) quantizer index for maximum \r
+                                  amplitude */\r
+       int *idxVec,    /* (o) vector of quantization indexes */\r
+       int len,        /* (i) length of all vectors */\r
+       int state_first     /* (i) position of start state in the \r
+                                  80 vec */\r
+   ){  \r
+       float dtmp, maxVal;\r
+       float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];\r
+       float *tmp, numerator[1+LPC_FILTERORDER]; \r
+       float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;\r
+       int k;\r
+       float qmax, scal;\r
+       \r
+       /* initialization of buffers and filter coefficients */\r
+   \r
+       memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       for (k=0; k<LPC_FILTERORDER; k++) {\r
+           numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
+       }\r
+       numerator[LPC_FILTERORDER]=syntDenum[0];\r
+       tmp = &tmpbuf[LPC_FILTERORDER];\r
+       fout = &foutbuf[LPC_FILTERORDER];\r
+   \r
+       /* circular convolution with the all-pass filter */\r
+       \r
+       memcpy(tmp, residual, len*sizeof(float));\r
+       memset(tmp+len, 0, len*sizeof(float));\r
+       ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
+           LPC_FILTERORDER, fout);\r
+       for (k=0; k<len; k++) {\r
+           fout[k] += fout[k+len];\r
+       }   \r
+           \r
+       /* identification of the maximum amplitude value */\r
+       \r
+       maxVal = fout[0];\r
+   \r
+   \r
+       for (k=1; k<len; k++) {\r
+           \r
+           if (fout[k]*fout[k] > maxVal*maxVal){\r
+               maxVal = fout[k];\r
+           }\r
+       }\r
+       maxVal=(float)fabs(maxVal);\r
+           \r
+       /* encoding of the maximum amplitude value */\r
+       \r
+       if (maxVal < 10.0) {\r
+           maxVal = 10.0;\r
+       }\r
+       maxVal = (float)log10(maxVal);\r
+       sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);\r
+   \r
+       /* decoding of the maximum amplitude representation value,\r
+          and corresponding scaling of start state */\r
+   \r
+       maxVal=state_frgqTbl[*idxForMax];\r
+       qmax = (float)pow(10,maxVal);\r
+       scal = (float)(4.5)/qmax;\r
+       for (k=0; k<len; k++){\r
+           fout[k] *= scal;\r
+       }\r
+   \r
+       /* predictive noise shaping encoding of scaled start state */\r
+   \r
+       AbsQuantW(iLBCenc_inst, fout,syntDenum, \r
+           weightDenum,idxVec, len, state_first);\r
+   }\r
+   \r
+   \r
index 3d53077b3d0bd86458baca1b11e7150a247c3622..470c437b4368a4e4fd7e97982e3fa4e825a2e1a6 100644 (file)
@@ -1,48 +1,48 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    StateSearchW.h     \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_STATESEARCHW_H\r
-#define __iLBC_STATESEARCHW_H\r
-\r
-void AbsQuantW(\r
-    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
-                        /* (i) Encoder instance */\r
-    float *in,          /* (i) vector to encode */\r
-    float *syntDenum,   /* (i) denominator of synthesis filter */\r
-    float *weightDenum, /* (i) denominator of weighting filter */\r
-    int *out,           /* (o) vector of quantizer indexes */\r
-    int len,        /* (i) length of vector to encode and \r
-                               vector of quantizer indexes */\r
-    int state_first     /* (i) position of start state in the \r
-                               80 vec */\r
-);\r
-\r
-void StateSearchW( \r
-    iLBC_Enc_Inst_t *iLBCenc_inst,  \r
-                        /* (i) Encoder instance */\r
-    float *residual,/* (i) target residual vector */\r
-    float *syntDenum,   /* (i) lpc synthesis filter */\r
-    float *weightDenum, /* (i) weighting filter denuminator */\r
-    int *idxForMax,     /* (o) quantizer index for maximum \r
-                               amplitude */\r
-    int *idxVec,    /* (o) vector of quantization indexes */\r
-    int len,        /* (i) length of all vectors */\r
-    int state_first     /* (i) position of start state in the \r
-\r
-\r
-                               80 vec */\r
-);\r
-\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateSearchW.h     \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_STATESEARCHW_H\r
+   #define __iLBC_STATESEARCHW_H\r
+   \r
+   void AbsQuantW(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *in,          /* (i) vector to encode */\r
+       float *syntDenum,   /* (i) denominator of synthesis filter */\r
+       float *weightDenum, /* (i) denominator of weighting filter */\r
+       int *out,           /* (o) vector of quantizer indexes */\r
+       int len,        /* (i) length of vector to encode and \r
+                                  vector of quantizer indexes */\r
+       int state_first     /* (i) position of start state in the \r
+                                  80 vec */\r
+   );\r
+   \r
+   void StateSearchW( \r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *residual,/* (i) target residual vector */\r
+       float *syntDenum,   /* (i) lpc synthesis filter */\r
+       float *weightDenum, /* (i) weighting filter denuminator */\r
+       int *idxForMax,     /* (o) quantizer index for maximum \r
+                                  amplitude */\r
+       int *idxVec,    /* (o) vector of quantization indexes */\r
+       int len,        /* (i) length of all vectors */\r
+       int state_first     /* (i) position of start state in the \r
+   \r
+   \r
+                                  80 vec */\r
+   );\r
+   \r
+   \r
+   #endif\r
+   \r
+   \r
index bdaee1886ab3d242241c9d70a05bb027f771a620..09ecafb29210bdcdb684d135f99198713d0da098 100644 (file)
@@ -1,71 +1,70 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    anaFilter.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <string.h>\r
-#include "anaFilter.h"\r
-#include "iLBC_define.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  LP analysis filter.\r
-\r
-\r
- *---------------------------------------------------------------*/\r
-    \r
-void anaFilter(\r
-    float *In,  /* (i) Signal to be filtered */\r
-    float *a,   /* (i) LP parameters */\r
-    int len,/* (i) Length of signal */\r
-    float *Out, /* (o) Filtered signal */\r
-    float *mem  /* (i/o) Filter state */\r
-){\r
-    int i, j;\r
-    float *po, *pi, *pm, *pa;\r
-\r
-    po = Out;\r
-\r
-    /* Filter first part using memory from past */\r
-    \r
-    for (i=0; i<LPC_FILTERORDER; i++) {\r
-        pi = &In[i];\r
-        pm = &mem[LPC_FILTERORDER-1];\r
-        pa = a;\r
-        *po=0.0;\r
-        for (j=0; j<=i; j++) {\r
-            *po+=(*pa++)*(*pi--);\r
-        }\r
-        for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
-\r
-            *po+=(*pa++)*(*pm--);\r
-        }\r
-        po++;\r
-    }\r
-\r
-    /* Filter last part where the state is entierly \r
-       in the input vector */\r
-\r
-    for (i=LPC_FILTERORDER; i<len; i++) {\r
-        pi = &In[i];\r
-        pa = a;\r
-        *po=0.0;\r
-        for (j=0; j<LPC_FILTERORDER+1; j++) {\r
-            *po+=(*pa++)*(*pi--);\r
-        }\r
-        po++;\r
-    }\r
-\r
-    /* Update state vector */\r
-\r
-    memcpy(mem, &In[len-LPC_FILTERORDER], \r
-        LPC_FILTERORDER*sizeof(float));\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       anaFilter.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  LP analysis filter.\r
+   \r
+   \r
+    *---------------------------------------------------------------*/\r
+       \r
+   void anaFilter(\r
+       float *In,  /* (i) Signal to be filtered */\r
+       float *a,   /* (i) LP parameters */\r
+       int len,/* (i) Length of signal */\r
+       float *Out, /* (o) Filtered signal */\r
+       float *mem  /* (i/o) Filter state */\r
+   ){\r
+       int i, j;\r
+       float *po, *pi, *pm, *pa;\r
+   \r
+       po = Out;\r
+   \r
+       /* Filter first part using memory from past */\r
+       \r
+       for (i=0; i<LPC_FILTERORDER; i++) {\r
+           pi = &In[i];\r
+           pm = &mem[LPC_FILTERORDER-1];\r
+           pa = a;\r
+           *po=0.0;\r
+           for (j=0; j<=i; j++) {\r
+               *po+=(*pa++)*(*pi--);\r
+           }\r
+           for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
+   \r
+               *po+=(*pa++)*(*pm--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Filter last part where the state is entierly \r
+          in the input vector */\r
+   \r
+       for (i=LPC_FILTERORDER; i<len; i++) {\r
+           pi = &In[i];\r
+           pa = a;\r
+           *po=0.0;\r
+           for (j=0; j<LPC_FILTERORDER+1; j++) {\r
+               *po+=(*pa++)*(*pi--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Update state vector */\r
+   \r
+       memcpy(mem, &In[len-LPC_FILTERORDER], \r
+           LPC_FILTERORDER*sizeof(float));\r
+   }\r
+   \r
+   \r
index e1afd555ac001c63f412ab289f3e5ce1c1b428b6..a9181448a4384932ccfe3aeef4cc1d5bca7594a6 100644 (file)
@@ -1,26 +1,26 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    anaFilter.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_ANAFILTER_H\r
-#define __iLBC_ANAFILTER_H\r
-\r
-void anaFilter(\r
-    float *In,  /* (i) Signal to be filtered */\r
-    float *a,   /* (i) LP parameters */\r
-    int len,/* (i) Length of signal */\r
-    float *Out, /* (o) Filtered signal */\r
-    float *mem  /* (i/o) Filter state */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       anaFilter.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ANAFILTER_H\r
+   #define __iLBC_ANAFILTER_H\r
+   \r
+   void anaFilter(\r
+       float *In,  /* (i) Signal to be filtered */\r
+       float *a,   /* (i) LP parameters */\r
+       int len,/* (i) Length of signal */\r
+       float *Out, /* (o) Filtered signal */\r
+       float *mem  /* (i/o) Filter state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index ee8cb0eb35cc3658613f6aae294b4212adb67cfe..e1504bfce5cc4c6ddeb405f99a8d9371151d8c66 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    constants.c\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include "iLBC_define.h"\r
-\r
-/* ULP bit allocation */\r
-\r
-    /* 20 ms frame */\r
-\r
-const iLBC_ULP_Inst_t ULP_20msTbl = {\r
-    /* LSF */\r
-    {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
-        {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
-    /* Start state location, gain and samples */\r
-    {2,0,0,0,0},\r
-    {1,0,0,0,0},\r
-    {6,0,0,0,0},\r
-    {0,1,2,0,0},\r
-    /* extra CB index and extra CB gain */\r
-    {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
-    {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
-    /* CB index and CB gain */\r
-    {   {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
-        {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
-        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
-        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},\r
-    {   {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
-        {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
-        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
-        {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}\r
-};\r
-\r
-    /* 30 ms frame */\r
-\r
-const iLBC_ULP_Inst_t ULP_30msTbl = {\r
-    /* LSF */\r
-    {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
-\r
-\r
-        {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},\r
-    /* Start state location, gain and samples */\r
-    {3,0,0,0,0},\r
-    {1,0,0,0,0},\r
-    {6,0,0,0,0},\r
-    {0,1,2,0,0},\r
-    /* extra CB index and extra CB gain */\r
-    {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
-    {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
-    /* CB index and CB gain */\r
-    {   {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
-        {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
-        {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
-        {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},\r
-    {   {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},\r
-        {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
-        {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},\r
-        {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}\r
-};\r
-\r
-/* HP Filters */\r
-\r
-float hpi_zero_coefsTbl[3] = {\r
-    (float)0.92727436, (float)-1.8544941, (float)0.92727436\r
-};\r
-float hpi_pole_coefsTbl[3] = {\r
-    (float)1.0, (float)-1.9059465, (float)0.9114024\r
-};\r
-float hpo_zero_coefsTbl[3] = {\r
-    (float)0.93980581, (float)-1.8795834, (float)0.93980581\r
-};\r
-float hpo_pole_coefsTbl[3] = {\r
-    (float)1.0, (float)-1.9330735, (float)0.93589199\r
-};\r
-\r
-/* LP Filter */\r
-\r
-float lpFilt_coefsTbl[FILTERORDER_DS]={\r
-    (float)-0.066650, (float)0.125000, (float)0.316650, \r
-    (float)0.414063, (float)0.316650, \r
-    (float)0.125000, (float)-0.066650\r
-};\r
-\r
-/* State quantization tables */\r
-\r
-float state_sq3Tbl[8] = {\r
-    (float)-3.719849, (float)-2.177490, (float)-1.130005, \r
-    (float)-0.309692, (float)0.444214, (float)1.329712, \r
-    (float)2.436279, (float)3.983887\r
-};\r
-\r
-float state_frgqTbl[64] = {\r
-    (float)1.000085, (float)1.071695, (float)1.140395, \r
-    (float)1.206868, (float)1.277188, (float)1.351503, \r
-\r
-\r
-    (float)1.429380, (float)1.500727, (float)1.569049, \r
-    (float)1.639599, (float)1.707071, (float)1.781531, \r
-    (float)1.840799, (float)1.901550, (float)1.956695, \r
-    (float)2.006750, (float)2.055474, (float)2.102787, \r
-    (float)2.142819, (float)2.183592, (float)2.217962, \r
-    (float)2.257177, (float)2.295739, (float)2.332967, \r
-    (float)2.369248, (float)2.402792, (float)2.435080, \r
-    (float)2.468598, (float)2.503394, (float)2.539284, \r
-    (float)2.572944, (float)2.605036, (float)2.636331, \r
-    (float)2.668939, (float)2.698780, (float)2.729101, \r
-    (float)2.759786, (float)2.789834, (float)2.818679, \r
-    (float)2.848074, (float)2.877470, (float)2.906899, \r
-    (float)2.936655, (float)2.967804, (float)3.000115, \r
-    (float)3.033367, (float)3.066355, (float)3.104231, \r
-    (float)3.141499, (float)3.183012, (float)3.222952, \r
-    (float)3.265433, (float)3.308441, (float)3.350823, \r
-    (float)3.395275, (float)3.442793, (float)3.490801, \r
-    (float)3.542514, (float)3.604064, (float)3.666050, \r
-    (float)3.740994, (float)3.830749, (float)3.938770, \r
-    (float)4.101764\r
-};\r
-\r
-/* CB tables */\r
-\r
-int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, \r
-            {108,108,108}, {108,108,108}, {108,108,108}};\r
-int stMemLTbl=85;\r
-int memLfTbl[NASUB_MAX]={147,147,147,147};\r
-\r
-/* expansion filter(s) */\r
-\r
-float cbfiltersTbl[CB_FILTERLEN]={\r
-    (float)-0.034180, (float)0.108887, (float)-0.184326,\r
-    (float)0.806152,  (float)0.713379, (float)-0.144043,\r
-    (float)0.083740,  (float)-0.033691\r
-};\r
-\r
-/* Gain Quantization */\r
-\r
-float gain_sq3Tbl[8]={\r
-    (float)-1.000000,  (float)-0.659973,  (float)-0.330017,\r
-    (float)0.000000, (float)0.250000, (float)0.500000, \r
-    (float)0.750000, (float)1.00000};\r
-\r
-float gain_sq4Tbl[16]={\r
-    (float)-1.049988, (float)-0.900024, (float)-0.750000, \r
-    (float)-0.599976, (float)-0.450012, (float)-0.299988, \r
-    (float)-0.150024, (float)0.000000, (float)0.150024, \r
-    (float)0.299988, (float)0.450012, (float)0.599976, \r
-    (float)0.750000, (float)0.900024, (float)1.049988, \r
-    (float)1.200012};\r
-\r
-float gain_sq5Tbl[32]={\r
-    (float)0.037476, (float)0.075012, (float)0.112488, \r
-\r
-\r
-    (float)0.150024, (float)0.187500, (float)0.224976, \r
-    (float)0.262512, (float)0.299988, (float)0.337524, \r
-    (float)0.375000, (float)0.412476, (float)0.450012, \r
-    (float)0.487488, (float)0.525024, (float)0.562500, \r
-    (float)0.599976, (float)0.637512, (float)0.674988, \r
-    (float)0.712524, (float)0.750000, (float)0.787476, \r
-    (float)0.825012, (float)0.862488, (float)0.900024, \r
-    (float)0.937500, (float)0.974976, (float)1.012512, \r
-    (float)1.049988, (float)1.087524, (float)1.125000, \r
-    (float)1.162476, (float)1.200012};\r
-\r
-/* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */\r
-float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ \r
-    (float)0.000000, (float)0.000000, (float)0.000000,\r
-(float)1.000000, \r
-        (float)0.000000, (float)0.000000, (float)0.000000, \r
-    (float)0.015625, (float)-0.076904, (float)0.288330,\r
-(float)0.862061, \r
-        (float)-0.106445, (float)0.018799, (float)-0.015625, \r
-    (float)0.023682, (float)-0.124268, (float)0.601563,\r
-(float)0.601563, \r
-        (float)-0.124268, (float)0.023682, (float)-0.023682, \r
-    (float)0.018799, (float)-0.106445, (float)0.862061,\r
-(float)0.288330, \r
-        (float)-0.076904, (float)0.015625, (float)-0.018799};\r
-\r
-float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, \r
-            (float)200.0, (float)280.0, (float)360.0, \r
-            (float)440.0, (float)520.0, (float)600.0};\r
-\r
-/* LPC analysis and quantization */ \r
-\r
-int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};\r
-int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};\r
-\r
-\r
-float lsfmeanTbl[LPC_FILTERORDER] = { \r
-    (float)0.281738, (float)0.445801, (float)0.663330, \r
-    (float)0.962524, (float)1.251831, (float)1.533081, \r
-    (float)1.850586, (float)2.137817, (float)2.481445, \r
-    (float)2.777344};\r
-\r
-float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,\r
-(float)(2.0/3.0), \r
-    (float)(1.0/3.0), (float)0.0, (float)0.0};\r
-\r
-float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), \r
-    (float)(1.0/4.0), (float)(0.0)};\r
-\r
-/* Hanning LPC window */\r
-float lpc_winTbl[BLOCKL_MAX]={\r
-    (float)0.000183, (float)0.000671, (float)0.001526,\r
-    (float)0.002716, (float)0.004242, (float)0.006104,\r
-    (float)0.008301, (float)0.010834, (float)0.013702,\r
-\r
-\r
-    (float)0.016907, (float)0.020416, (float)0.024261,\r
-    (float)0.028442, (float)0.032928, (float)0.037750,\r
-    (float)0.042877, (float)0.048309, (float)0.054047,\r
-    (float)0.060089, (float)0.066437, (float)0.073090,\r
-    (float)0.080017, (float)0.087219, (float)0.094727,\r
-    (float)0.102509, (float)0.110535, (float)0.118835,\r
-    (float)0.127411, (float)0.136230, (float)0.145294,\r
-    (float)0.154602, (float)0.164154, (float)0.173920,\r
-    (float)0.183899, (float)0.194122, (float)0.204529,\r
-    (float)0.215149, (float)0.225952, (float)0.236938,\r
-    (float)0.248108, (float)0.259460, (float)0.270966,\r
-    (float)0.282654, (float)0.294464, (float)0.306396,\r
-    (float)0.318481, (float)0.330688, (float)0.343018,\r
-    (float)0.355438, (float)0.367981, (float)0.380585,\r
-    (float)0.393280, (float)0.406067, (float)0.418884,\r
-    (float)0.431763, (float)0.444702, (float)0.457672,\r
-    (float)0.470673, (float)0.483704, (float)0.496735,\r
-    (float)0.509766, (float)0.522797, (float)0.535828,\r
-    (float)0.548798, (float)0.561768, (float)0.574677,\r
-    (float)0.587524, (float)0.600342, (float)0.613068,\r
-    (float)0.625732, (float)0.638306, (float)0.650787,\r
-    (float)0.663147, (float)0.675415, (float)0.687561,\r
-    (float)0.699585, (float)0.711487, (float)0.723206,\r
-    (float)0.734802, (float)0.746216, (float)0.757477,\r
-    (float)0.768585, (float)0.779480, (float)0.790192,\r
-    (float)0.800720, (float)0.811005, (float)0.821106,\r
-    (float)0.830994, (float)0.840668, (float)0.850067,\r
-    (float)0.859253, (float)0.868225, (float)0.876892,\r
-    (float)0.885345, (float)0.893524, (float)0.901428,\r
-    (float)0.909058, (float)0.916412, (float)0.923492,\r
-    (float)0.930267, (float)0.936768, (float)0.942963,\r
-    (float)0.948853, (float)0.954437, (float)0.959717,\r
-    (float)0.964691, (float)0.969360, (float)0.973694,\r
-    (float)0.977692, (float)0.981384, (float)0.984741,\r
-    (float)0.987762, (float)0.990479, (float)0.992828,\r
-    (float)0.994873, (float)0.996552, (float)0.997925,\r
-    (float)0.998932, (float)0.999603, (float)0.999969,\r
-    (float)0.999969, (float)0.999603, (float)0.998932,\r
-    (float)0.997925, (float)0.996552, (float)0.994873,\r
-    (float)0.992828, (float)0.990479, (float)0.987762,\r
-    (float)0.984741, (float)0.981384, (float)0.977692,\r
-    (float)0.973694, (float)0.969360, (float)0.964691,\r
-    (float)0.959717, (float)0.954437, (float)0.948853,\r
-    (float)0.942963, (float)0.936768, (float)0.930267,\r
-    (float)0.923492, (float)0.916412, (float)0.909058,\r
-    (float)0.901428, (float)0.893524, (float)0.885345,\r
-    (float)0.876892, (float)0.868225, (float)0.859253,\r
-    (float)0.850067, (float)0.840668, (float)0.830994,\r
-    (float)0.821106, (float)0.811005, (float)0.800720,\r
-    (float)0.790192, (float)0.779480, (float)0.768585,\r
-    (float)0.757477, (float)0.746216, (float)0.734802,\r
-    (float)0.723206, (float)0.711487, (float)0.699585,\r
-    (float)0.687561, (float)0.675415, (float)0.663147,\r
-    (float)0.650787, (float)0.638306, (float)0.625732,\r
-\r
-\r
-    (float)0.613068, (float)0.600342, (float)0.587524,\r
-    (float)0.574677, (float)0.561768, (float)0.548798,\r
-    (float)0.535828, (float)0.522797, (float)0.509766,\r
-    (float)0.496735, (float)0.483704, (float)0.470673,\r
-    (float)0.457672, (float)0.444702, (float)0.431763,\r
-    (float)0.418884, (float)0.406067, (float)0.393280,\r
-    (float)0.380585, (float)0.367981, (float)0.355438,\r
-    (float)0.343018, (float)0.330688, (float)0.318481,\r
-    (float)0.306396, (float)0.294464, (float)0.282654,\r
-    (float)0.270966, (float)0.259460, (float)0.248108,\r
-    (float)0.236938, (float)0.225952, (float)0.215149,\r
-    (float)0.204529, (float)0.194122, (float)0.183899,\r
-    (float)0.173920, (float)0.164154, (float)0.154602,\r
-    (float)0.145294, (float)0.136230, (float)0.127411,\r
-    (float)0.118835, (float)0.110535, (float)0.102509,\r
-    (float)0.094727, (float)0.087219, (float)0.080017,\r
-    (float)0.073090, (float)0.066437, (float)0.060089,\r
-    (float)0.054047, (float)0.048309, (float)0.042877,\r
-    (float)0.037750, (float)0.032928, (float)0.028442,\r
-    (float)0.024261, (float)0.020416, (float)0.016907,\r
-    (float)0.013702, (float)0.010834, (float)0.008301,\r
-    (float)0.006104, (float)0.004242, (float)0.002716,\r
-    (float)0.001526, (float)0.000671, (float)0.000183\r
-};\r
-\r
-/* Asymmetric LPC window */\r
-float lpc_asymwinTbl[BLOCKL_MAX]={\r
-    (float)0.000061, (float)0.000214, (float)0.000458,\r
-    (float)0.000824, (float)0.001282, (float)0.001831,\r
-    (float)0.002472, (float)0.003235, (float)0.004120,\r
-    (float)0.005066, (float)0.006134, (float)0.007294,\r
-    (float)0.008545, (float)0.009918, (float)0.011383,\r
-    (float)0.012939, (float)0.014587, (float)0.016357,\r
-    (float)0.018219, (float)0.020172, (float)0.022217,\r
-    (float)0.024353, (float)0.026611, (float)0.028961,\r
-    (float)0.031372, (float)0.033905, (float)0.036530,\r
-    (float)0.039276, (float)0.042084, (float)0.044983,\r
-    (float)0.047974, (float)0.051086, (float)0.054260,\r
-    (float)0.057526, (float)0.060883, (float)0.064331,\r
-    (float)0.067871, (float)0.071503, (float)0.075226,\r
-    (float)0.079010, (float)0.082916, (float)0.086884,\r
-    (float)0.090942, (float)0.095062, (float)0.099304,\r
-    (float)0.103607, (float)0.107971, (float)0.112427,\r
-    (float)0.116974, (float)0.121582, (float)0.126282,\r
-    (float)0.131073, (float)0.135895, (float)0.140839,\r
-    (float)0.145813, (float)0.150879, (float)0.156006,\r
-    (float)0.161224, (float)0.166504, (float)0.171844,\r
-    (float)0.177246, (float)0.182709, (float)0.188263,\r
-    (float)0.193848, (float)0.199524, (float)0.205231,\r
-    (float)0.211029, (float)0.216858, (float)0.222778,\r
-    (float)0.228729, (float)0.234741, (float)0.240814,\r
-    (float)0.246918, (float)0.253082, (float)0.259308,\r
-    (float)0.265564, (float)0.271881, (float)0.278259,\r
-    (float)0.284668, (float)0.291107, (float)0.297607,\r
-\r
-\r
-    (float)0.304138, (float)0.310730, (float)0.317322,\r
-    (float)0.323975, (float)0.330658, (float)0.337372,\r
-    (float)0.344147, (float)0.350922, (float)0.357727,\r
-    (float)0.364594, (float)0.371460, (float)0.378357,\r
-    (float)0.385284, (float)0.392212, (float)0.399170,\r
-    (float)0.406158, (float)0.413177, (float)0.420197,\r
-    (float)0.427246, (float)0.434296, (float)0.441376,\r
-    (float)0.448456, (float)0.455536, (float)0.462646,\r
-    (float)0.469757, (float)0.476868, (float)0.483978,\r
-    (float)0.491089, (float)0.498230, (float)0.505341,\r
-    (float)0.512451, (float)0.519592, (float)0.526703,\r
-    (float)0.533813, (float)0.540924, (float)0.548004,\r
-    (float)0.555084, (float)0.562164, (float)0.569244,\r
-    (float)0.576294, (float)0.583313, (float)0.590332,\r
-    (float)0.597321, (float)0.604309, (float)0.611267,\r
-    (float)0.618195, (float)0.625092, (float)0.631989,\r
-    (float)0.638855, (float)0.645660, (float)0.652466,\r
-    (float)0.659241, (float)0.665985, (float)0.672668,\r
-    (float)0.679352, (float)0.685974, (float)0.692566,\r
-    (float)0.699127, (float)0.705658, (float)0.712128,\r
-    (float)0.718536, (float)0.724945, (float)0.731262,\r
-    (float)0.737549, (float)0.743805, (float)0.750000,\r
-    (float)0.756134, (float)0.762238, (float)0.768280,\r
-    (float)0.774261, (float)0.780182, (float)0.786072,\r
-    (float)0.791870, (float)0.797638, (float)0.803314,\r
-    (float)0.808960, (float)0.814514, (float)0.820038,\r
-    (float)0.825470, (float)0.830841, (float)0.836151,\r
-    (float)0.841400, (float)0.846558, (float)0.851654,\r
-    (float)0.856689, (float)0.861633, (float)0.866516,\r
-    (float)0.871338, (float)0.876068, (float)0.880737,\r
-    (float)0.885315, (float)0.889801, (float)0.894226,\r
-    (float)0.898560, (float)0.902832, (float)0.907013,\r
-    (float)0.911102, (float)0.915100, (float)0.919037,\r
-    (float)0.922882, (float)0.926636, (float)0.930328,\r
-    (float)0.933899, (float)0.937408, (float)0.940796,\r
-    (float)0.944122, (float)0.947357, (float)0.950470,\r
-    (float)0.953522, (float)0.956482, (float)0.959351,\r
-    (float)0.962097, (float)0.964783, (float)0.967377,\r
-    (float)0.969849, (float)0.972229, (float)0.974518,\r
-    (float)0.976715, (float)0.978821, (float)0.980835,\r
-    (float)0.982727, (float)0.984528, (float)0.986237,\r
-    (float)0.987854, (float)0.989380, (float)0.990784,\r
-    (float)0.992096, (float)0.993317, (float)0.994415,\r
-    (float)0.995422, (float)0.996338, (float)0.997162,\r
-    (float)0.997864, (float)0.998474, (float)0.998962,\r
-    (float)0.999390, (float)0.999695, (float)0.999878,\r
-    (float)0.999969, (float)0.999969, (float)0.996918,\r
-    (float)0.987701, (float)0.972382, (float)0.951050,\r
-    (float)0.923889, (float)0.891022, (float)0.852631,\r
-    (float)0.809021, (float)0.760406, (float)0.707092,\r
-    (float)0.649445, (float)0.587799, (float)0.522491,\r
-    (float)0.453979, (float)0.382690, (float)0.309021,\r
-    (float)0.233459, (float)0.156433, (float)0.078461\r
-};\r
-\r
-\r
-\r
-/* Lag window for LPC */\r
-float lpc_lagwinTbl[LPC_FILTERORDER + 1]={\r
-    (float)1.000100, (float)0.998890, (float)0.995569,\r
-        (float)0.990057, (float)0.982392,\r
-    (float)0.972623, (float)0.960816, (float)0.947047,\r
-        (float)0.931405, (float)0.913989, (float)0.894909};\r
-\r
-/* LSF quantization*/\r
-float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {\r
-(float)0.155396, (float)0.273193, (float)0.451172,\r
-(float)0.390503, (float)0.648071, (float)1.002075,\r
-(float)0.440186, (float)0.692261, (float)0.955688,\r
-(float)0.343628, (float)0.642334, (float)1.071533,\r
-(float)0.318359, (float)0.491577, (float)0.670532,\r
-(float)0.193115, (float)0.375488, (float)0.725708,\r
-(float)0.364136, (float)0.510376, (float)0.658691,\r
-(float)0.297485, (float)0.527588, (float)0.842529,\r
-(float)0.227173, (float)0.365967, (float)0.563110,\r
-(float)0.244995, (float)0.396729, (float)0.636475,\r
-(float)0.169434, (float)0.300171, (float)0.520264,\r
-(float)0.312866, (float)0.464478, (float)0.643188,\r
-(float)0.248535, (float)0.429932, (float)0.626099,\r
-(float)0.236206, (float)0.491333, (float)0.817139,\r
-(float)0.334961, (float)0.625122, (float)0.895752,\r
-(float)0.343018, (float)0.518555, (float)0.698608,\r
-(float)0.372803, (float)0.659790, (float)0.945435,\r
-(float)0.176880, (float)0.316528, (float)0.581421,\r
-(float)0.416382, (float)0.625977, (float)0.805176,\r
-(float)0.303223, (float)0.568726, (float)0.915039,\r
-(float)0.203613, (float)0.351440, (float)0.588135,\r
-(float)0.221191, (float)0.375000, (float)0.614746,\r
-(float)0.199951, (float)0.323364, (float)0.476074,\r
-(float)0.300781, (float)0.433350, (float)0.566895,\r
-(float)0.226196, (float)0.354004, (float)0.507568,\r
-(float)0.300049, (float)0.508179, (float)0.711670,\r
-(float)0.312012, (float)0.492676, (float)0.763428,\r
-(float)0.329956, (float)0.541016, (float)0.795776,\r
-(float)0.373779, (float)0.604614, (float)0.928833,\r
-(float)0.210571, (float)0.452026, (float)0.755249,\r
-(float)0.271118, (float)0.473267, (float)0.662476,\r
-(float)0.285522, (float)0.436890, (float)0.634399,\r
-(float)0.246704, (float)0.565552, (float)0.859009,\r
-(float)0.270508, (float)0.406250, (float)0.553589,\r
-(float)0.361450, (float)0.578491, (float)0.813843,\r
-(float)0.342651, (float)0.482788, (float)0.622437,\r
-(float)0.340332, (float)0.549438, (float)0.743164,\r
-(float)0.200439, (float)0.336304, (float)0.540894,\r
-(float)0.407837, (float)0.644775, (float)0.895142,\r
-(float)0.294678, (float)0.454834, (float)0.699097,\r
-(float)0.193115, (float)0.344482, (float)0.643188,\r
-(float)0.275757, (float)0.420776, (float)0.598755,\r
-(float)0.380493, (float)0.608643, (float)0.861084,\r
-(float)0.222778, (float)0.426147, (float)0.676514,\r
-\r
-\r
-(float)0.407471, (float)0.700195, (float)1.053101,\r
-(float)0.218384, (float)0.377197, (float)0.669922,\r
-(float)0.313232, (float)0.454102, (float)0.600952,\r
-(float)0.347412, (float)0.571533, (float)0.874146,\r
-(float)0.238037, (float)0.405396, (float)0.729492,\r
-(float)0.223877, (float)0.412964, (float)0.822021,\r
-(float)0.395264, (float)0.582153, (float)0.743896,\r
-(float)0.247925, (float)0.485596, (float)0.720581,\r
-(float)0.229126, (float)0.496582, (float)0.907715,\r
-(float)0.260132, (float)0.566895, (float)1.012695,\r
-(float)0.337402, (float)0.611572, (float)0.978149,\r
-(float)0.267822, (float)0.447632, (float)0.769287,\r
-(float)0.250610, (float)0.381714, (float)0.530029,\r
-(float)0.430054, (float)0.805054, (float)1.221924,\r
-(float)0.382568, (float)0.544067, (float)0.701660,\r
-(float)0.383545, (float)0.710327, (float)1.149170,\r
-(float)0.271362, (float)0.529053, (float)0.775513,\r
-(float)0.246826, (float)0.393555, (float)0.588623,\r
-(float)0.266846, (float)0.422119, (float)0.676758,\r
-(float)0.311523, (float)0.580688, (float)0.838623,\r
-(float)1.331177, (float)1.576782, (float)1.779541,\r
-(float)1.160034, (float)1.401978, (float)1.768188,\r
-(float)1.161865, (float)1.525146, (float)1.715332,\r
-(float)0.759521, (float)0.913940, (float)1.119873,\r
-(float)0.947144, (float)1.121338, (float)1.282471,\r
-(float)1.015015, (float)1.557007, (float)1.804932,\r
-(float)1.172974, (float)1.402100, (float)1.692627,\r
-(float)1.087524, (float)1.474243, (float)1.665405,\r
-(float)0.899536, (float)1.105225, (float)1.406250,\r
-(float)1.148438, (float)1.484741, (float)1.796265,\r
-(float)0.785645, (float)1.209839, (float)1.567749,\r
-(float)0.867798, (float)1.166504, (float)1.450684,\r
-(float)0.922485, (float)1.229858, (float)1.420898,\r
-(float)0.791260, (float)1.123291, (float)1.409546,\r
-(float)0.788940, (float)0.966064, (float)1.340332,\r
-(float)1.051147, (float)1.272827, (float)1.556641,\r
-(float)0.866821, (float)1.181152, (float)1.538818,\r
-(float)0.906738, (float)1.373535, (float)1.607910,\r
-(float)1.244751, (float)1.581421, (float)1.933838,\r
-(float)0.913940, (float)1.337280, (float)1.539673,\r
-(float)0.680542, (float)0.959229, (float)1.662720,\r
-(float)0.887207, (float)1.430542, (float)1.800781,\r
-(float)0.912598, (float)1.433594, (float)1.683960,\r
-(float)0.860474, (float)1.060303, (float)1.455322,\r
-(float)1.005127, (float)1.381104, (float)1.706909,\r
-(float)0.800781, (float)1.363892, (float)1.829102,\r
-(float)0.781860, (float)1.124390, (float)1.505981,\r
-(float)1.003662, (float)1.471436, (float)1.684692,\r
-(float)0.981323, (float)1.309570, (float)1.618042,\r
-(float)1.228760, (float)1.554321, (float)1.756470,\r
-(float)0.734375, (float)0.895752, (float)1.225586,\r
-(float)0.841797, (float)1.055664, (float)1.249268,\r
-(float)0.920166, (float)1.119385, (float)1.486206,\r
-(float)0.894409, (float)1.539063, (float)1.828979,\r
-\r
-\r
-(float)1.283691, (float)1.543335, (float)1.858276,\r
-(float)0.676025, (float)0.933105, (float)1.490845,\r
-(float)0.821289, (float)1.491821, (float)1.739868,\r
-(float)0.923218, (float)1.144653, (float)1.580566,\r
-(float)1.057251, (float)1.345581, (float)1.635864,\r
-(float)0.888672, (float)1.074951, (float)1.353149,\r
-(float)0.942749, (float)1.195435, (float)1.505493,\r
-(float)1.492310, (float)1.788086, (float)2.039673,\r
-(float)1.070313, (float)1.634399, (float)1.860962,\r
-(float)1.253296, (float)1.488892, (float)1.686035,\r
-(float)0.647095, (float)0.864014, (float)1.401855,\r
-(float)0.866699, (float)1.254883, (float)1.453369,\r
-(float)1.063965, (float)1.532593, (float)1.731323,\r
-(float)1.167847, (float)1.521484, (float)1.884033,\r
-(float)0.956055, (float)1.502075, (float)1.745605,\r
-(float)0.928711, (float)1.288574, (float)1.479614,\r
-(float)1.088013, (float)1.380737, (float)1.570801,\r
-(float)0.905029, (float)1.186768, (float)1.371948,\r
-(float)1.057861, (float)1.421021, (float)1.617432,\r
-(float)1.108276, (float)1.312500, (float)1.501465,\r
-(float)0.979492, (float)1.416992, (float)1.624268,\r
-(float)1.276001, (float)1.661011, (float)2.007935,\r
-(float)0.993042, (float)1.168579, (float)1.331665,\r
-(float)0.778198, (float)0.944946, (float)1.235962,\r
-(float)1.223755, (float)1.491333, (float)1.815674,\r
-(float)0.852661, (float)1.350464, (float)1.722290,\r
-(float)1.134766, (float)1.593140, (float)1.787354,\r
-(float)1.051392, (float)1.339722, (float)1.531006,\r
-(float)0.803589, (float)1.271240, (float)1.652100,\r
-(float)0.755737, (float)1.143555, (float)1.639404,\r
-(float)0.700928, (float)0.837280, (float)1.130371,\r
-(float)0.942749, (float)1.197876, (float)1.669800,\r
-(float)0.993286, (float)1.378296, (float)1.566528,\r
-(float)0.801025, (float)1.095337, (float)1.298950,\r
-(float)0.739990, (float)1.032959, (float)1.383667,\r
-(float)0.845703, (float)1.072266, (float)1.543823,\r
-(float)0.915649, (float)1.072266, (float)1.224487,\r
-(float)1.021973, (float)1.226196, (float)1.481323,\r
-(float)0.999878, (float)1.204102, (float)1.555908,\r
-(float)0.722290, (float)0.913940, (float)1.340210,\r
-(float)0.673340, (float)0.835938, (float)1.259521,\r
-(float)0.832397, (float)1.208374, (float)1.394165,\r
-(float)0.962158, (float)1.576172, (float)1.912842,\r
-(float)1.166748, (float)1.370850, (float)1.556763,\r
-(float)0.946289, (float)1.138550, (float)1.400391,\r
-(float)1.035034, (float)1.218262, (float)1.386475,\r
-(float)1.393799, (float)1.717773, (float)2.000244,\r
-(float)0.972656, (float)1.260986, (float)1.760620,\r
-(float)1.028198, (float)1.288452, (float)1.484619,\r
-(float)0.773560, (float)1.258057, (float)1.756714,\r
-(float)1.080322, (float)1.328003, (float)1.742676,\r
-(float)0.823975, (float)1.450806, (float)1.917725,\r
-(float)0.859009, (float)1.016602, (float)1.191895,\r
-(float)0.843994, (float)1.131104, (float)1.645020,\r
-\r
-\r
-(float)1.189697, (float)1.702759, (float)1.894409,\r
-(float)1.346680, (float)1.763184, (float)2.066040,\r
-(float)0.980469, (float)1.253784, (float)1.441650,\r
-(float)1.338135, (float)1.641968, (float)1.932739,\r
-(float)1.223267, (float)1.424194, (float)1.626465,\r
-(float)0.765747, (float)1.004150, (float)1.579102,\r
-(float)1.042847, (float)1.269165, (float)1.647461,\r
-(float)0.968750, (float)1.257568, (float)1.555786,\r
-(float)0.826294, (float)0.993408, (float)1.275146,\r
-(float)0.742310, (float)0.950439, (float)1.430542,\r
-(float)1.054321, (float)1.439819, (float)1.828003,\r
-(float)1.072998, (float)1.261719, (float)1.441895,\r
-(float)0.859375, (float)1.036377, (float)1.314819,\r
-(float)0.895752, (float)1.267212, (float)1.605591,\r
-(float)0.805420, (float)0.962891, (float)1.142334,\r
-(float)0.795654, (float)1.005493, (float)1.468506,\r
-(float)1.105347, (float)1.313843, (float)1.584839,\r
-(float)0.792236, (float)1.221802, (float)1.465698,\r
-(float)1.170532, (float)1.467651, (float)1.664063,\r
-(float)0.838257, (float)1.153198, (float)1.342163,\r
-(float)0.968018, (float)1.198242, (float)1.391235,\r
-(float)1.250122, (float)1.623535, (float)1.823608,\r
-(float)0.711670, (float)1.058350, (float)1.512085,\r
-(float)1.204834, (float)1.454468, (float)1.739136,\r
-(float)1.137451, (float)1.421753, (float)1.620117,\r
-(float)0.820435, (float)1.322754, (float)1.578247,\r
-(float)0.798706, (float)1.005005, (float)1.213867,\r
-(float)0.980713, (float)1.324951, (float)1.512939,\r
-(float)1.112305, (float)1.438843, (float)1.735596,\r
-(float)1.135498, (float)1.356689, (float)1.635742,\r
-(float)1.101318, (float)1.387451, (float)1.686523,\r
-(float)0.849854, (float)1.276978, (float)1.523438,\r
-(float)1.377930, (float)1.627563, (float)1.858154,\r
-(float)0.884888, (float)1.095459, (float)1.287476,\r
-(float)1.289795, (float)1.505859, (float)1.756592,\r
-(float)0.817505, (float)1.384155, (float)1.650513,\r
-(float)1.446655, (float)1.702148, (float)1.931885,\r
-(float)0.835815, (float)1.023071, (float)1.385376,\r
-(float)0.916626, (float)1.139038, (float)1.335327,\r
-(float)0.980103, (float)1.174072, (float)1.453735,\r
-(float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,\r
-(float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,\r
-(float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,\r
-(float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,\r
-(float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,\r
-(float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,\r
-(float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,\r
-(float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,\r
-(float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,\r
-(float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,\r
-(float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,\r
-(float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,\r
-(float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,\r
-(float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,\r
-\r
-\r
-(float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,\r
-(float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,\r
-(float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,\r
-(float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,\r
-(float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,\r
-(float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,\r
-(float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,\r
-(float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,\r
-(float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,\r
-(float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,\r
-(float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,\r
-(float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,\r
-(float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,\r
-(float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,\r
-(float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,\r
-(float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,\r
-(float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,\r
-(float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,\r
-(float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,\r
-(float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,\r
-(float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,\r
-(float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,\r
-(float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,\r
-(float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,\r
-(float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,\r
-(float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,\r
-(float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,\r
-(float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,\r
-(float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,\r
-(float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,\r
-(float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,\r
-(float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,\r
-(float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,\r
-(float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,\r
-(float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,\r
-(float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,\r
-(float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,\r
-(float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,\r
-(float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,\r
-(float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,\r
-(float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,\r
-(float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,\r
-(float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,\r
-(float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,\r
-(float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,\r
-(float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,\r
-(float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,\r
-(float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,\r
-(float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,\r
-(float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,\r
-(float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,\r
-(float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,\r
-(float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,\r
-(float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,\r
-\r
-\r
-(float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,\r
-(float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,\r
-(float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,\r
-(float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,\r
-(float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,\r
-(float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,\r
-(float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,\r
-(float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,\r
-(float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,\r
-(float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,\r
-(float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,\r
-(float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,\r
-(float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,\r
-(float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,\r
-(float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,\r
-(float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,\r
-(float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,\r
-(float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,\r
-(float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,\r
-(float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,\r
-(float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,\r
-(float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,\r
-(float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,\r
-(float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,\r
-(float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,\r
-(float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,\r
-(float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,\r
-(float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,\r
-(float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,\r
-(float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,\r
-(float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,\r
-(float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,\r
-(float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,\r
-(float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,\r
-(float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,\r
-(float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,\r
-(float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,\r
-(float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,\r
-(float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,\r
-(float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,\r
-(float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,\r
-(float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,\r
-(float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,\r
-(float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,\r
-(float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,\r
-(float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,\r
-(float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,\r
-(float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,\r
-(float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,\r
-(float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,\r
-(float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,\r
-(float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,\r
-(float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,\r
-(float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,\r
-\r
-\r
-(float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,\r
-(float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,\r
-(float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,\r
-(float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,\r
-(float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,\r
-(float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143\r
-};\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       constants.c\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /* ULP bit allocation */\r
+   \r
+       /* 20 ms frame */\r
+   \r
+   const iLBC_ULP_Inst_t ULP_20msTbl = {\r
+       /* LSF */\r
+       {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
+           {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+       /* Start state location, gain and samples */\r
+       {2,0,0,0,0},\r
+       {1,0,0,0,0},\r
+       {6,0,0,0,0},\r
+       {0,1,2,0,0},\r
+       /* extra CB index and extra CB gain */\r
+       {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+       {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+       /* CB index and CB gain */\r
+       {   {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+           {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},\r
+       {   {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+           {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}\r
+   };\r
+   \r
+       /* 30 ms frame */\r
+   \r
+   const iLBC_ULP_Inst_t ULP_30msTbl = {\r
+       /* LSF */\r
+       {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
+   \r
+   \r
+           {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},\r
+       /* Start state location, gain and samples */\r
+       {3,0,0,0,0},\r
+       {1,0,0,0,0},\r
+       {6,0,0,0,0},\r
+       {0,1,2,0,0},\r
+       /* extra CB index and extra CB gain */\r
+       {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+       {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+       /* CB index and CB gain */\r
+       {   {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},\r
+       {   {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},\r
+           {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
+           {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},\r
+           {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}\r
+   };\r
+   \r
+   /* HP Filters */\r
+   \r
+   float hpi_zero_coefsTbl[3] = {\r
+       (float)0.92727436, (float)-1.8544941, (float)0.92727436\r
+   };\r
+   float hpi_pole_coefsTbl[3] = {\r
+       (float)1.0, (float)-1.9059465, (float)0.9114024\r
+   };\r
+   float hpo_zero_coefsTbl[3] = {\r
+       (float)0.93980581, (float)-1.8795834, (float)0.93980581\r
+   };\r
+   float hpo_pole_coefsTbl[3] = {\r
+       (float)1.0, (float)-1.9330735, (float)0.93589199\r
+   };\r
+   \r
+   /* LP Filter */\r
+   \r
+   float lpFilt_coefsTbl[FILTERORDER_DS]={\r
+       (float)-0.066650, (float)0.125000, (float)0.316650, \r
+       (float)0.414063, (float)0.316650, \r
+       (float)0.125000, (float)-0.066650\r
+   };\r
+   \r
+   /* State quantization tables */\r
+   \r
+   float state_sq3Tbl[8] = {\r
+       (float)-3.719849, (float)-2.177490, (float)-1.130005, \r
+       (float)-0.309692, (float)0.444214, (float)1.329712, \r
+       (float)2.436279, (float)3.983887\r
+   };\r
+   \r
+   float state_frgqTbl[64] = {\r
+       (float)1.000085, (float)1.071695, (float)1.140395, \r
+       (float)1.206868, (float)1.277188, (float)1.351503, \r
+   \r
+   \r
+       (float)1.429380, (float)1.500727, (float)1.569049, \r
+       (float)1.639599, (float)1.707071, (float)1.781531, \r
+       (float)1.840799, (float)1.901550, (float)1.956695, \r
+       (float)2.006750, (float)2.055474, (float)2.102787, \r
+       (float)2.142819, (float)2.183592, (float)2.217962, \r
+       (float)2.257177, (float)2.295739, (float)2.332967, \r
+       (float)2.369248, (float)2.402792, (float)2.435080, \r
+       (float)2.468598, (float)2.503394, (float)2.539284, \r
+       (float)2.572944, (float)2.605036, (float)2.636331, \r
+       (float)2.668939, (float)2.698780, (float)2.729101, \r
+       (float)2.759786, (float)2.789834, (float)2.818679, \r
+       (float)2.848074, (float)2.877470, (float)2.906899, \r
+       (float)2.936655, (float)2.967804, (float)3.000115, \r
+       (float)3.033367, (float)3.066355, (float)3.104231, \r
+       (float)3.141499, (float)3.183012, (float)3.222952, \r
+       (float)3.265433, (float)3.308441, (float)3.350823, \r
+       (float)3.395275, (float)3.442793, (float)3.490801, \r
+       (float)3.542514, (float)3.604064, (float)3.666050, \r
+       (float)3.740994, (float)3.830749, (float)3.938770, \r
+       (float)4.101764\r
+   };\r
+   \r
+   /* CB tables */\r
+   \r
+   int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, \r
+               {108,108,108}, {108,108,108}, {108,108,108}};\r
+   int stMemLTbl=85;\r
+   int memLfTbl[NASUB_MAX]={147,147,147,147};\r
+   \r
+   /* expansion filter(s) */\r
+   \r
+   float cbfiltersTbl[CB_FILTERLEN]={\r
+       (float)-0.034180, (float)0.108887, (float)-0.184326,\r
+       (float)0.806152,  (float)0.713379, (float)-0.144043,\r
+       (float)0.083740,  (float)-0.033691\r
+   };\r
+   \r
+   /* Gain Quantization */\r
+   \r
+   float gain_sq3Tbl[8]={\r
+       (float)-1.000000,  (float)-0.659973,  (float)-0.330017,\r
+       (float)0.000000, (float)0.250000, (float)0.500000, \r
+       (float)0.750000, (float)1.00000};\r
+   \r
+   float gain_sq4Tbl[16]={\r
+       (float)-1.049988, (float)-0.900024, (float)-0.750000, \r
+       (float)-0.599976, (float)-0.450012, (float)-0.299988, \r
+       (float)-0.150024, (float)0.000000, (float)0.150024, \r
+       (float)0.299988, (float)0.450012, (float)0.599976, \r
+       (float)0.750000, (float)0.900024, (float)1.049988, \r
+       (float)1.200012};\r
+   \r
+   float gain_sq5Tbl[32]={\r
+       (float)0.037476, (float)0.075012, (float)0.112488, \r
+   \r
+   \r
+       (float)0.150024, (float)0.187500, (float)0.224976, \r
+       (float)0.262512, (float)0.299988, (float)0.337524, \r
+       (float)0.375000, (float)0.412476, (float)0.450012, \r
+       (float)0.487488, (float)0.525024, (float)0.562500, \r
+       (float)0.599976, (float)0.637512, (float)0.674988, \r
+       (float)0.712524, (float)0.750000, (float)0.787476, \r
+       (float)0.825012, (float)0.862488, (float)0.900024, \r
+       (float)0.937500, (float)0.974976, (float)1.012512, \r
+       (float)1.049988, (float)1.087524, (float)1.125000, \r
+       (float)1.162476, (float)1.200012};\r
+   \r
+   /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */\r
+   float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ \r
+       (float)0.000000, (float)0.000000, (float)0.000000,\r
+   (float)1.000000, \r
+           (float)0.000000, (float)0.000000, (float)0.000000, \r
+       (float)0.015625, (float)-0.076904, (float)0.288330,\r
+   (float)0.862061, \r
+           (float)-0.106445, (float)0.018799, (float)-0.015625, \r
+       (float)0.023682, (float)-0.124268, (float)0.601563,\r
+   (float)0.601563, \r
+           (float)-0.124268, (float)0.023682, (float)-0.023682, \r
+       (float)0.018799, (float)-0.106445, (float)0.862061,\r
+   (float)0.288330, \r
+           (float)-0.076904, (float)0.015625, (float)-0.018799};\r
+   \r
+   float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, \r
+               (float)200.0, (float)280.0, (float)360.0, \r
+               (float)440.0, (float)520.0, (float)600.0};\r
+   \r
+   /* LPC analysis and quantization */ \r
+   \r
+   int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};\r
+   int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};\r
+   \r
+   \r
+   float lsfmeanTbl[LPC_FILTERORDER] = { \r
+       (float)0.281738, (float)0.445801, (float)0.663330, \r
+       (float)0.962524, (float)1.251831, (float)1.533081, \r
+       (float)1.850586, (float)2.137817, (float)2.481445, \r
+       (float)2.777344};\r
+   \r
+   float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,\r
+   (float)(2.0/3.0), \r
+       (float)(1.0/3.0), (float)0.0, (float)0.0};\r
+   \r
+   float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), \r
+       (float)(1.0/4.0), (float)(0.0)};\r
+   \r
+   /* Hanning LPC window */\r
+   float lpc_winTbl[BLOCKL_MAX]={\r
+       (float)0.000183, (float)0.000671, (float)0.001526,\r
+       (float)0.002716, (float)0.004242, (float)0.006104,\r
+       (float)0.008301, (float)0.010834, (float)0.013702,\r
+   \r
+   \r
+       (float)0.016907, (float)0.020416, (float)0.024261,\r
+       (float)0.028442, (float)0.032928, (float)0.037750,\r
+       (float)0.042877, (float)0.048309, (float)0.054047,\r
+       (float)0.060089, (float)0.066437, (float)0.073090,\r
+       (float)0.080017, (float)0.087219, (float)0.094727,\r
+       (float)0.102509, (float)0.110535, (float)0.118835,\r
+       (float)0.127411, (float)0.136230, (float)0.145294,\r
+       (float)0.154602, (float)0.164154, (float)0.173920,\r
+       (float)0.183899, (float)0.194122, (float)0.204529,\r
+       (float)0.215149, (float)0.225952, (float)0.236938,\r
+       (float)0.248108, (float)0.259460, (float)0.270966,\r
+       (float)0.282654, (float)0.294464, (float)0.306396,\r
+       (float)0.318481, (float)0.330688, (float)0.343018,\r
+       (float)0.355438, (float)0.367981, (float)0.380585,\r
+       (float)0.393280, (float)0.406067, (float)0.418884,\r
+       (float)0.431763, (float)0.444702, (float)0.457672,\r
+       (float)0.470673, (float)0.483704, (float)0.496735,\r
+       (float)0.509766, (float)0.522797, (float)0.535828,\r
+       (float)0.548798, (float)0.561768, (float)0.574677,\r
+       (float)0.587524, (float)0.600342, (float)0.613068,\r
+       (float)0.625732, (float)0.638306, (float)0.650787,\r
+       (float)0.663147, (float)0.675415, (float)0.687561,\r
+       (float)0.699585, (float)0.711487, (float)0.723206,\r
+       (float)0.734802, (float)0.746216, (float)0.757477,\r
+       (float)0.768585, (float)0.779480, (float)0.790192,\r
+       (float)0.800720, (float)0.811005, (float)0.821106,\r
+       (float)0.830994, (float)0.840668, (float)0.850067,\r
+       (float)0.859253, (float)0.868225, (float)0.876892,\r
+       (float)0.885345, (float)0.893524, (float)0.901428,\r
+       (float)0.909058, (float)0.916412, (float)0.923492,\r
+       (float)0.930267, (float)0.936768, (float)0.942963,\r
+       (float)0.948853, (float)0.954437, (float)0.959717,\r
+       (float)0.964691, (float)0.969360, (float)0.973694,\r
+       (float)0.977692, (float)0.981384, (float)0.984741,\r
+       (float)0.987762, (float)0.990479, (float)0.992828,\r
+       (float)0.994873, (float)0.996552, (float)0.997925,\r
+       (float)0.998932, (float)0.999603, (float)0.999969,\r
+       (float)0.999969, (float)0.999603, (float)0.998932,\r
+       (float)0.997925, (float)0.996552, (float)0.994873,\r
+       (float)0.992828, (float)0.990479, (float)0.987762,\r
+       (float)0.984741, (float)0.981384, (float)0.977692,\r
+       (float)0.973694, (float)0.969360, (float)0.964691,\r
+       (float)0.959717, (float)0.954437, (float)0.948853,\r
+       (float)0.942963, (float)0.936768, (float)0.930267,\r
+       (float)0.923492, (float)0.916412, (float)0.909058,\r
+       (float)0.901428, (float)0.893524, (float)0.885345,\r
+       (float)0.876892, (float)0.868225, (float)0.859253,\r
+       (float)0.850067, (float)0.840668, (float)0.830994,\r
+       (float)0.821106, (float)0.811005, (float)0.800720,\r
+       (float)0.790192, (float)0.779480, (float)0.768585,\r
+       (float)0.757477, (float)0.746216, (float)0.734802,\r
+       (float)0.723206, (float)0.711487, (float)0.699585,\r
+       (float)0.687561, (float)0.675415, (float)0.663147,\r
+       (float)0.650787, (float)0.638306, (float)0.625732,\r
+   \r
+   \r
+       (float)0.613068, (float)0.600342, (float)0.587524,\r
+       (float)0.574677, (float)0.561768, (float)0.548798,\r
+       (float)0.535828, (float)0.522797, (float)0.509766,\r
+       (float)0.496735, (float)0.483704, (float)0.470673,\r
+       (float)0.457672, (float)0.444702, (float)0.431763,\r
+       (float)0.418884, (float)0.406067, (float)0.393280,\r
+       (float)0.380585, (float)0.367981, (float)0.355438,\r
+       (float)0.343018, (float)0.330688, (float)0.318481,\r
+       (float)0.306396, (float)0.294464, (float)0.282654,\r
+       (float)0.270966, (float)0.259460, (float)0.248108,\r
+       (float)0.236938, (float)0.225952, (float)0.215149,\r
+       (float)0.204529, (float)0.194122, (float)0.183899,\r
+       (float)0.173920, (float)0.164154, (float)0.154602,\r
+       (float)0.145294, (float)0.136230, (float)0.127411,\r
+       (float)0.118835, (float)0.110535, (float)0.102509,\r
+       (float)0.094727, (float)0.087219, (float)0.080017,\r
+       (float)0.073090, (float)0.066437, (float)0.060089,\r
+       (float)0.054047, (float)0.048309, (float)0.042877,\r
+       (float)0.037750, (float)0.032928, (float)0.028442,\r
+       (float)0.024261, (float)0.020416, (float)0.016907,\r
+       (float)0.013702, (float)0.010834, (float)0.008301,\r
+       (float)0.006104, (float)0.004242, (float)0.002716,\r
+       (float)0.001526, (float)0.000671, (float)0.000183\r
+   };\r
+   \r
+   /* Asymmetric LPC window */\r
+   float lpc_asymwinTbl[BLOCKL_MAX]={\r
+       (float)0.000061, (float)0.000214, (float)0.000458,\r
+       (float)0.000824, (float)0.001282, (float)0.001831,\r
+       (float)0.002472, (float)0.003235, (float)0.004120,\r
+       (float)0.005066, (float)0.006134, (float)0.007294,\r
+       (float)0.008545, (float)0.009918, (float)0.011383,\r
+       (float)0.012939, (float)0.014587, (float)0.016357,\r
+       (float)0.018219, (float)0.020172, (float)0.022217,\r
+       (float)0.024353, (float)0.026611, (float)0.028961,\r
+       (float)0.031372, (float)0.033905, (float)0.036530,\r
+       (float)0.039276, (float)0.042084, (float)0.044983,\r
+       (float)0.047974, (float)0.051086, (float)0.054260,\r
+       (float)0.057526, (float)0.060883, (float)0.064331,\r
+       (float)0.067871, (float)0.071503, (float)0.075226,\r
+       (float)0.079010, (float)0.082916, (float)0.086884,\r
+       (float)0.090942, (float)0.095062, (float)0.099304,\r
+       (float)0.103607, (float)0.107971, (float)0.112427,\r
+       (float)0.116974, (float)0.121582, (float)0.126282,\r
+       (float)0.131073, (float)0.135895, (float)0.140839,\r
+       (float)0.145813, (float)0.150879, (float)0.156006,\r
+       (float)0.161224, (float)0.166504, (float)0.171844,\r
+       (float)0.177246, (float)0.182709, (float)0.188263,\r
+       (float)0.193848, (float)0.199524, (float)0.205231,\r
+       (float)0.211029, (float)0.216858, (float)0.222778,\r
+       (float)0.228729, (float)0.234741, (float)0.240814,\r
+       (float)0.246918, (float)0.253082, (float)0.259308,\r
+       (float)0.265564, (float)0.271881, (float)0.278259,\r
+       (float)0.284668, (float)0.291107, (float)0.297607,\r
+   \r
+   \r
+       (float)0.304138, (float)0.310730, (float)0.317322,\r
+       (float)0.323975, (float)0.330658, (float)0.337372,\r
+       (float)0.344147, (float)0.350922, (float)0.357727,\r
+       (float)0.364594, (float)0.371460, (float)0.378357,\r
+       (float)0.385284, (float)0.392212, (float)0.399170,\r
+       (float)0.406158, (float)0.413177, (float)0.420197,\r
+       (float)0.427246, (float)0.434296, (float)0.441376,\r
+       (float)0.448456, (float)0.455536, (float)0.462646,\r
+       (float)0.469757, (float)0.476868, (float)0.483978,\r
+       (float)0.491089, (float)0.498230, (float)0.505341,\r
+       (float)0.512451, (float)0.519592, (float)0.526703,\r
+       (float)0.533813, (float)0.540924, (float)0.548004,\r
+       (float)0.555084, (float)0.562164, (float)0.569244,\r
+       (float)0.576294, (float)0.583313, (float)0.590332,\r
+       (float)0.597321, (float)0.604309, (float)0.611267,\r
+       (float)0.618195, (float)0.625092, (float)0.631989,\r
+       (float)0.638855, (float)0.645660, (float)0.652466,\r
+       (float)0.659241, (float)0.665985, (float)0.672668,\r
+       (float)0.679352, (float)0.685974, (float)0.692566,\r
+       (float)0.699127, (float)0.705658, (float)0.712128,\r
+       (float)0.718536, (float)0.724945, (float)0.731262,\r
+       (float)0.737549, (float)0.743805, (float)0.750000,\r
+       (float)0.756134, (float)0.762238, (float)0.768280,\r
+       (float)0.774261, (float)0.780182, (float)0.786072,\r
+       (float)0.791870, (float)0.797638, (float)0.803314,\r
+       (float)0.808960, (float)0.814514, (float)0.820038,\r
+       (float)0.825470, (float)0.830841, (float)0.836151,\r
+       (float)0.841400, (float)0.846558, (float)0.851654,\r
+       (float)0.856689, (float)0.861633, (float)0.866516,\r
+       (float)0.871338, (float)0.876068, (float)0.880737,\r
+       (float)0.885315, (float)0.889801, (float)0.894226,\r
+       (float)0.898560, (float)0.902832, (float)0.907013,\r
+       (float)0.911102, (float)0.915100, (float)0.919037,\r
+       (float)0.922882, (float)0.926636, (float)0.930328,\r
+       (float)0.933899, (float)0.937408, (float)0.940796,\r
+       (float)0.944122, (float)0.947357, (float)0.950470,\r
+       (float)0.953522, (float)0.956482, (float)0.959351,\r
+       (float)0.962097, (float)0.964783, (float)0.967377,\r
+       (float)0.969849, (float)0.972229, (float)0.974518,\r
+       (float)0.976715, (float)0.978821, (float)0.980835,\r
+       (float)0.982727, (float)0.984528, (float)0.986237,\r
+       (float)0.987854, (float)0.989380, (float)0.990784,\r
+       (float)0.992096, (float)0.993317, (float)0.994415,\r
+       (float)0.995422, (float)0.996338, (float)0.997162,\r
+       (float)0.997864, (float)0.998474, (float)0.998962,\r
+       (float)0.999390, (float)0.999695, (float)0.999878,\r
+       (float)0.999969, (float)0.999969, (float)0.996918,\r
+       (float)0.987701, (float)0.972382, (float)0.951050,\r
+       (float)0.923889, (float)0.891022, (float)0.852631,\r
+       (float)0.809021, (float)0.760406, (float)0.707092,\r
+       (float)0.649445, (float)0.587799, (float)0.522491,\r
+       (float)0.453979, (float)0.382690, (float)0.309021,\r
+       (float)0.233459, (float)0.156433, (float)0.078461\r
+   };\r
+   \r
+   \r
+   \r
+   /* Lag window for LPC */\r
+   float lpc_lagwinTbl[LPC_FILTERORDER + 1]={\r
+       (float)1.000100, (float)0.998890, (float)0.995569,\r
+           (float)0.990057, (float)0.982392,\r
+       (float)0.972623, (float)0.960816, (float)0.947047,\r
+           (float)0.931405, (float)0.913989, (float)0.894909};\r
+   \r
+   /* LSF quantization*/\r
+   float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {\r
+   (float)0.155396, (float)0.273193, (float)0.451172,\r
+   (float)0.390503, (float)0.648071, (float)1.002075,\r
+   (float)0.440186, (float)0.692261, (float)0.955688,\r
+   (float)0.343628, (float)0.642334, (float)1.071533,\r
+   (float)0.318359, (float)0.491577, (float)0.670532,\r
+   (float)0.193115, (float)0.375488, (float)0.725708,\r
+   (float)0.364136, (float)0.510376, (float)0.658691,\r
+   (float)0.297485, (float)0.527588, (float)0.842529,\r
+   (float)0.227173, (float)0.365967, (float)0.563110,\r
+   (float)0.244995, (float)0.396729, (float)0.636475,\r
+   (float)0.169434, (float)0.300171, (float)0.520264,\r
+   (float)0.312866, (float)0.464478, (float)0.643188,\r
+   (float)0.248535, (float)0.429932, (float)0.626099,\r
+   (float)0.236206, (float)0.491333, (float)0.817139,\r
+   (float)0.334961, (float)0.625122, (float)0.895752,\r
+   (float)0.343018, (float)0.518555, (float)0.698608,\r
+   (float)0.372803, (float)0.659790, (float)0.945435,\r
+   (float)0.176880, (float)0.316528, (float)0.581421,\r
+   (float)0.416382, (float)0.625977, (float)0.805176,\r
+   (float)0.303223, (float)0.568726, (float)0.915039,\r
+   (float)0.203613, (float)0.351440, (float)0.588135,\r
+   (float)0.221191, (float)0.375000, (float)0.614746,\r
+   (float)0.199951, (float)0.323364, (float)0.476074,\r
+   (float)0.300781, (float)0.433350, (float)0.566895,\r
+   (float)0.226196, (float)0.354004, (float)0.507568,\r
+   (float)0.300049, (float)0.508179, (float)0.711670,\r
+   (float)0.312012, (float)0.492676, (float)0.763428,\r
+   (float)0.329956, (float)0.541016, (float)0.795776,\r
+   (float)0.373779, (float)0.604614, (float)0.928833,\r
+   (float)0.210571, (float)0.452026, (float)0.755249,\r
+   (float)0.271118, (float)0.473267, (float)0.662476,\r
+   (float)0.285522, (float)0.436890, (float)0.634399,\r
+   (float)0.246704, (float)0.565552, (float)0.859009,\r
+   (float)0.270508, (float)0.406250, (float)0.553589,\r
+   (float)0.361450, (float)0.578491, (float)0.813843,\r
+   (float)0.342651, (float)0.482788, (float)0.622437,\r
+   (float)0.340332, (float)0.549438, (float)0.743164,\r
+   (float)0.200439, (float)0.336304, (float)0.540894,\r
+   (float)0.407837, (float)0.644775, (float)0.895142,\r
+   (float)0.294678, (float)0.454834, (float)0.699097,\r
+   (float)0.193115, (float)0.344482, (float)0.643188,\r
+   (float)0.275757, (float)0.420776, (float)0.598755,\r
+   (float)0.380493, (float)0.608643, (float)0.861084,\r
+   (float)0.222778, (float)0.426147, (float)0.676514,\r
+   \r
+   \r
+   (float)0.407471, (float)0.700195, (float)1.053101,\r
+   (float)0.218384, (float)0.377197, (float)0.669922,\r
+   (float)0.313232, (float)0.454102, (float)0.600952,\r
+   (float)0.347412, (float)0.571533, (float)0.874146,\r
+   (float)0.238037, (float)0.405396, (float)0.729492,\r
+   (float)0.223877, (float)0.412964, (float)0.822021,\r
+   (float)0.395264, (float)0.582153, (float)0.743896,\r
+   (float)0.247925, (float)0.485596, (float)0.720581,\r
+   (float)0.229126, (float)0.496582, (float)0.907715,\r
+   (float)0.260132, (float)0.566895, (float)1.012695,\r
+   (float)0.337402, (float)0.611572, (float)0.978149,\r
+   (float)0.267822, (float)0.447632, (float)0.769287,\r
+   (float)0.250610, (float)0.381714, (float)0.530029,\r
+   (float)0.430054, (float)0.805054, (float)1.221924,\r
+   (float)0.382568, (float)0.544067, (float)0.701660,\r
+   (float)0.383545, (float)0.710327, (float)1.149170,\r
+   (float)0.271362, (float)0.529053, (float)0.775513,\r
+   (float)0.246826, (float)0.393555, (float)0.588623,\r
+   (float)0.266846, (float)0.422119, (float)0.676758,\r
+   (float)0.311523, (float)0.580688, (float)0.838623,\r
+   (float)1.331177, (float)1.576782, (float)1.779541,\r
+   (float)1.160034, (float)1.401978, (float)1.768188,\r
+   (float)1.161865, (float)1.525146, (float)1.715332,\r
+   (float)0.759521, (float)0.913940, (float)1.119873,\r
+   (float)0.947144, (float)1.121338, (float)1.282471,\r
+   (float)1.015015, (float)1.557007, (float)1.804932,\r
+   (float)1.172974, (float)1.402100, (float)1.692627,\r
+   (float)1.087524, (float)1.474243, (float)1.665405,\r
+   (float)0.899536, (float)1.105225, (float)1.406250,\r
+   (float)1.148438, (float)1.484741, (float)1.796265,\r
+   (float)0.785645, (float)1.209839, (float)1.567749,\r
+   (float)0.867798, (float)1.166504, (float)1.450684,\r
+   (float)0.922485, (float)1.229858, (float)1.420898,\r
+   (float)0.791260, (float)1.123291, (float)1.409546,\r
+   (float)0.788940, (float)0.966064, (float)1.340332,\r
+   (float)1.051147, (float)1.272827, (float)1.556641,\r
+   (float)0.866821, (float)1.181152, (float)1.538818,\r
+   (float)0.906738, (float)1.373535, (float)1.607910,\r
+   (float)1.244751, (float)1.581421, (float)1.933838,\r
+   (float)0.913940, (float)1.337280, (float)1.539673,\r
+   (float)0.680542, (float)0.959229, (float)1.662720,\r
+   (float)0.887207, (float)1.430542, (float)1.800781,\r
+   (float)0.912598, (float)1.433594, (float)1.683960,\r
+   (float)0.860474, (float)1.060303, (float)1.455322,\r
+   (float)1.005127, (float)1.381104, (float)1.706909,\r
+   (float)0.800781, (float)1.363892, (float)1.829102,\r
+   (float)0.781860, (float)1.124390, (float)1.505981,\r
+   (float)1.003662, (float)1.471436, (float)1.684692,\r
+   (float)0.981323, (float)1.309570, (float)1.618042,\r
+   (float)1.228760, (float)1.554321, (float)1.756470,\r
+   (float)0.734375, (float)0.895752, (float)1.225586,\r
+   (float)0.841797, (float)1.055664, (float)1.249268,\r
+   (float)0.920166, (float)1.119385, (float)1.486206,\r
+   (float)0.894409, (float)1.539063, (float)1.828979,\r
+   \r
+   \r
+   (float)1.283691, (float)1.543335, (float)1.858276,\r
+   (float)0.676025, (float)0.933105, (float)1.490845,\r
+   (float)0.821289, (float)1.491821, (float)1.739868,\r
+   (float)0.923218, (float)1.144653, (float)1.580566,\r
+   (float)1.057251, (float)1.345581, (float)1.635864,\r
+   (float)0.888672, (float)1.074951, (float)1.353149,\r
+   (float)0.942749, (float)1.195435, (float)1.505493,\r
+   (float)1.492310, (float)1.788086, (float)2.039673,\r
+   (float)1.070313, (float)1.634399, (float)1.860962,\r
+   (float)1.253296, (float)1.488892, (float)1.686035,\r
+   (float)0.647095, (float)0.864014, (float)1.401855,\r
+   (float)0.866699, (float)1.254883, (float)1.453369,\r
+   (float)1.063965, (float)1.532593, (float)1.731323,\r
+   (float)1.167847, (float)1.521484, (float)1.884033,\r
+   (float)0.956055, (float)1.502075, (float)1.745605,\r
+   (float)0.928711, (float)1.288574, (float)1.479614,\r
+   (float)1.088013, (float)1.380737, (float)1.570801,\r
+   (float)0.905029, (float)1.186768, (float)1.371948,\r
+   (float)1.057861, (float)1.421021, (float)1.617432,\r
+   (float)1.108276, (float)1.312500, (float)1.501465,\r
+   (float)0.979492, (float)1.416992, (float)1.624268,\r
+   (float)1.276001, (float)1.661011, (float)2.007935,\r
+   (float)0.993042, (float)1.168579, (float)1.331665,\r
+   (float)0.778198, (float)0.944946, (float)1.235962,\r
+   (float)1.223755, (float)1.491333, (float)1.815674,\r
+   (float)0.852661, (float)1.350464, (float)1.722290,\r
+   (float)1.134766, (float)1.593140, (float)1.787354,\r
+   (float)1.051392, (float)1.339722, (float)1.531006,\r
+   (float)0.803589, (float)1.271240, (float)1.652100,\r
+   (float)0.755737, (float)1.143555, (float)1.639404,\r
+   (float)0.700928, (float)0.837280, (float)1.130371,\r
+   (float)0.942749, (float)1.197876, (float)1.669800,\r
+   (float)0.993286, (float)1.378296, (float)1.566528,\r
+   (float)0.801025, (float)1.095337, (float)1.298950,\r
+   (float)0.739990, (float)1.032959, (float)1.383667,\r
+   (float)0.845703, (float)1.072266, (float)1.543823,\r
+   (float)0.915649, (float)1.072266, (float)1.224487,\r
+   (float)1.021973, (float)1.226196, (float)1.481323,\r
+   (float)0.999878, (float)1.204102, (float)1.555908,\r
+   (float)0.722290, (float)0.913940, (float)1.340210,\r
+   (float)0.673340, (float)0.835938, (float)1.259521,\r
+   (float)0.832397, (float)1.208374, (float)1.394165,\r
+   (float)0.962158, (float)1.576172, (float)1.912842,\r
+   (float)1.166748, (float)1.370850, (float)1.556763,\r
+   (float)0.946289, (float)1.138550, (float)1.400391,\r
+   (float)1.035034, (float)1.218262, (float)1.386475,\r
+   (float)1.393799, (float)1.717773, (float)2.000244,\r
+   (float)0.972656, (float)1.260986, (float)1.760620,\r
+   (float)1.028198, (float)1.288452, (float)1.484619,\r
+   (float)0.773560, (float)1.258057, (float)1.756714,\r
+   (float)1.080322, (float)1.328003, (float)1.742676,\r
+   (float)0.823975, (float)1.450806, (float)1.917725,\r
+   (float)0.859009, (float)1.016602, (float)1.191895,\r
+   (float)0.843994, (float)1.131104, (float)1.645020,\r
+   \r
+   \r
+   (float)1.189697, (float)1.702759, (float)1.894409,\r
+   (float)1.346680, (float)1.763184, (float)2.066040,\r
+   (float)0.980469, (float)1.253784, (float)1.441650,\r
+   (float)1.338135, (float)1.641968, (float)1.932739,\r
+   (float)1.223267, (float)1.424194, (float)1.626465,\r
+   (float)0.765747, (float)1.004150, (float)1.579102,\r
+   (float)1.042847, (float)1.269165, (float)1.647461,\r
+   (float)0.968750, (float)1.257568, (float)1.555786,\r
+   (float)0.826294, (float)0.993408, (float)1.275146,\r
+   (float)0.742310, (float)0.950439, (float)1.430542,\r
+   (float)1.054321, (float)1.439819, (float)1.828003,\r
+   (float)1.072998, (float)1.261719, (float)1.441895,\r
+   (float)0.859375, (float)1.036377, (float)1.314819,\r
+   (float)0.895752, (float)1.267212, (float)1.605591,\r
+   (float)0.805420, (float)0.962891, (float)1.142334,\r
+   (float)0.795654, (float)1.005493, (float)1.468506,\r
+   (float)1.105347, (float)1.313843, (float)1.584839,\r
+   (float)0.792236, (float)1.221802, (float)1.465698,\r
+   (float)1.170532, (float)1.467651, (float)1.664063,\r
+   (float)0.838257, (float)1.153198, (float)1.342163,\r
+   (float)0.968018, (float)1.198242, (float)1.391235,\r
+   (float)1.250122, (float)1.623535, (float)1.823608,\r
+   (float)0.711670, (float)1.058350, (float)1.512085,\r
+   (float)1.204834, (float)1.454468, (float)1.739136,\r
+   (float)1.137451, (float)1.421753, (float)1.620117,\r
+   (float)0.820435, (float)1.322754, (float)1.578247,\r
+   (float)0.798706, (float)1.005005, (float)1.213867,\r
+   (float)0.980713, (float)1.324951, (float)1.512939,\r
+   (float)1.112305, (float)1.438843, (float)1.735596,\r
+   (float)1.135498, (float)1.356689, (float)1.635742,\r
+   (float)1.101318, (float)1.387451, (float)1.686523,\r
+   (float)0.849854, (float)1.276978, (float)1.523438,\r
+   (float)1.377930, (float)1.627563, (float)1.858154,\r
+   (float)0.884888, (float)1.095459, (float)1.287476,\r
+   (float)1.289795, (float)1.505859, (float)1.756592,\r
+   (float)0.817505, (float)1.384155, (float)1.650513,\r
+   (float)1.446655, (float)1.702148, (float)1.931885,\r
+   (float)0.835815, (float)1.023071, (float)1.385376,\r
+   (float)0.916626, (float)1.139038, (float)1.335327,\r
+   (float)0.980103, (float)1.174072, (float)1.453735,\r
+   (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,\r
+   (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,\r
+   (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,\r
+   (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,\r
+   (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,\r
+   (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,\r
+   (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,\r
+   (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,\r
+   (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,\r
+   (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,\r
+   (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,\r
+   (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,\r
+   (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,\r
+   (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,\r
+   \r
+   \r
+   (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,\r
+   (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,\r
+   (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,\r
+   (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,\r
+   (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,\r
+   (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,\r
+   (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,\r
+   (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,\r
+   (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,\r
+   (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,\r
+   (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,\r
+   (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,\r
+   (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,\r
+   (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,\r
+   (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,\r
+   (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,\r
+   (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,\r
+   (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,\r
+   (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,\r
+   (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,\r
+   (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,\r
+   (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,\r
+   (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,\r
+   (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,\r
+   (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,\r
+   (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,\r
+   (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,\r
+   (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,\r
+   (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,\r
+   (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,\r
+   (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,\r
+   (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,\r
+   (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,\r
+   (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,\r
+   (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,\r
+   (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,\r
+   (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,\r
+   (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,\r
+   (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,\r
+   (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,\r
+   (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,\r
+   (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,\r
+   (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,\r
+   (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,\r
+   (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,\r
+   (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,\r
+   (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,\r
+   (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,\r
+   (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,\r
+   (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,\r
+   (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,\r
+   (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,\r
+   (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,\r
+   (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,\r
+   \r
+   \r
+   (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,\r
+   (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,\r
+   (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,\r
+   (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,\r
+   (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,\r
+   (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,\r
+   (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,\r
+   (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,\r
+   (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,\r
+   (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,\r
+   (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,\r
+   (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,\r
+   (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,\r
+   (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,\r
+   (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,\r
+   (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,\r
+   (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,\r
+   (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,\r
+   (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,\r
+   (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,\r
+   (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,\r
+   (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,\r
+   (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,\r
+   (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,\r
+   (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,\r
+   (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,\r
+   (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,\r
+   (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,\r
+   (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,\r
+   (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,\r
+   (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,\r
+   (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,\r
+   (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,\r
+   (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,\r
+   (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,\r
+   (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,\r
+   (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,\r
+   (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,\r
+   (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,\r
+   (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,\r
+   (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,\r
+   (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,\r
+   (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,\r
+   (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,\r
+   (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,\r
+   (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,\r
+   (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,\r
+   (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,\r
+   (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,\r
+   (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,\r
+   (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,\r
+   (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,\r
+   (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,\r
+   (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,\r
+   \r
+   \r
+   (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,\r
+   (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,\r
+   (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,\r
+   (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,\r
+   (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,\r
+   (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143\r
+   };\r
+   \r
+   \r
index 155ee970af3d35dc160171f52fa1ec3f3e70d95c..ebc5b2c3a669cbe3844e2739137f4218681636a0 100644 (file)
@@ -1,74 +1,74 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    constants.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_CONSTANTS_H\r
-#define __iLBC_CONSTANTS_H\r
-\r
-#include "iLBC_define.h"\r
-\r
-\r
-/* ULP bit allocation */\r
-\r
-extern const iLBC_ULP_Inst_t ULP_20msTbl;\r
-extern const iLBC_ULP_Inst_t ULP_30msTbl;\r
-\r
-/* high pass filters */\r
-\r
-extern float hpi_zero_coefsTbl[];\r
-extern float hpi_pole_coefsTbl[];\r
-extern float hpo_zero_coefsTbl[];\r
-extern float hpo_pole_coefsTbl[];  \r
-\r
-/* low pass filters */\r
-extern float lpFilt_coefsTbl[];\r
-\r
-/* LPC analysis and quantization */\r
-\r
-extern float lpc_winTbl[];\r
-extern float lpc_asymwinTbl[];\r
-extern float lpc_lagwinTbl[];\r
-extern float lsfCbTbl[];\r
-extern float lsfmeanTbl[];\r
-extern int   dim_lsfCbTbl[];\r
-extern int   size_lsfCbTbl[];\r
-extern float lsf_weightTbl_30ms[]; \r
-extern float lsf_weightTbl_20ms[];\r
-\r
-/* state quantization tables */\r
-\r
-extern float state_sq3Tbl[];\r
-extern float state_frgqTbl[];\r
-\r
-/* gain quantization tables */\r
-\r
-extern float gain_sq3Tbl[];\r
-extern float gain_sq4Tbl[];\r
-extern float gain_sq5Tbl[];\r
-\r
-/* adaptive codebook definitions */\r
-\r
-extern int search_rangeTbl[5][CB_NSTAGES];\r
-extern int memLfTbl[];\r
-extern int stMemLTbl;\r
-extern float cbfiltersTbl[CB_FILTERLEN];\r
-\r
-\r
-\r
-/* enhancer definitions */\r
-\r
-extern float polyphaserTbl[];\r
-extern float enh_plocsTbl[];\r
-\r
-#endif\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       constants.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_CONSTANTS_H\r
+   #define __iLBC_CONSTANTS_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   \r
+   /* ULP bit allocation */\r
+   \r
+   extern const iLBC_ULP_Inst_t ULP_20msTbl;\r
+   extern const iLBC_ULP_Inst_t ULP_30msTbl;\r
+   \r
+   /* high pass filters */\r
+   \r
+   extern float hpi_zero_coefsTbl[];\r
+   extern float hpi_pole_coefsTbl[];\r
+   extern float hpo_zero_coefsTbl[];\r
+   extern float hpo_pole_coefsTbl[];  \r
+   \r
+   /* low pass filters */\r
+   extern float lpFilt_coefsTbl[];\r
+   \r
+   /* LPC analysis and quantization */\r
+   \r
+   extern float lpc_winTbl[];\r
+   extern float lpc_asymwinTbl[];\r
+   extern float lpc_lagwinTbl[];\r
+   extern float lsfCbTbl[];\r
+   extern float lsfmeanTbl[];\r
+   extern int   dim_lsfCbTbl[];\r
+   extern int   size_lsfCbTbl[];\r
+   extern float lsf_weightTbl_30ms[]; \r
+   extern float lsf_weightTbl_20ms[];\r
+   \r
+   /* state quantization tables */\r
+   \r
+   extern float state_sq3Tbl[];\r
+   extern float state_frgqTbl[];\r
+   \r
+   /* gain quantization tables */\r
+   \r
+   extern float gain_sq3Tbl[];\r
+   extern float gain_sq4Tbl[];\r
+   extern float gain_sq5Tbl[];\r
+   \r
+   /* adaptive codebook definitions */\r
+   \r
+   extern int search_rangeTbl[5][CB_NSTAGES];\r
+   extern int memLfTbl[];\r
+   extern int stMemLTbl;\r
+   extern float cbfiltersTbl[CB_FILTERLEN];\r
+   \r
+   \r
+   \r
+   /* enhancer definitions */\r
+   \r
+   extern float polyphaserTbl[];\r
+   extern float enh_plocsTbl[];\r
+   \r
+   #endif\r
+   \r
index cd79fa2b957fefe13c6261df6a72345f282beb96..0512a622ba59cd22ab770b79784f58c87635cb75 100644 (file)
-\r
-\r
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    createCB.c\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include "iLBC_define.h"\r
-#include "createCB.h"\r
-#include "constants.h"\r
-#include <string.h>\r
-#include <math.h>\r
-\r
-/*----------------------------------------------------------------*\r
- *  Construct an additional codebook vector by filtering the\r
- *  initial codebook buffer. This vector is then used to expand\r
- *  the codebook with an additional section.\r
- *---------------------------------------------------------------*/\r
-\r
-void filteredCBvecs(\r
-    float *cbvectors,   /* (o) Codebook vectors for the \r
-                               higher section */\r
-    float *mem,         /* (i) Buffer to create codebook \r
-                               vector from */\r
-    int lMem        /* (i) Length of buffer */\r
-){\r
-    int j, k;\r
-    float *pp, *pp1;\r
-    float tempbuff2[CB_MEML+CB_FILTERLEN];\r
-    float *pos;\r
-\r
-    memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));\r
-    memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));\r
-    memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, \r
-        (CB_HALFFILTERLEN+1)*sizeof(float));\r
-\r
-    /* Create codebook vector for higher section by filtering */\r
-\r
-    /* do filtering */\r
-    pos=cbvectors;\r
-    memset(pos, 0, lMem*sizeof(float));\r
-    for (k=0; k<lMem; k++) {\r
-        pp=&tempbuff2[k];\r
-        pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
-        for (j=0;j<CB_FILTERLEN;j++) {\r
-            (*pos)+=(*pp++)*(*pp1--);\r
-        }\r
-        pos++;\r
-    }\r
-}\r
-\r
-\r
-\r
-/*----------------------------------------------------------------*\r
- *  Search the augmented part of the codebook to find the best\r
- *  measure.\r
- *----------------------------------------------------------------*/\r
-\r
-void searchAugmentedCB(\r
-    int low,        /* (i) Start index for the search */\r
-    int high,           /* (i) End index for the search */\r
-    int stage,          /* (i) Current stage */\r
-    int startIndex,     /* (i) Codebook index for the first \r
-                               aug vector */\r
-    float *target,      /* (i) Target vector for encoding */\r
-    float *buffer,      /* (i) Pointer to the end of the buffer for\r
-                               augmented codebook construction */\r
-    float *max_measure, /* (i/o) Currently maximum measure */\r
-    int *best_index,/* (o) Currently the best index */\r
-    float *gain,    /* (o) Currently the best gain */\r
-    float *energy,      /* (o) Energy of augmented codebook \r
-                               vectors */\r
-    float *invenergy/* (o) Inv energy of augmented codebook \r
-                               vectors */\r
-) {\r
-    int icount, ilow, j, tmpIndex;\r
-    float *pp, *ppo, *ppi, *ppe, crossDot, alfa; \r
-    float weighted, measure, nrjRecursive;\r
-    float ftmp;\r
-\r
-    /* Compute the energy for the first (low-5) \r
-       noninterpolated samples */\r
-    nrjRecursive = (float) 0.0;\r
-    pp = buffer - low + 1;\r
-    for (j=0; j<(low-5); j++) {\r
-        nrjRecursive += ( (*pp)*(*pp) );\r
-        pp++;\r
-    }\r
-    ppe = buffer - low;\r
-\r
-\r
-    for (icount=low; icount<=high; icount++) {\r
-\r
-        /* Index of the codebook vector used for retrieving \r
-           energy values */\r
-        tmpIndex = startIndex+icount-20;\r
-\r
-        ilow = icount-4;\r
-            \r
-        /* Update the energy recursively to save complexity */\r
-        nrjRecursive = nrjRecursive + (*ppe)*(*ppe);\r
-        ppe--;\r
-        energy[tmpIndex] = nrjRecursive;\r
-\r
-        /* Compute cross dot product for the first (low-5) \r
-           samples */\r
-        crossDot = (float) 0.0;\r
-\r
-\r
-        pp = buffer-icount;\r
-        for (j=0; j<ilow; j++) {\r
-            crossDot += target[j]*(*pp++);\r
-        }\r
-\r
-        /* interpolation */\r
-        alfa = (float) 0.2;\r
-        ppo = buffer-4;\r
-        ppi = buffer-icount-4;\r
-        for (j=ilow; j<icount; j++) {\r
-            weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
-            ppo++;\r
-            ppi++;\r
-            energy[tmpIndex] += weighted*weighted;\r
-            crossDot += target[j]*weighted;\r
-            alfa += (float)0.2;\r
-        }\r
-\r
-        /* Compute energy and cross dot product for the \r
-           remaining samples */\r
-        pp = buffer - icount;\r
-        for (j=icount; j<SUBL; j++) {\r
-            energy[tmpIndex] += (*pp)*(*pp);\r
-            crossDot += target[j]*(*pp++);\r
-        }\r
-        \r
-        if (energy[tmpIndex]>0.0) {\r
-            invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);\r
-        } else {\r
-            invenergy[tmpIndex] = (float) 0.0;\r
-        }\r
-        \r
-        if (stage==0) {\r
-            measure = (float)-10000000.0;\r
-            \r
-            if (crossDot > 0.0) {\r
-                measure = crossDot*crossDot*invenergy[tmpIndex];\r
-            }\r
-        }\r
-        else {\r
-            measure = crossDot*crossDot*invenergy[tmpIndex];\r
-        }\r
-    \r
-        /* check if measure is better */\r
-        ftmp = crossDot*invenergy[tmpIndex];\r
-        \r
-        if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
-            *best_index = tmpIndex;\r
-            *max_measure = measure;\r
-            *gain = ftmp;\r
-        }\r
-    }\r
-}\r
-\r
-\r
-\r
-\r
-/*----------------------------------------------------------------*\r
- *  Recreate a specific codebook vector from the augmented part.\r
- *\r
- *----------------------------------------------------------------*/\r
-\r
-void createAugmentedVec(\r
-    int index,      /* (i) Index for the augmented vector \r
-                           to be created */\r
-    float *buffer,  /* (i) Pointer to the end of the buffer for\r
-                           augmented codebook construction */\r
-    float *cbVec/* (o) The construced codebook vector */\r
-) {\r
-    int ilow, j;\r
-    float *pp, *ppo, *ppi, alfa, alfa1, weighted;\r
-\r
-    ilow = index-5;\r
-            \r
-    /* copy the first noninterpolated part */\r
-\r
-    pp = buffer-index;\r
-    memcpy(cbVec,pp,sizeof(float)*index);\r
-\r
-    /* interpolation */\r
-\r
-    alfa1 = (float)0.2;\r
-    alfa = 0.0;\r
-    ppo = buffer-5;\r
-    ppi = buffer-index-5;\r
-    for (j=ilow; j<index; j++) {\r
-        weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
-        ppo++;\r
-        ppi++;\r
-        cbVec[j] = weighted;\r
-        alfa += alfa1;\r
-    }\r
-\r
-    /* copy the second noninterpolated part */\r
-\r
-    pp = buffer - index;\r
-    memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));\r
-}\r
-\r
-\r
+   \r
+   \r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       createCB.c\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include <string.h>\r
+   #include <math.h>\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Construct an additional codebook vector by filtering the\r
+    *  initial codebook buffer. This vector is then used to expand\r
+    *  the codebook with an additional section.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void filteredCBvecs(\r
+       float *cbvectors,   /* (o) Codebook vectors for the \r
+                                  higher section */\r
+       float *mem,         /* (i) Buffer to create codebook \r
+                                  vector from */\r
+       int lMem        /* (i) Length of buffer */\r
+   ){\r
+       int j, k;\r
+       float *pp, *pp1;\r
+       float tempbuff2[CB_MEML+CB_FILTERLEN];\r
+       float *pos;\r
+   \r
+       memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));\r
+       memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));\r
+       memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, \r
+           (CB_HALFFILTERLEN+1)*sizeof(float));\r
+   \r
+       /* Create codebook vector for higher section by filtering */\r
+   \r
+       /* do filtering */\r
+       pos=cbvectors;\r
+       memset(pos, 0, lMem*sizeof(float));\r
+       for (k=0; k<lMem; k++) {\r
+           pp=&tempbuff2[k];\r
+           pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+           for (j=0;j<CB_FILTERLEN;j++) {\r
+               (*pos)+=(*pp++)*(*pp1--);\r
+           }\r
+           pos++;\r
+       }\r
+   }\r
+   \r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Search the augmented part of the codebook to find the best\r
+    *  measure.\r
+    *----------------------------------------------------------------*/\r
+   \r
+   void searchAugmentedCB(\r
+       int low,        /* (i) Start index for the search */\r
+       int high,           /* (i) End index for the search */\r
+       int stage,          /* (i) Current stage */\r
+       int startIndex,     /* (i) Codebook index for the first \r
+                                  aug vector */\r
+       float *target,      /* (i) Target vector for encoding */\r
+       float *buffer,      /* (i) Pointer to the end of the buffer for\r
+                                  augmented codebook construction */\r
+       float *max_measure, /* (i/o) Currently maximum measure */\r
+       int *best_index,/* (o) Currently the best index */\r
+       float *gain,    /* (o) Currently the best gain */\r
+       float *energy,      /* (o) Energy of augmented codebook \r
+                                  vectors */\r
+       float *invenergy/* (o) Inv energy of augmented codebook \r
+                                  vectors */\r
+   ) {\r
+       int icount, ilow, j, tmpIndex;\r
+       float *pp, *ppo, *ppi, *ppe, crossDot, alfa; \r
+       float weighted, measure, nrjRecursive;\r
+       float ftmp;\r
+   \r
+       /* Compute the energy for the first (low-5) \r
+          noninterpolated samples */\r
+       nrjRecursive = (float) 0.0;\r
+       pp = buffer - low + 1;\r
+       for (j=0; j<(low-5); j++) {\r
+           nrjRecursive += ( (*pp)*(*pp) );\r
+           pp++;\r
+       }\r
+       ppe = buffer - low;\r
+   \r
+   \r
+       for (icount=low; icount<=high; icount++) {\r
+   \r
+           /* Index of the codebook vector used for retrieving \r
+              energy values */\r
+           tmpIndex = startIndex+icount-20;\r
+   \r
+           ilow = icount-4;\r
+               \r
+           /* Update the energy recursively to save complexity */\r
+           nrjRecursive = nrjRecursive + (*ppe)*(*ppe);\r
+           ppe--;\r
+           energy[tmpIndex] = nrjRecursive;\r
+   \r
+           /* Compute cross dot product for the first (low-5) \r
+              samples */\r
+           crossDot = (float) 0.0;\r
+   \r
+   \r
+           pp = buffer-icount;\r
+           for (j=0; j<ilow; j++) {\r
+               crossDot += target[j]*(*pp++);\r
+           }\r
+   \r
+           /* interpolation */\r
+           alfa = (float) 0.2;\r
+           ppo = buffer-4;\r
+           ppi = buffer-icount-4;\r
+           for (j=ilow; j<icount; j++) {\r
+               weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
+               ppo++;\r
+               ppi++;\r
+               energy[tmpIndex] += weighted*weighted;\r
+               crossDot += target[j]*weighted;\r
+               alfa += (float)0.2;\r
+           }\r
+   \r
+           /* Compute energy and cross dot product for the \r
+              remaining samples */\r
+           pp = buffer - icount;\r
+           for (j=icount; j<SUBL; j++) {\r
+               energy[tmpIndex] += (*pp)*(*pp);\r
+               crossDot += target[j]*(*pp++);\r
+           }\r
+           \r
+           if (energy[tmpIndex]>0.0) {\r
+               invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);\r
+           } else {\r
+               invenergy[tmpIndex] = (float) 0.0;\r
+           }\r
+           \r
+           if (stage==0) {\r
+               measure = (float)-10000000.0;\r
+               \r
+               if (crossDot > 0.0) {\r
+                   measure = crossDot*crossDot*invenergy[tmpIndex];\r
+               }\r
+           }\r
+           else {\r
+               measure = crossDot*crossDot*invenergy[tmpIndex];\r
+           }\r
+       \r
+           /* check if measure is better */\r
+           ftmp = crossDot*invenergy[tmpIndex];\r
+           \r
+           if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+               *best_index = tmpIndex;\r
+               *max_measure = measure;\r
+               *gain = ftmp;\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Recreate a specific codebook vector from the augmented part.\r
+    *\r
+    *----------------------------------------------------------------*/\r
+   \r
+   void createAugmentedVec(\r
+       int index,      /* (i) Index for the augmented vector \r
+                              to be created */\r
+       float *buffer,  /* (i) Pointer to the end of the buffer for\r
+                              augmented codebook construction */\r
+       float *cbVec/* (o) The construced codebook vector */\r
+   ) {\r
+       int ilow, j;\r
+       float *pp, *ppo, *ppi, alfa, alfa1, weighted;\r
+   \r
+       ilow = index-5;\r
+               \r
+       /* copy the first noninterpolated part */\r
+   \r
+       pp = buffer-index;\r
+       memcpy(cbVec,pp,sizeof(float)*index);\r
+   \r
+       /* interpolation */\r
+   \r
+       alfa1 = (float)0.2;\r
+       alfa = 0.0;\r
+       ppo = buffer-5;\r
+       ppi = buffer-index-5;\r
+       for (j=ilow; j<index; j++) {\r
+           weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
+           ppo++;\r
+           ppi++;\r
+           cbVec[j] = weighted;\r
+           alfa += alfa1;\r
+       }\r
+   \r
+       /* copy the second noninterpolated part */\r
+   \r
+       pp = buffer - index;\r
+       memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));\r
+   }\r
+   \r
+   \r
index b099a83c647ba87b73908afc175437b22e8e348f..d0377ba9a9546b683e7acd8d5b24e462a70e978f 100644 (file)
@@ -1,56 +1,56 @@
-\r
-/******************************************************************\r
-\r
-\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    createCB.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_CREATECB_H\r
-#define __iLBC_CREATECB_H\r
-\r
-void filteredCBvecs(\r
-    float *cbvectors,   /* (o) Codebook vector for the \r
-                               higher section */\r
-    float *mem,         /* (i) Buffer to create codebook \r
-                               vectors from */\r
-    int lMem        /* (i) Length of buffer */\r
-);\r
-\r
-void searchAugmentedCB(\r
-    int low,        /* (i) Start index for the search */\r
-    int high,           /* (i) End index for the search */\r
-    int stage,          /* (i) Current stage */\r
-    int startIndex,     /* (i) CB index for the first \r
-                               augmented vector */\r
-    float *target,      /* (i) Target vector for encoding */\r
-    float *buffer,      /* (i) Pointer to the end of the \r
-                               buffer for augmented codebook \r
-                               construction */\r
-    float *max_measure, /* (i/o) Currently maximum measure */\r
-    int *best_index,/* (o) Currently the best index */\r
-    float *gain,    /* (o) Currently the best gain */\r
-    float *energy,      /* (o) Energy of augmented \r
-                               codebook vectors */\r
-    float *invenergy/* (o) Inv energy of aug codebook \r
-                               vectors */\r
-);\r
-\r
-void createAugmentedVec(\r
-    int index,          /* (i) Index for the aug vector \r
-                               to be created */\r
-    float *buffer,      /* (i) Pointer to the end of the \r
-                               buffer for augmented codebook \r
-                               construction */\r
-    float *cbVec    /* (o) The construced codebook vector */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+   \r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       createCB.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_CREATECB_H\r
+   #define __iLBC_CREATECB_H\r
+   \r
+   void filteredCBvecs(\r
+       float *cbvectors,   /* (o) Codebook vector for the \r
+                                  higher section */\r
+       float *mem,         /* (i) Buffer to create codebook \r
+                                  vectors from */\r
+       int lMem        /* (i) Length of buffer */\r
+   );\r
+   \r
+   void searchAugmentedCB(\r
+       int low,        /* (i) Start index for the search */\r
+       int high,           /* (i) End index for the search */\r
+       int stage,          /* (i) Current stage */\r
+       int startIndex,     /* (i) CB index for the first \r
+                                  augmented vector */\r
+       float *target,      /* (i) Target vector for encoding */\r
+       float *buffer,      /* (i) Pointer to the end of the \r
+                                  buffer for augmented codebook \r
+                                  construction */\r
+       float *max_measure, /* (i/o) Currently maximum measure */\r
+       int *best_index,/* (o) Currently the best index */\r
+       float *gain,    /* (o) Currently the best gain */\r
+       float *energy,      /* (o) Energy of augmented \r
+                                  codebook vectors */\r
+       float *invenergy/* (o) Inv energy of aug codebook \r
+                                  vectors */\r
+   );\r
+   \r
+   void createAugmentedVec(\r
+       int index,          /* (i) Index for the aug vector \r
+                                  to be created */\r
+       float *buffer,      /* (i) Pointer to the end of the \r
+                                  buffer for augmented codebook \r
+                                  construction */\r
+       float *cbVec    /* (o) The construced codebook vector */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index b7d3b4e8349072516958360ee8afda15bfa0b4f5..e04855ad108b2644df1b72722864114026567392 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    doCPLC.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <string.h>\r
-#include <stdio.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "doCPLC.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  Compute cross correlation and pitch gain for pitch prediction\r
- *  of last subframe at given lag.\r
- *---------------------------------------------------------------*/\r
-\r
-static void compCorr(\r
-    float *cc,      /* (o) cross correlation coefficient */\r
-    float *gc,      /* (o) gain */\r
-    float *pm,\r
-    float *buffer,  /* (i) signal buffer */\r
-    int lag,    /* (i) pitch lag */\r
-    int bLen,       /* (i) length of buffer */\r
-    int sRange      /* (i) correlation search length */\r
-){\r
-\r
-\r
-    int i;\r
-    float ftmp1, ftmp2, ftmp3;\r
-\r
-    /* Guard against getting outside buffer */\r
-    if ((bLen-sRange-lag)<0) {\r
-        sRange=bLen-lag;\r
-    }\r
-\r
-    ftmp1 = 0.0;\r
-    ftmp2 = 0.0;\r
-    ftmp3 = 0.0;\r
-    for (i=0; i<sRange; i++) {\r
-        ftmp1 += buffer[bLen-sRange+i] *\r
-            buffer[bLen-sRange+i-lag];\r
-        ftmp2 += buffer[bLen-sRange+i-lag] * \r
-                buffer[bLen-sRange+i-lag];\r
-        ftmp3 += buffer[bLen-sRange+i] * \r
-                buffer[bLen-sRange+i];\r
-    }\r
-\r
-    if (ftmp2 > 0.0) {\r
-        *cc = ftmp1*ftmp1/ftmp2;\r
-        *gc = (float)fabs(ftmp1/ftmp2);\r
-        *pm=(float)fabs(ftmp1)/\r
-            ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));\r
-    }\r
-    else {\r
-        *cc = 0.0;\r
-        *gc = 0.0;\r
-        *pm=0.0;\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  Packet loss concealment routine. Conceals a residual signal\r
- *  and LP parameters. If no packet loss, update state.\r
- *---------------------------------------------------------------*/\r
-\r
-void doThePLC(\r
-    float *PLCresidual, /* (o) concealed residual */ \r
-    float *PLClpc,      /* (o) concealed LP parameters */  \r
-    int PLI,        /* (i) packet loss indicator \r
-                               0 - no PL, 1 = PL */ \r
-    float *decresidual, /* (i) decoded residual */\r
-    float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
-    int inlag,          /* (i) pitch lag */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst \r
-                        /* (i/o) decoder instance */\r
-){\r
-    int lag=20, randlag;\r
-    float gain, maxcc;\r
-    float use_gain;\r
-    float gain_comp, maxcc_comp, per, max_per;\r
-    int i, pick, use_lag;\r
-\r
-\r
-    float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;\r
-            \r
-    /* Packet Loss */\r
-\r
-    if (PLI == 1) {\r
-        \r
-        iLBCdec_inst->consPLICount += 1;\r
-        \r
-        /* if previous frame not lost, \r
-           determine pitch pred. gain */\r
-        \r
-        if (iLBCdec_inst->prevPLI != 1) {\r
-\r
-            /* Search around the previous lag to find the \r
-               best pitch period */\r
-            \r
-            lag=inlag-3;\r
-            compCorr(&maxcc, &gain, &max_per, \r
-                iLBCdec_inst->prevResidual,\r
-                lag, iLBCdec_inst->blockl, 60);\r
-            for (i=inlag-2;i<=inlag+3;i++) {\r
-                compCorr(&maxcc_comp, &gain_comp, &per,\r
-                    iLBCdec_inst->prevResidual,\r
-                    i, iLBCdec_inst->blockl, 60);\r
-                \r
-                if (maxcc_comp>maxcc) {\r
-                    maxcc=maxcc_comp;\r
-                    gain=gain_comp;\r
-                    lag=i;\r
-                    max_per=per;\r
-                }\r
-            }\r
-            \r
-        }\r
-\r
-        /* previous frame lost, use recorded lag and periodicity */\r
-\r
-        else {\r
-            lag=iLBCdec_inst->prevLag;\r
-            max_per=iLBCdec_inst->per;\r
-        }\r
-        \r
-        /* downscaling */\r
-\r
-        use_gain=1.0;\r
-        if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)\r
-            use_gain=(float)0.9;\r
-        else if (iLBCdec_inst->consPLICount*\r
-                        iLBCdec_inst->blockl>2*320)\r
-            use_gain=(float)0.7;\r
-        else if (iLBCdec_inst->consPLICount*\r
-                        iLBCdec_inst->blockl>3*320)\r
-            use_gain=(float)0.5;\r
-        else if (iLBCdec_inst->consPLICount*\r
-\r
-\r
-                        iLBCdec_inst->blockl>4*320)\r
-            use_gain=(float)0.0;\r
-\r
-        /* mix noise and pitch repeatition */\r
-        ftmp=(float)sqrt(max_per);\r
-        if (ftmp>(float)0.7)\r
-            pitchfact=(float)1.0;\r
-        else if (ftmp>(float)0.4)\r
-            pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);\r
-        else\r
-            pitchfact=0.0;\r
-\r
-\r
-        /* avoid repetition of same pitch cycle */\r
-        use_lag=lag;\r
-        if (lag<80) {\r
-            use_lag=2*lag;\r
-        }\r
-\r
-        /* compute concealed residual */\r
-\r
-        energy = 0.0;\r
-        for (i=0; i<iLBCdec_inst->blockl; i++) {\r
-\r
-            /* noise component */\r
-\r
-            iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & \r
-                (0x80000000L-1);\r
-            randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;\r
-            pick = i - randlag;\r
-            \r
-            if (pick < 0) {\r
-                randvec[i] = \r
-                    iLBCdec_inst->prevResidual[\r
-                                iLBCdec_inst->blockl+pick];\r
-            } else {\r
-                randvec[i] =  randvec[pick];\r
-            }\r
-\r
-            /* pitch repeatition component */\r
-            pick = i - use_lag;\r
-            \r
-            if (pick < 0) {\r
-                PLCresidual[i] =  \r
-                    iLBCdec_inst->prevResidual[\r
-                                iLBCdec_inst->blockl+pick];\r
-            } else {\r
-                PLCresidual[i] = PLCresidual[pick];\r
-            }\r
-\r
-            /* mix random and periodicity component */\r
-\r
-            if (i<80)\r
-                PLCresidual[i] = use_gain*(pitchfact * \r
-\r
-\r
-                            PLCresidual[i] +\r
-                            ((float)1.0 - pitchfact) * randvec[i]);\r
-            else if (i<160)\r
-                PLCresidual[i] = (float)0.95*use_gain*(pitchfact * \r
-                            PLCresidual[i] +\r
-                            ((float)1.0 - pitchfact) * randvec[i]);\r
-            else\r
-                PLCresidual[i] = (float)0.9*use_gain*(pitchfact * \r
-                            PLCresidual[i] +\r
-                            ((float)1.0 - pitchfact) * randvec[i]);\r
-\r
-            energy += PLCresidual[i] * PLCresidual[i];\r
-        }\r
-        \r
-        /* less than 30 dB, use only noise */\r
-        \r
-        if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { \r
-            gain=0.0;\r
-            for (i=0; i<iLBCdec_inst->blockl; i++) {\r
-                PLCresidual[i] = randvec[i];\r
-            }\r
-        }\r
-\r
-        /* use old LPC */\r
-\r
-        memcpy(PLClpc,iLBCdec_inst->prevLpc,\r
-            (LPC_FILTERORDER+1)*sizeof(float));\r
-        \r
-    }\r
-\r
-    /* no packet loss, copy input */\r
-\r
-    else {\r
-        memcpy(PLCresidual, decresidual, \r
-            iLBCdec_inst->blockl*sizeof(float));\r
-        memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));\r
-        iLBCdec_inst->consPLICount = 0;\r
-    }\r
-    \r
-    /* update state */\r
-\r
-    if (PLI) {\r
-        iLBCdec_inst->prevLag = lag;\r
-        iLBCdec_inst->per=max_per;\r
-    }\r
-\r
-    iLBCdec_inst->prevPLI = PLI;\r
-    memcpy(iLBCdec_inst->prevLpc, PLClpc, \r
-        (LPC_FILTERORDER+1)*sizeof(float));\r
-    memcpy(iLBCdec_inst->prevResidual, PLCresidual,\r
-        iLBCdec_inst->blockl*sizeof(float));\r
-}\r
-\r
-\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       doCPLC.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   #include <stdio.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Compute cross correlation and pitch gain for pitch prediction\r
+    *  of last subframe at given lag.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void compCorr(\r
+       float *cc,      /* (o) cross correlation coefficient */\r
+       float *gc,      /* (o) gain */\r
+       float *pm,\r
+       float *buffer,  /* (i) signal buffer */\r
+       int lag,    /* (i) pitch lag */\r
+       int bLen,       /* (i) length of buffer */\r
+       int sRange      /* (i) correlation search length */\r
+   ){\r
+   \r
+   \r
+       int i;\r
+       float ftmp1, ftmp2, ftmp3;\r
+   \r
+       /* Guard against getting outside buffer */\r
+       if ((bLen-sRange-lag)<0) {\r
+           sRange=bLen-lag;\r
+       }\r
+   \r
+       ftmp1 = 0.0;\r
+       ftmp2 = 0.0;\r
+       ftmp3 = 0.0;\r
+       for (i=0; i<sRange; i++) {\r
+           ftmp1 += buffer[bLen-sRange+i] *\r
+               buffer[bLen-sRange+i-lag];\r
+           ftmp2 += buffer[bLen-sRange+i-lag] * \r
+                   buffer[bLen-sRange+i-lag];\r
+           ftmp3 += buffer[bLen-sRange+i] * \r
+                   buffer[bLen-sRange+i];\r
+       }\r
+   \r
+       if (ftmp2 > 0.0) {\r
+           *cc = ftmp1*ftmp1/ftmp2;\r
+           *gc = (float)fabs(ftmp1/ftmp2);\r
+           *pm=(float)fabs(ftmp1)/\r
+               ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));\r
+       }\r
+       else {\r
+           *cc = 0.0;\r
+           *gc = 0.0;\r
+           *pm=0.0;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Packet loss concealment routine. Conceals a residual signal\r
+    *  and LP parameters. If no packet loss, update state.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void doThePLC(\r
+       float *PLCresidual, /* (o) concealed residual */ \r
+       float *PLClpc,      /* (o) concealed LP parameters */  \r
+       int PLI,        /* (i) packet loss indicator \r
+                                  0 - no PL, 1 = PL */ \r
+       float *decresidual, /* (i) decoded residual */\r
+       float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
+       int inlag,          /* (i) pitch lag */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i/o) decoder instance */\r
+   ){\r
+       int lag=20, randlag;\r
+       float gain, maxcc;\r
+       float use_gain;\r
+       float gain_comp, maxcc_comp, per, max_per;\r
+       int i, pick, use_lag;\r
+   \r
+   \r
+       float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;\r
+               \r
+       /* Packet Loss */\r
+   \r
+       if (PLI == 1) {\r
+           \r
+           iLBCdec_inst->consPLICount += 1;\r
+           \r
+           /* if previous frame not lost, \r
+              determine pitch pred. gain */\r
+           \r
+           if (iLBCdec_inst->prevPLI != 1) {\r
+   \r
+               /* Search around the previous lag to find the \r
+                  best pitch period */\r
+               \r
+               lag=inlag-3;\r
+               compCorr(&maxcc, &gain, &max_per, \r
+                   iLBCdec_inst->prevResidual,\r
+                   lag, iLBCdec_inst->blockl, 60);\r
+               for (i=inlag-2;i<=inlag+3;i++) {\r
+                   compCorr(&maxcc_comp, &gain_comp, &per,\r
+                       iLBCdec_inst->prevResidual,\r
+                       i, iLBCdec_inst->blockl, 60);\r
+                   \r
+                   if (maxcc_comp>maxcc) {\r
+                       maxcc=maxcc_comp;\r
+                       gain=gain_comp;\r
+                       lag=i;\r
+                       max_per=per;\r
+                   }\r
+               }\r
+               \r
+           }\r
+   \r
+           /* previous frame lost, use recorded lag and periodicity */\r
+   \r
+           else {\r
+               lag=iLBCdec_inst->prevLag;\r
+               max_per=iLBCdec_inst->per;\r
+           }\r
+           \r
+           /* downscaling */\r
+   \r
+           use_gain=1.0;\r
+           if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)\r
+               use_gain=(float)0.9;\r
+           else if (iLBCdec_inst->consPLICount*\r
+                           iLBCdec_inst->blockl>2*320)\r
+               use_gain=(float)0.7;\r
+           else if (iLBCdec_inst->consPLICount*\r
+                           iLBCdec_inst->blockl>3*320)\r
+               use_gain=(float)0.5;\r
+           else if (iLBCdec_inst->consPLICount*\r
+   \r
+   \r
+                           iLBCdec_inst->blockl>4*320)\r
+               use_gain=(float)0.0;\r
+   \r
+           /* mix noise and pitch repeatition */\r
+           ftmp=(float)sqrt(max_per);\r
+           if (ftmp>(float)0.7)\r
+               pitchfact=(float)1.0;\r
+           else if (ftmp>(float)0.4)\r
+               pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);\r
+           else\r
+               pitchfact=0.0;\r
+   \r
+   \r
+           /* avoid repetition of same pitch cycle */\r
+           use_lag=lag;\r
+           if (lag<80) {\r
+               use_lag=2*lag;\r
+           }\r
+   \r
+           /* compute concealed residual */\r
+   \r
+           energy = 0.0;\r
+           for (i=0; i<iLBCdec_inst->blockl; i++) {\r
+   \r
+               /* noise component */\r
+   \r
+               iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & \r
+                   (0x80000000L-1);\r
+               randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;\r
+               pick = i - randlag;\r
+               \r
+               if (pick < 0) {\r
+                   randvec[i] = \r
+                       iLBCdec_inst->prevResidual[\r
+                                   iLBCdec_inst->blockl+pick];\r
+               } else {\r
+                   randvec[i] =  randvec[pick];\r
+               }\r
+   \r
+               /* pitch repeatition component */\r
+               pick = i - use_lag;\r
+               \r
+               if (pick < 0) {\r
+                   PLCresidual[i] =  \r
+                       iLBCdec_inst->prevResidual[\r
+                                   iLBCdec_inst->blockl+pick];\r
+               } else {\r
+                   PLCresidual[i] = PLCresidual[pick];\r
+               }\r
+   \r
+               /* mix random and periodicity component */\r
+   \r
+               if (i<80)\r
+                   PLCresidual[i] = use_gain*(pitchfact * \r
+   \r
+   \r
+                               PLCresidual[i] +\r
+                               ((float)1.0 - pitchfact) * randvec[i]);\r
+               else if (i<160)\r
+                   PLCresidual[i] = (float)0.95*use_gain*(pitchfact * \r
+                               PLCresidual[i] +\r
+                               ((float)1.0 - pitchfact) * randvec[i]);\r
+               else\r
+                   PLCresidual[i] = (float)0.9*use_gain*(pitchfact * \r
+                               PLCresidual[i] +\r
+                               ((float)1.0 - pitchfact) * randvec[i]);\r
+   \r
+               energy += PLCresidual[i] * PLCresidual[i];\r
+           }\r
+           \r
+           /* less than 30 dB, use only noise */\r
+           \r
+           if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { \r
+               gain=0.0;\r
+               for (i=0; i<iLBCdec_inst->blockl; i++) {\r
+                   PLCresidual[i] = randvec[i];\r
+               }\r
+           }\r
+   \r
+           /* use old LPC */\r
+   \r
+           memcpy(PLClpc,iLBCdec_inst->prevLpc,\r
+               (LPC_FILTERORDER+1)*sizeof(float));\r
+           \r
+       }\r
+   \r
+       /* no packet loss, copy input */\r
+   \r
+       else {\r
+           memcpy(PLCresidual, decresidual, \r
+               iLBCdec_inst->blockl*sizeof(float));\r
+           memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));\r
+           iLBCdec_inst->consPLICount = 0;\r
+       }\r
+       \r
+       /* update state */\r
+   \r
+       if (PLI) {\r
+           iLBCdec_inst->prevLag = lag;\r
+           iLBCdec_inst->per=max_per;\r
+       }\r
+   \r
+       iLBCdec_inst->prevPLI = PLI;\r
+       memcpy(iLBCdec_inst->prevLpc, PLClpc, \r
+           (LPC_FILTERORDER+1)*sizeof(float));\r
+       memcpy(iLBCdec_inst->prevResidual, PLCresidual,\r
+           iLBCdec_inst->blockl*sizeof(float));\r
+   }\r
+   \r
+   \r
+   \r
+   \r
index 778367440dec5f198d42b4c7d823aa73e9c32f06..7764b4e900c324069716ff9b117ffd677f7b1d40 100644 (file)
@@ -1,32 +1,32 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    doCPLC.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_DOLPC_H\r
-#define __iLBC_DOLPC_H\r
-\r
-void doThePLC(\r
-    float *PLCresidual, /* (o) concealed residual */ \r
-    float *PLClpc,      /* (o) concealed LP parameters */  \r
-    int PLI,        /* (i) packet loss indicator \r
-                               0 - no PL, 1 = PL */ \r
-    float *decresidual, /* (i) decoded residual */\r
-    float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
-    int inlag,          /* (i) pitch lag */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst \r
-                        /* (i/o) decoder instance */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       doCPLC.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_DOLPC_H\r
+   #define __iLBC_DOLPC_H\r
+   \r
+   void doThePLC(\r
+       float *PLCresidual, /* (o) concealed residual */ \r
+       float *PLClpc,      /* (o) concealed LP parameters */  \r
+       int PLI,        /* (i) packet loss indicator \r
+                                  0 - no PL, 1 = PL */ \r
+       float *decresidual, /* (i) decoded residual */\r
+       float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
+       int inlag,          /* (i) pitch lag */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i/o) decoder instance */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
diff --git a/libs/codec/ilbc/draft-ietf-avt-ilbc-codec-05.txt b/libs/codec/ilbc/draft-ietf-avt-ilbc-codec-05.txt
new file mode 100644 (file)
index 0000000..ff13d7c
--- /dev/null
@@ -0,0 +1,10191 @@
+\r
+   Internet Draft                                        S. V. Andersen\r
+   Document: draft-ietf-avt-ilbc-codec-05.txt        Aalborg University\r
+   Category: Experimental                                      A. Duric\r
+   May 29th, 2004                                                 Telio\r
+   Expires: November 29th, 2004                               H. Astrom\r
+                                                               R. Hagen\r
+                                                           W. B. Kleijn\r
+                                                              J. Linden\r
+                                                        Global IP Sound\r
+                                               \r
+                                               \r
+\r
+\r
+\r
+                        Internet Low Bit Rate Codec\r
+\r
+\r
+\r
+Status of this Memo\r
+\r
+\r
+   This document specifies an Internet experimental standards track\r
+   protocol for the Internet community, and requests discussion and\r
+   suggestions for improvements. Please refer to the current edition of\r
+   the "Internet Official Protocol Standards" (STD 1) for the\r
+   standardization state and status of this protocol. Distribution of\r
+   this memo is unlimited.\r
+   \r
+   By submitting this Internet-Draft, we certify that any applicable\r
+   patent or other IPR claims of which we am aware have been disclosed,\r
+   and any of which we become aware will be disclosed, in accordance\r
+   with RFC 3668.\r
+\r
+\r
+Copyright Notice\r
+   \r
+   Copyright (C) The Internet Society (2004). All Rights Reserved.\r
+   \r
+Abstract\r
+   \r
+   This document specifies a speech codec suitable for robust voice\r
+   communication over IP. The codec is developed by Global IP Sound\r
+   (GIPS). It is designed for narrow band speech and results in a\r
+   payload bit rate of 13.33 kbit/s for 30 ms frames and 15.20 kbit/s\r
+   for 20 ms frames. The codec enables graceful speech quality\r
+   degradation in the case of lost frames, which occurs in connection\r
+   with lost or delayed IP packets.\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.                                                  1\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+Table of Contents\r
+   \r
+   Status of this Memo................................................1\r
+   Copyright Notice...................................................1\r
+   Abstract...........................................................1\r
+   Table of Contents..................................................2\r
+   1. INTRODUCTION....................................................5\r
+   2. OUTLINE OF THE CODEC............................................5\r
+   2.1 Encoder........................................................6\r
+   2.2 Decoder........................................................7\r
+   3. ENCODER PRINCIPLES..............................................8\r
+   3.1 Pre-processing.................................................9\r
+   3.2 LPC Analysis and Quantization..................................9\r
+   3.2.1 Computation of Autocorrelation Coefficients..................9\r
+   3.2.2 Computation of LPC Coefficients.............................11\r
+   3.2.3 Computation of LSF Coefficients from LPC Coefficients.......11\r
+   3.2.4 Quantization of LSF Coefficients............................11\r
+   3.2.5 Stability Check of LSF Coefficients.........................12\r
+   3.2.6 Interpolation of LSF Coefficients...........................12\r
+   3.2.7 LPC Analysis and Quantization for 20 ms frames..............13\r
+   3.3 Calculation of the Residual...................................14\r
+   3.4 Perceptual Weighting Filter...................................14\r
+   3.5 Start State Encoder...........................................15\r
+   3.5.1 Start State Estimation......................................15\r
+   3.5.2 All-Pass Filtering and Scale Quantization...................16\r
+   3.5.3 Scalar Quantization.........................................17\r
+   3.6 Encoding the remaining samples................................17\r
+   3.6.1 Codebook Memory.............................................19\r
+   3.6.2 Perceptual Weighting of Codebook Memory and Target..........20\r
+   3.6.3 Codebook Creation...........................................21\r
+   3.6.3.1 Creation of a Base Codebook...............................21\r
+   3.6.3.2 Codebook Expansion........................................22\r
+   3.6.3.3 Codebook Augmentation.....................................22\r
+   3.6.4 Codebook Search.............................................23\r
+   3.6.4.1 Codebook Search at Each Stage.............................24\r
+   3.6.4.2 Gain Quantization at Each Stage...........................24\r
+   3.6.4.3 Preparation of Target for Next Stage......................26\r
+   3.7 Gain Correction Encoding......................................26\r
+   3.8 Bitstream Definition..........................................27\r
+   4. DECODER PRINCIPLES.............................................30\r
+   4.1 LPC Filter Reconstruction.....................................30\r
+   4.2 Start State Reconstruction....................................31\r
+   4.3 Excitation Decoding Loop......................................31\r
+   4.4 Multistage Adaptive Codebook Decoding.........................32\r
+   4.4.1 Construction of the Decoded Excitation Signal...............32\r
+   4.5 Packet Loss Concealment.......................................33\r
+   4.5.1 Block Received Correctly and Previous Block also Received...33\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      2\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   4.5.2 Block Not Received..........................................33\r
+   4.5.3 Block Received Correctly When Previous Block Not Received...34\r
+   4.6 Enhancement...................................................34\r
+   4.6.1 Estimating the pitch........................................36\r
+   4.6.2 Determination of the Pitch-Synchronous Sequences............36\r
+   4.6.3 Calculation of the smoothed excitation......................37\r
+   4.6.4 Enhancer criterion..........................................38\r
+   4.6.5 Enhancing the excitation....................................38\r
+   4.7 Synthesis Filtering...........................................39\r
+   4.8 Post Filtering................................................39\r
+   5. IANA CONSIDERATIONS............................................39\r
+   6. SECURITY CONSIDERATIONS........................................39\r
+   7. EVALUATION OF THE ILBC IMPLEMENTATIONS.........................39\r
+   8. REFERENCES.....................................................40\r
+   8.1 Normative.....................................................40\r
+   8.2 Informative...................................................40\r
+   9. ACKNOWLEDGEMENTS...............................................40\r
+   10. AUTHOR'S ADDRESSES............................................41\r
+   Full Copyright Statement..........................................42\r
+   Intellectual Property.............................................42\r
+   APPENDIX A REFERENCE IMPLEMENTATION...............................43\r
+   A.1 iLBC_test.c...................................................44\r
+   A.2 iLBC_encode.h.................................................49\r
+   A.3 iLBC_encode.c.................................................50\r
+   A.4 iLBC_decode.h.................................................59\r
+   A.5 iLBC_decode.c.................................................60\r
+   A.6 iLBC_define.h.................................................71\r
+   A.7 constants.h...................................................74\r
+   A.8 constants.c...................................................76\r
+   A.9 anaFilter.h...................................................89\r
+   A.10 anaFilter.c..................................................89\r
+   A.11 createCB.h...................................................90\r
+   A.12 createCB.c...................................................91\r
+   A.13 doCPLC.h.....................................................95\r
+   A.14 doCPLC.c.....................................................96\r
+   A.15 enhancer.h..................................................101\r
+   A.16 enhancer.c..................................................101\r
+   A.17 filter.h....................................................113\r
+   A.18 filter.c....................................................114\r
+   A.19 FrameClassify.h.............................................117\r
+   A.20 FrameClassify.c.............................................118\r
+   A.21 gainquant.h.................................................120\r
+   A.22 gainquant.c.................................................120\r
+   A.23 getCBvec.h..................................................122\r
+   A.24 getCBvec.c..................................................123\r
+   A.25 helpfun.h...................................................126\r
+   A.26 helpfun.c...................................................128\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      3\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   A.27 hpInput.h...................................................133\r
+   A.28 hpInput.c...................................................134\r
+   A.29 hpOutput.h..................................................135\r
+   A.30 hpOutput.c..................................................135\r
+   A.31 iCBConstruct.h..............................................136\r
+   A.32 iCBConstruct.c..............................................137\r
+   A.33 iCBSearch.h.................................................139\r
+   A.34 iCBSearch.c.................................................140\r
+   A.35 LPCdecode.h.................................................148\r
+   A.36 LPCdecode.c.................................................149\r
+   A.37 LPCencode.h.................................................152\r
+   A.38 LPCencode.c.................................................152\r
+   A.39 lsf.h.......................................................156\r
+   A.40 lsf.c.......................................................157\r
+   A.41 packing.h...................................................162\r
+   A.42 packing.c...................................................163\r
+   A.43 StateConstructW.h...........................................166\r
+   A.44 StateConstructW.c...........................................166\r
+   A.45 StateSearchW.h..............................................168\r
+   A.46 StateSearchW.c..............................................169\r
+   A.47 syntFilter.h................................................172\r
+   A.48 syntFilter.c................................................173\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      4\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+1. INTRODUCTION \r
+\r
+\r
+   This document contains the description of an algorithm for the\r
+   coding of speech signals sampled at 8 kHz. The algorithm, called\r
+   iLBC, uses a block-independent linear-predictive coding (LPC)\r
+   algorithm and has support for two basic frame lengths: 20 ms at 15.2\r
+   kbit/s and 30 ms at 13.33 kbit/s. When the codec operates at block\r
+   lengths of 20 ms, it produces 304 bits per block which SHOULD be\r
+   packetized as in [1]. Similarly, for block lengths of 30 ms it\r
+   produces 400 bits per block which SHOULD be packetized as in [1].\r
+   The two modes for the different frame sizes operate in a very\r
+   similar way. When they differ it is explicitly stated in the text,\r
+   usually with the notation x/y, where x refers to the 20 ms mode and\r
+   y refers to the 30 ms mode.\r
+   \r
+   The described algorithm results in a speech coding system with a\r
+   controlled response to packet losses similar to what is known from\r
+   pulse code modulation (PCM) with packet loss concealment (PLC), such\r
+   as the ITU-T G.711 standard [4] which operates at a fixed bit rate\r
+   of 64 kbit/s. At the same time, the described algorithm enables\r
+   fixed bit rate coding with a quality-versus-bit rate tradeoff close\r
+   to state-of-the-art. A suitable RTP payload format for the iLBC\r
+   codec is specified in [1].\r
+   \r
+   Some of the applications for which this coder is suitable are: real\r
+   time communications such as telephony and videoconferencing,\r
+   streaming audio, archival, and messaging.\r
+   \r
+   Cable Television Laboratories (CableLabs(R)) intends to adapt iLBC\r
+   as a PacketCable(TM) audio codec standard for VoIP over Cable\r
+   applications [3].\r
+   \r
+   This document is organized as follows. In Section 2 a brief outline\r
+   of the codec is given. The specific encoder and decoder algorithms\r
+   are explained in Sections 3 and 4, respectively. A c-code reference\r
+   implementation is provided in Appendix A.\r
+   \r
+   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",\r
+   "SHOULD", "SHOULD NOT", "RECOMMENDED",  "MAY", and "OPTIONAL" in\r
+   this document are to be interpreted as described in RFC 2119 [2].\r
+\r
+\r
+   \r
+2. OUTLINE OF THE CODEC\r
+\r
+\r
+   The codec consists of an encoder and a decoder described in Section\r
+   2.1 and 2.2, respectively.\r
+   \r
+   The essence of the codec is LPC and block based coding of the LPC\r
+   residual signal. For each 160/240 (20ms/30 ms) sample block, the\r
+   following major steps are performed: A set of LPC filters are\r
+   computed and the speech signal is filtered through them to produce\r
+   the residual signal. The codec uses scalar quantization of the\r
+   dominant part, in terms of energy, of the residual signal for the\r
+   block. The dominant state is of length 57/58 (20 ms/30 ms) samples\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      5\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   and forms a start state for dynamic codebooks constructed from the\r
+   already coded parts of the residual signal. These dynamic codebooks\r
+   are used to code the remaining parts of the residual signal. By this\r
+   method, coding independence between blocks is achieved, resulting in\r
+   elimination of propagation of perceptual degradations due to packet\r
+   loss. The method facilitates high-quality packet loss concealment\r
+   (PLC).\r
+\r
+\r
+2.1 Encoder\r
+   \r
+   The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8\r
+   kHz. It SHOULD be partitioned into blocks of BLOCKL=160/240 samples\r
+   for the 20/30 ms frame size. Each block is divided into NSUB=4/6\r
+   consecutive sub-blocks of SUBL=40 samples each. For 30 ms frame\r
+   size, the encoder performs two LPC_FILTERORDER=10 linear-predictive\r
+   coding (LPC) analyses. The first analysis applies a smooth window\r
+   centered over the 2nd sub-block and extending to the middle of the\r
+   5th sub-block. The second LPC analysis applies a smooth asymmetric\r
+   window centered over the 5th sub-block and extending to the end of\r
+   the 6th sub-block. For 20 ms frame size one LPC_FILTERORDER=10\r
+   linear-predictive coding (LPC) analysis is performed with a smooth\r
+   window centered over the 3rd sub-frame.\r
+   \r
+   For each of the LPC analyses, a set of line-spectral frequencies\r
+   (LSFs) are obtained, quantized and interpolated to obtain LSF\r
+   coefficients for each sub-block. Subsequently, the LPC residual is\r
+   computed using the quantized and interpolated LPC analysis filters.\r
+   \r
+   The two consecutive sub-blocks of the residual exhibiting the\r
+   maximal weighted energy are identified. Within these 2 sub-blocks,\r
+   the start state (segment) is selected from two choices: the first\r
+   57/58 samples or the last 57/58 samples of the 2 consecutive sub-\r
+   blocks. The selected segment is the one of higher energy. The start\r
+   state is encoded with scalar quantization. \r
+   \r
+   A dynamic codebook encoding procedure is used to encode 1) the 23/22\r
+   (20 ms/30 ms) remaining samples in the 2 sub-blocks containing the\r
+   start state; 2) encoding of the sub-blocks after the start state in\r
+   time; 3) encoding of the sub-blocks before the start state in time.\r
+   Thus, the encoding target can be either the 23/22 samples remaining\r
+   of the 2 sub-blocks containing the start state or a 40 sample sub-\r
+   block. This target can consist of samples that are indexed forwards\r
+   in time or backwards in time depending on the location of the start\r
+   state. \r
+   \r
+   The coding is based on an adaptive codebook that is built from a\r
+   codebook memory which contains decoded LPC excitation samples from\r
+   the already encoded part of the block. These samples are indexed in\r
+   the same time direction as the target vector and ending at the\r
+   sample instant prior to the first sample instant represented in the\r
+   target vector. The codebook is used in CB_NSTAGES=3 stages in a\r
+   successive refinement approach and the resulting 3 code vector gains\r
+   are encoded with 5, 4, and 3 bit scalar quantization, respectively.\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      6\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   The codebook search method employs noise shaping derived from the\r
+   LPC filters and the main decision criterion is minimizing the\r
+   squared error between the target vector and the code vectors. Each\r
+   code vector in this codebook comes from one of CB_EXPAND=2 codebook\r
+   sections. The first section is filled with delayed, already encoded\r
+   residual vectors. The code vectors of the second codebook section\r
+   are constructed by predefined linear combinations of vectors in the\r
+   first section of the codebook.\r
+\r
+\r
+   Since codebook encoding with squared-error matching is known to\r
+   produce a coded signal of less power than the scalar quantized start\r
+   state signal, a gain re-scaling method is implemented by a refined\r
+   search for a better set of codebook gains in terms of power matching\r
+   after encoding. This is done by searching for a higher value of the\r
+   gain factor for the first stage codebook since the subsequent stage\r
+   codebook gains are scaled by the first stage gain.\r
+\r
+\r
+2.2 Decoder\r
+   \r
+   For packet communications, typically a jitter buffer placed at the\r
+   receiving end decides whether the packet containing an encoded\r
+   signal block has been received or lost. This logic is not part of\r
+   the codec described here. For each received encoded signal block the\r
+   decoder performs a decoding. For each lost signal block the decoder\r
+   performs a PLC operation.\r
+   \r
+   The decoding for each block starts by decoding and interpolating the\r
+   LPC coefficients. Subsequently the start state is decoded.\r
+   \r
+   For codebook encoded segments, each segment is decoded by\r
+   constructing the 3 code vectors given by the received codebook\r
+   indices in the same way as the code vectors were constructed in the\r
+   encoder. The 3 gain factors are also decoded and the resulting\r
+   decoded signal is given by the sum of the 3 codebook vectors scaled\r
+   with respective gain.\r
+   \r
+   An enhancement algorithm is applied on the reconstructed excitation\r
+   signal. This enhancement augments the periodicity of voiced speech\r
+   regions. The enhancement is optimized under the constraint that the\r
+   modification signal (defined as the difference between the enhanced\r
+   excitation and the excitation signal prior to enhancement) has a\r
+   short-time energy that does not exceed a preset fraction of the\r
+   short-time energy of the excitation signal prior to enhancement.\r
+   \r
+   A packet loss concealment (PLC) operation is easily embedded in the\r
+   decoder. The PLC operation can, e.g., be based on repetition of LPC\r
+   filters and obtaining the LPC residual signal using a long term\r
+   prediction estimate from previous residual blocks. \r
+   \r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      7\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+3. ENCODER PRINCIPLES\r
+   \r
+   The following block diagram is an overview of all the components of\r
+   the iLBC encoding procedure. The description of the blocks contains\r
+   references to the section where that particular procedure is\r
+   described further.\r
+   \r
+              +-----------+    +---------+    +---------+   \r
+    speech -> | 1. Pre P  | -> | 2. LPC  | -> | 3. Ana  | ->\r
+              +-----------+    +---------+    +---------+   \r
+   \r
+              +---------------+   +--------------+    \r
+           -> | 4. Start Sel  | ->| 5. Scalar Qu | -> \r
+              +---------------+   +--------------+   \r
+   \r
+              +--------------+    +---------------+\r
+           -> |6. CB Search  | -> | 7. Packetize  | -> payload\r
+           |  +--------------+ |  +---------------+\r
+           ----<---------<------\r
+        sub-frame 0..2/4 (20 ms/30 ms)\r
+   \r
+   Figure 3.1. Flow chart of the iLBC encoder\r
+   \r
+   1. Pre process speech with a HP filter if needed (section 3.1)\r
+   2. Compute LPC parameters, quantize and interpolate (section 3.2)\r
+   3. Use analysis filters on speech to compute residual (section 3.3)\r
+   4. Select position of 57/58 sample start state (section 3.5)\r
+   5. Quantize the 57/58 sample start state with scalar quantization\r
+   (section 3.5)\r
+   6. Search the codebook for each sub-frame. Start with 23/22 sample\r
+   block, then encode sub-blocks forward in time and then encode sub-\r
+   blocks backward in time. For each block the steps in figure 3.4 are\r
+   performed (section 3.6)\r
+   7. Packetize the bits into the payload specified in table 3.2.\r
+   \r
+   The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8\r
+   kHz. Also it SHOULD be partitioned into blocks of BLOCKL=160/240\r
+   samples. Each block input to the encoder is divided into NSUB=4/6\r
+   consecutive sub-blocks of SUBL=40 samples each.\r
+   \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      8\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               0        39        79       119       159\r
+               +---------------------------------------+\r
+               |    1    |    2    |    3    |    4    |\r
+               +---------------------------------------+\r
+                              20 ms frame\r
+   \r
+     0        39        79       119       159       199       239\r
+     +-----------------------------------------------------------+\r
+     |    1    |    2    |    3    |    4    |    5    |    6    |\r
+     +-----------------------------------------------------------+\r
+                               30 ms frame\r
+   \r
+   Figure 3.2. One input block to the encoder for 20 ms (with 4 sub-\r
+   frames) and 30 ms (with 6 sub-frames).\r
+\r
+\r
+3.1 Pre-processing\r
+   \r
+   In some applications the recorded speech signal contains DC level\r
+   and/or 50/60 Hz noise. If these components have not been removed\r
+   prior to the encoder call, they should be removed by a high-pass\r
+   filter. A reference implementation of this, using a filter with cut\r
+   off frequency 90 Hz, can be found in Appendix A.28.\r
+\r
+\r
+3.2 LPC Analysis and Quantization\r
+   \r
+   The input to the LPC analysis module is a possibly high-pass\r
+   filtered speech buffer, speech_hp, that contains 240/300\r
+   (LPC_LOOKBACK + BLOCKL = 80/60 + 160/240 = 240/300) speech samples\r
+,\r
+   where samples 0 through 79/59 are from the previous block and\r
+   samples 80/60 through 239/299 are from the current block. No look-\r
+   ahead into the next block is used. For the very first block\r
+   processed, the look back samples are assumed to be zeros.\r
+   \r
+   For each input block, the LPC analysis calculates one/two set(s) of\r
+   LPC_FILTERORDER=10 LPC filter coefficients using the autocorrelation\r
+\r
+\r
+   method and the Levinson-Durbin recursion. These coefficients are\r
+   converted to the Line Spectrum Frequency representation. In the 20\r
+   ms case the set, lsf, represents the spectral characteristics as\r
+   measured at the center of the third sub-block. For 30 ms frames the\r
+   first set, lsf1, represents the spectral properties of the input\r
+   signal at the center of the second sub-block while the other set,\r
+   lsf2, represents the spectral characteristics as measured at the\r
+   center of the fifth sub-block. The details of the computation for 30\r
+   ms frames are described in 3.2.1 through 3.2.6. Section 3.2.7\r
+   explains how the LPC Analysis and Quantization differs for 20 ms\r
+   frames.\r
+\r
+\r
+ 3.2.1 Computation of Autocorrelation Coefficients\r
+   \r
+   The first step in the LPC analysis procedure is to calculate\r
+   autocorrelation coefficients using windowed speech samples. This\r
+   windowing is the only difference in the LPC analysis procedure for\r
+   the two sets of coefficients. For the first set, a 240 sample long\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004      9\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   standard symmetric Hanning window is applied to samples 0 through\r
+   239 of the input data. The first window, lpc_winTbl, is defined as:\r
+   \r
+         lpc_winTbl[i]= 0.5 * (1.0 - cos((2*PI*(i+1))/(BLOCKL+1)));\r
+                  i=0,...,119\r
+         lpc_winTbl[i] = winTbl[BLOCKL - i - 1]; i=120,...,239\r
+   \r
+   The windowed speech speech_hp_win1 is then obtained by multiplying\r
+   the 240 first samples of the input speech buffer with the window\r
+   coefficients:\r
+   \r
+         speech_hp_win1[i] = speech_hp[i] * lpc_winTbl[i];\r
+                  i=0,...,BLOCKL-1\r
+   \r
+   From these 240 windowed speech samples, 11 (LPC_FILTERORDER + 1)\r
+   autocorrelation coefficients, acf1, are calculated:\r
+   \r
+         acf1[lag] += speech_hp_win1[n] * speech_hp_win1[n + lag];\r
+                  lag=0,...,LPC_FILTERORDER; n=0,...,BLOCKL-lag-1\r
+   \r
+   In order to make the analysis more robust against numerical\r
+   precision problems, a spectral smoothing procedure is applied by\r
+   windowing the autocorrelation coefficients before the LPC\r
+   coefficients are computed. Also, a white noise floor is added to the\r
+   autocorrelation function by multiplying coefficient zero by 1.0001\r
+   (40dB below the energy of the windowed speech signal). These two\r
+   steps are implemented by multiplying the autocorrelation\r
+   coefficients with the following window:\r
+   \r
+         lpc_lagwinTbl[0] = 1.0001; \r
+         lpc_lagwinTbl[i] = exp(-0.5 * ((2 * PI * 60.0 * i) /FS)^2); \r
+                  i=1,...,LPC_FILTERORDER\r
+                  where FS=8000 is the sampling frequency\r
+   \r
+   Then, the windowed acf function acf1_win is obtained by:\r
+   \r
+         acf1_win[i] = acf1[i] * lpc_lagwinTbl[i];\r
+                  i=0,...,LPC_FILTERORDER\r
+   \r
+   The second set of autocorrelation coefficients, acf2_win are\r
+   obtained in a similar manner. The window, lpc_asymwinTbl, is applied\r
+   to samples 60 through 299, i.e., the entire current block. The\r
+   window consists of two segments; the first (samples 0 to 219) being\r
+   half a Hanning window with length 440 and the second being a quarter\r
+   of a cycle of a cosine wave. By using this asymmetric window, an LPC\r
+   analysis centered in the fifth sub-block is obtained without the\r
+   need for any look-ahead, which would have added delay. The\r
+   asymmetric window is defined as:\r
+   \r
+         lpc_asymwinTbl[i] = (sin(PI * (i + 1) / 441))^2; i=0,...,219\r
+\r
+\r
+         lpc_asymwinTbl[i] = cos((i - 220) * PI / 40); i=220,...,239\r
+   \r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     10\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   and the windowed speech is computed by:\r
+   \r
+         speech_hp_win2[i] = speech_hp[i + LPC_LOOKBACK] *\r
+                  lpc_asymwinTbl[i];  i=0,....BLOCKL-1\r
+   \r
+   The windowed autocorrelation coefficients are then obtained in\r
+   exactly the same way as for the first analysis instance.\r
+   \r
+   The generation of the windows lpc_winTbl, lpc_asymwinTbl, and\r
+   lpc_lagwinTbl are typically done in advance and the arrays are\r
+   stored in ROM rather than repeating the calculation for every block.\r
+\r
+\r
+ 3.2.2 Computation of LPC Coefficients\r
+   \r
+   From the 2 x 11 smoothed autocorrelation coefficients, acf1_win and\r
+   acf2_win, the 2 x 11 LPC coefficients, lp1 and lp2, are calculated\r
+   in the same way for both analysis locations using the well known\r
+   Levinson-Durbin recursion. The first LPC coefficient is always 1.0,\r
+   resulting in 10 unique coefficients.\r
+   \r
+   After determining the LPC coefficients, a bandwidth expansion\r
+   procedure is applied in order to smooth the spectral peaks in the\r
+   short-term spectrum. The bandwidth addition is obtained by the\r
+   following modification of the LPC coefficients:\r
+   \r
+         lp1_bw[i] = lp1[i] * chirp^i; i=0,...,LPC_FILTERORDER\r
+         lp2_bw[i] = lp2[i] * chirp^i; i=0,...,LPC_FILTERORDER\r
+   \r
+   where "chirp" is a real number between 0 and 1. It is RECOMMENDED to\r
+   use a value of 0.9.\r
+\r
+\r
+ 3.2.3 Computation of LSF Coefficients from LPC Coefficients\r
+   \r
+   Thusfar, two sets of LPC coefficients that represent the short-term\r
+   spectral characteristics of the speech signal for two different time\r
+   locations within the current block have been determined. These\r
+   coefficients SHOULD be quantized and interpolated. Before doing so,\r
+   it is advantageous to convert the LPC parameters into another type\r
+   of representation called Line Spectral Frequencies (LSF). The LSF\r
+   parameters are used because they are better suited for quantization\r
+   and interpolation than the regular LPC coefficients. Many\r
+   computationally efficient methods for calculating the LSFs from the\r
+   LPC coefficients have been proposed in the literature. The detailed\r
+   implementation of one applicable method can be found in Appendix\r
+   A.26. The two arrays of LSF coefficients obtained, lsf1 and lsf2,\r
+   are of dimension 10 (LPC_FILTERORDER).\r
+\r
+\r
+ 3.2.4 Quantization of LSF Coefficients\r
+   \r
+   Since the LPC filters defined by the two sets of LSFs are needed\r
+   also in the decoder, the LSF parameters need to be quantized and\r
+   transmitted as side information. The total number of bits required\r
+   to represent the quantization of the two LSF representations for one\r
+   block of speech is 40 with 20 bits used for each of lsf1 and lsf2.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     11\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   For computational and storage reasons, the LSF vectors are quantized\r
+   using 3-split vector quantization (VQ). That is, the LSF vectors are\r
+   split into three sub-vectors which are each quantized with a regular\r
+   VQ. The quantized versions of lsf1 and lsf2, qlsf1 and qlsf2, are\r
+   obtained by using the same memoryless split VQ.  The length of each\r
+   of these two LSF vectors is 10 and they are split into 3 sub-vectors\r
+   containing 3, 3 and 4 values respectively.\r
+   \r
+   For each of the sub-vectors, a separate codebook of quantized values\r
+   has been designed using a standard VQ training method for a large\r
+   database containing speech from a large number of speakers recorded\r
+   under various conditions. The size of each of the three codebooks\r
+   associated with the split definitions above is:\r
+   \r
+        int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};\r
+   \r
+   The actual values of the vector quantization codebook that must be\r
+   used can be found in the reference code of appendix A. Both sets of\r
+   LSF coefficients, lsf1 and lsf2, are quantized with a standard\r
+   memoryless split vector quantization (VQ) structure using the\r
+   squared error criterion in the LSF domain. The split VQ quantization\r
+   consists of the following steps:\r
+   \r
+   1) Quantize the first 3 LSF coefficients (1 - 3) with a VQ codebook\r
+   of size 64.\r
+   2) Quantize the LSF coefficients 4, 5, and 6 with VQ a codebook of\r
+   size 128.\r
+   3) Quantize the last 4 LSF coefficients (7 - 10) with a VQ codebook\r
+   of size 128.\r
+   \r
+   This procedure, repeated for lsf1 and lsf2, gives 6 quantization\r
+   indices and the quantized sets of LSF coefficients qlsf1 and qlsf2.\r
+   Each set of three indices is encoded with 6 + 7 + 7 = 20 bits. The\r
+   total number of bits used for LSF quantization in a block is thus 40\r
+   bits. \r
+\r
+\r
+ 3.2.5 Stability Check of LSF Coefficients\r
+   \r
+   The LSF representation of the LPC filter has the nice property that\r
+   the coefficients are ordered by increasing value, i.e., lsf(n-1) <\r
+   lsf(n), 0 < n < 10, if the corresponding synthesis filter is stable.\r
+   Since we are employing a split VQ scheme it is possible that at the\r
+   split boundaries the LSF coefficients are not ordered correctly and\r
+   hence the corresponding LP filter is unstable. To ensure that the\r
+   filter used is stable, a stability check is performed for the\r
+   quantized LSF vectors. If it turns out that the coefficients are not\r
+   ordered appropriately (with a safety margin of 50 Hz to ensure that\r
+   formant peaks are not too narrow) they will be moved apart. The\r
+   detailed method for this can be found in Appendix A.40. The same\r
+   procedure is performed in the decoder. This ensures that exactly the\r
+   same LSF representations are used in both encoder and decoder.\r
+\r
+\r
+ 3.2.6 Interpolation of LSF Coefficients\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     12\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   From the two sets of LSF coefficients that are computed for each\r
+   block of speech, different LSFs are obtained for each sub-block by\r
+   means of interpolation. This procedure is performed for the original\r
+   LSFs (lsf1 and lsf2), as well as the quantized versions qlsf1 and\r
+   qlsf2 since both versions are used in the encoder. Here follows a\r
+   brief summary of the interpolation scheme while the details are\r
+   found in the c-code of Appendix A. In the first sub-block, the\r
+   average of the second LSF vector from the previous block and the\r
+   first LSF vector in the current block is used. For sub-blocks two\r
+   through five the LSFs used are obtained by linear interpolation from\r
+   lsf1 (and qlsf1) to lsf2 (and qlsf2) with lsf1 used in sub-block two\r
+   and lsf2 in sub-block five. In the last sub-block, lsf2 is used. For\r
+   the very first block it is assumed that the last LSF vector of the\r
+   previous block is equal to a predefined vector, lsfmeanTbl, that was\r
+   obtained by calculating the mean LSF vector of the LSF design\r
+   database.\r
+   \r
+   lsfmeanTbl[LPC_FILTERORDER] = {0.281738, 0.445801, 0.663330, \r
+                  0.962524, 1.251831, 1.533081, 1.850586, 2.137817,\r
+                  2.481445, 2.777344}\r
+   \r
+   The interpolation method is standard linear interpolation in the LSF\r
+   domain. The interpolated LSF values are converted to LPC\r
+   coefficients for each sub-block. The unquantized and quantized LPC\r
+   coefficients form two sets of filters respectively. The unquantized\r
+   analysis filter for sub-block k:\r
+   \r
+                ___\r
+                \\r
+      Ak(z)= 1 + > ak(i)*z^(-i)\r
+                /__\r
+             i=1...LPC_FILTERORDER\r
+   \r
+   And the quantized analysis filter for sub-block k:\r
+                 ___\r
+                 \\r
+      A~k(z)= 1 + > a~k(i)*z^(-i)\r
+                 /__\r
+             i=1...LPC_FILTERORDER\r
+   \r
+   A reference implementation of the lsf encoding is given in Appendix\r
+   A.38. A reference implementation of the corresponding decoding can\r
+   be found in Appendix A.36.\r
+  \r
+ 3.2.7 LPC Analysis and Quantization for 20 ms frames\r
\r
+   As stated before, the codec only calculates one set of LPC\r
+   parameters for the 20 ms frame size as opposed to two sets for 30 ms\r
+   frames. A single set of autocorrelation coefficients is calculated\r
+   on the LPC_LOOKBACK + BLOCKL = 80 + 160 = 240 samples. These sampl\r
+es\r
+   are windowed with the asymmetric window lpc_asymwinTbl, centered\r
+   over the third sub-frame, to form speech_hp_win. Autocorrelation\r
+   coefficients, acf, are calculated on the 240 samples in\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     13\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   speech_hp_win and then windowed exactly as in 3.2.1 (resulting in\r
+   acf_win).\r
+   \r
+   This single set of windowed autocorrelation coefficients is used to\r
+   calculate LPC Coefficients, LSF Coefficients and quantized LSF\r
+   coefficients in exactly the same manner as in 3.2.3 to 3.2.4. As for\r
+   the 30 ms frame size, the 10 LSF coefficients are divided into three\r
+   sub-vectors of size 3, 3, 4 and quantized using the same scheme and\r
+   codebook as in 3.2.4 to finally get 3 quantization indices. The\r
+   quantized LSF coefficients are stabilized with the algorithm\r
+   described in 3.2.5.\r
+   \r
+   From the set of LSF coefficients that was computed for this block\r
+   together with the LSF coefficients from the previous block,\r
+   different LSFs are obtained for each sub-block by means of\r
+   interpolation. The interpolation is done linearly in the LSF domain\r
+   over the 4 sub-blocks, so that the n-th sub-frame uses the weight\r
+   (4-n)/4 for the LSF from old frame and the weight n/4 of the LSF\r
+   from the current frame. For the very first block the mean LSF,\r
+   lsfmeanTbl, is used as the LSF from the previous block. Similar to\r
+   3.2.6, both unquantized, A(z), and quantized, A~(z), analysis\r
+   filters are calculated for each of the four sub-blocks.\r
+\r
+\r
+3.3 Calculation of the Residual\r
+   \r
+   The block of speech samples is filtered by the quantized and\r
+   interpolated LPC analysis filters to yield the residual signal. In\r
+   particular, the corresponding LPC analysis filter for each 40 sample\r
+   sub-block is used to filter the speech samples for the same sub-\r
+   block. The filter memory at the end of each sub-block is carried\r
+   over to the LPC filter of the next sub-block.  The signal at the\r
+   output of each LP analysis filter constitutes the residual signal\r
+   for the corresponding sub-block.\r
+   \r
+   A reference implementation of the LPC analysis filters is given in\r
+   Appendix A.10.\r
+\r
+\r
+3.4 Perceptual Weighting Filter\r
+   \r
+   In principle any good design of a perceptual weighting filter can be\r
+   applied in the encoder without compromising this codec definition.\r
+   It is however RECOMMENDED to use the perceptual weighting filter\r
+   specified below:\r
+   \r
+      Weighting filter for sub-block k:\r
+   \r
+      Wk(z)=1/Ak(z/LPC_CHIRP_WEIGHTDENUM), where\r
+                               LPC_CHIRP_WEIGHTDENUM = 0.4222\r
+   \r
+   This is a simple design with low complexity that is applied in the\r
+   LPC residual domain. Here Ak(z) is the filter obtained from\r
+   unquantized but interpolated LSF coefficients.\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     14\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+3.5 Start State Encoder \r
+   \r
+   The start state is quantized using a common 6-bit scalar quantizer\r
+   for the block and a 3-bit scalar quantizer operating on scaled\r
+   samples in the weighted speech domain. In the following we describe\r
+   the state encoding in greater detail.\r
+\r
+\r
+ 3.5.1 Start State Estimation\r
+   \r
+   The two sub-blocks containing the start state are determined by\r
+   finding the two consecutive sub-blocks in the block having the\r
+   highest power. Advantageously, down-weighting is used in the\r
+   beginning and end of the sub-frames. I.e., the following measure is\r
+   computed (NSUB=4/6 for 20/30 ms frame size):\r
+   \r
+         nsub=1,...,NSUB-1 \r
+         ssqn[nsub] = 0.0; \r
+         for (i=(nsub-1)*SUBL; i<(nsub-1)*SUBL+5; i++) \r
+                  ssqn[nsub] += sampEn_win[i-(nsub-1)*SUBL]*\r
+                                    residual[i]*residual[i];\r
+         for (i=(nsub-1)*SUBL+5; i<(nsub+1)*SUBL-5; i++) \r
+                  ssqn[nsub] += residual[i]*residual[i];\r
+         for (i=(nsub+1)*SUBL-5; i<(nsub+1)*SUBL; i++) \r
+                  ssqn[nsub] += sampEn_win[(nsub+1)*SUBL-i-1]*\r
+                                    residual[i]*residual[i];\r
+   \r
+   where sampEn_win[5]={1/6, 2/6, 3/6, 4/6, 5/6}; MAY be used. The sub-\r
+   frame number corresponding to the maximum value of ssqEn_win[nsub-\r
+   1]*ssqn[nsub] is selected as the start state indicator. A weighting\r
+   of ssqEn_win[]={0.8,0.9,1.0,0.9,0.8} for 30 ms frames and\r
+   ssqEn_win[]={0.9,1.0,0.9} for 20 ms frames; MAY advantageously be\r
+   used to bias the start state towards the middle of the frame. \r
+   \r
+   For 20 ms frames there are 3 possible positions of the two-sub-block\r
+   length maximum power segment, the start state position is encoded\r
+   using 2 bits. The start state position, start, MUST be encoded as:\r
+   \r
+         start=1: start state in sub-frame 0 and 1\r
+         start=2: start state in sub-frame 1 and 2\r
+         start=3: start state in sub-frame 2 and 3\r
+   \r
+   For 30 ms frames there are 5 possible positions of the two-sub-block\r
+   length maximum power segment, the start state position is encoded\r
+   using 3 bits. The start state position, start, MUST be encoded as:\r
+   \r
+         start=1: start state in sub-frame 0 and 1\r
+         start=2: start state in sub-frame 1 and 2\r
+         start=3: start state in sub-frame 2 and 3\r
+         start=4: start state in sub-frame 3 and 4\r
+         start=5: start state in sub-frame 4 and 5\r
+   \r
+   hence, in both cases, index 0 is not utilized. In order to shorten\r
+   the start state for bit rate efficiency, the start state is brought\r
+   down to STATE_SHORT_LEN=57 samples for 20 ms frames and\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     15\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   STATE_SHORT_LEN=58 samples for 30 ms frames. The power of the first\r
+   23/22 and last 23/22 samples of the 2 sub-frame block identified\r
+   above is computed as the sum of the squared signal sample values and\r
+   the 23/22 sample segment with the lowest power is excluded from the\r
+   start state. One bit is transmitted to indicate which of the 2\r
+   possible 57/58 sample segments is used. The start state position\r
+   within the 2 sub-frames determined above, state_first, MUST be\r
+   encoded as:\r
+   \r
+         state_first=1: start state is first STATE_SHORT_LEN samples\r
+         state_first=0: start state is last STATE_SHORT_LEN samples\r
+\r
+\r
+ 3.5.2 All-Pass Filtering and Scale Quantization\r
+   \r
+   The block of residual samples in the start state is first filtered\r
+   by an all-pass filter with the quantized LPC coefficients as\r
+   denominator and reversed quantized LPC coefficients as numerator.\r
+   The purpose of this phase-dispersion filter is to get a more even\r
+   distribution of the sample values in the residual signal. The\r
+   filtering is performed by circular convolution, where the initial\r
+   filter memory is set to zero.\r
+   \r
+      res(0..(STATE_SHORT_LEN-1))   = uncoded start state residual\r
+      res((STATE_SHORT_LEN)..(2*STATE_SHORT_LEN-1)) = 0\r
+   \r
+      Pk(z) = A~rk(z)/A~k(z), where\r
+                                   ___\r
+                                   \\r
+      A~rk(z)= z^(-LPC_FILTERORDER)+>a~k(i+1)*z^(i-(LPC_FILTERORDER-1))\r
+\r
+\r
+                                   /__\r
+                               i=0...(LPC_FILTERORDER-1)\r
+   \r
+      and A~k(z) is taken from the block where the start state begins\r
+   \r
+      res -> Pk(z) -> filtered\r
+   \r
+      ccres(k) = filtered(k) + filtered(k+STATE_SHORT_LEN), \r
+                                        k=0..(STATE_SHORT_LEN-1)\r
+   \r
+   The all pass filtered block is searched for its largest magnitude\r
+   sample. The 10-logarithm of this magnitude is quantized with a 6-bit\r
+   quantizer, state_frgqTbl, by finding the nearest representation.\r
+   This results in an index, idxForMax, corresponding to a quantized\r
+   value, qmax. The all-pass filtered residual samples in the block are\r
+   then multiplied with a scaling factor scal=4.5/(10^qmax) to yield\r
+   normalized samples.\r
+   \r
+   state_frgqTbl[64] = {1.000085, 1.071695, 1.140395, 1.206868,\r
+                  1.277188, 1.351503, 1.429380, 1.500727, 1.569049,\r
+                  1.639599, 1.707071, 1.781531, 1.840799, 1.901550,\r
+                  1.956695, 2.006750, 2.055474, 2.102787, 2.142819,\r
+                  2.183592, 2.217962, 2.257177, 2.295739, 2.332967,\r
+                  2.369248, 2.402792, 2.435080, 2.468598, 2.503394,\r
+                  2.539284, 2.572944, 2.605036, 2.636331, 2.668939,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     16\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                  2.698780, 2.729101, 2.759786, 2.789834, 2.818679,\r
+                  2.848074, 2.877470, 2.906899, 2.936655, 2.967804,\r
+                  3.000115, 3.033367, 3.066355, 3.104231, 3.141499,\r
+                  3.183012, 3.222952, 3.265433, 3.308441, 3.350823,\r
+                  3.395275, 3.442793, 3.490801, 3.542514, 3.604064,\r
+                  3.666050, 3.740994, 3.830749, 3.938770, 4.101764}\r
+\r
+\r
+ 3.5.3 Scalar Quantization\r
+\r
+\r
+   The normalized samples are quantized in the perceptually weighted\r
+   speech domain by a sample-by-sample scalar DPCM quantization as\r
+   depicted in Figure 3.3. Each sample in the block is filtered by a\r
+   weighting filter Wk(z), specified in section 3.4, to form a weighted\r
+   speech sample x[n]. The target sample d[n] is formed by subtracting\r
+   a predicted sample y[n], where the prediction filter is given by\r
+   \r
+           Pk(z) = 1 - 1 / Wk(z).\r
+   \r
+               +-------+  x[n] +    d[n] +-----------+ u[n]\r
+   residual -->| Wk(z) |-------->(+)---->| Quantizer |------> quantized\r
+               +-------+       - /|\     +-----------+    |   residual\r
+                                  |                      \|/\r
+                             y[n] +--------------------->(+)\r
+                                  |                       |\r
+                                  |        +------+       |\r
+                                  +--------| Pk(z)|<------+\r
+                                           +------+\r
+   \r
+   Figure 3.3. Quantization of start state samples by DPCM in weighted\r
+   speech domain.\r
+   \r
+   The coded state sample u[n] is obtained by quantizing d[n] with a 3-\r
+   bit quantizer with quantization table state_sq3Tbl.\r
+   \r
+   state_sq3Tbl[8] = {-3.719849, -2.177490, -1.130005, -0.309692,\r
+                  0.444214, 1.329712, 2.436279, 3.983887}\r
+   \r
+   The quantized samples are transformed back to the residual domain by\r
+   1) scaling with 1/scal 2) time-reversing the scaled samples 3)\r
+   filtering the time-reversed samples by the same all-pass filter as\r
+   in section 3.5.2, using circular convolution 4) time-reversing the\r
+   filtered samples. (More detailed in section 4.2)\r
+   \r
+   A reference implementation of the start state encoding can be found\r
+   in Appendix A.46.\r
+\r
+\r
+3.6 Encoding the remaining samples\r
+   \r
+   A dynamic codebook is used to encode 1) the 23/22 remaining samples\r
+   in the 2 sub-blocks containing the start state; 2) encoding of the\r
+   sub-blocks after the start state in time; 3) encoding of the sub-\r
+   blocks before the start state in time. Thus, the encoding target can\r
+   be either the 23/22 samples remaining of the 2 sub-blocks containing\r
+   the start state or a 40 sample sub-block. This target can consist of\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     17\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   samples that are indexed forwards in time or backwards in time\r
+   depending on the location of the start state. The length of the\r
+   target is denoted by lTarget.\r
+   \r
+   The coding is based on an adaptive codebook that is built from a\r
+   codebook memory which contains decoded LPC excitation samples from\r
+   the already encoded part of the block. These samples are indexed in\r
+   the same time direction as the target vector and ending at the\r
+   sample instant prior to the first sample instant represented in the\r
+   target vector. The codebook memory has length lMem which is equal to\r
+   CB_MEML=147 for the two/four 40 sample sub-blocks and 85 for the\r
+   23/22 sample sub-block.\r
+   \r
+   The following figure shows an overview of the encoding procedure.\r
+   \r
+            +------------+    +---------------+    +-------------+\r
+         -> | 1. Decode  | -> | 2. Mem setup  | -> | 3. Perc. W. | ->\r
+            +------------+    +---------------+    +-------------+\r
+   \r
+            +------------+    +-----------------+    \r
+         -> | 4. Search  | -> | 5. Upd. Target  | ------------------> \r
+          | +------------+    +------------------ |  \r
+          ----<-------------<-----------<----------\r
+                        stage=0..2\r
+   \r
+            +----------------+\r
+         -> | 6. Recalc G[0] | ---------------> gains and CB indices\r
+            +----------------+\r
+   \r
+   Figure 3.4. Flow chart of the codebook search in the iLBC encoder\r
+\r
+\r
+   1. Decode the part of the residual that has been encoded so far,\r
+   using the codebook without perceptual weighting\r
+   2. Set up the memory by taking data from the decoded residual. This\r
+   memory is used to construct codebooks from. For blocks preceding the\r
+   start state, both the decoded residual and the target are time\r
+   reversed (section 3.6.1)\r
+   3. Filter the memory + target with the perceptual weighting filter\r
+   (section 3.6.2)\r
+   4. Search for the best match between the target and the codebook\r
+   vector. Compute the optimal gain for this match and quantize that\r
+   gain (section 3.6.4)\r
+   5. Update the perceptually weighted target by subtracting the\r
+   contribution from the selected codebook vector from the perceptually\r
+   weighted memory (quantized gain times selected vector). Repeat 4.\r
+   and 5. for the 2 additional stages\r
+   6. Calculate the energy loss due to encoding of the residual. If\r
+   needed, compensate for this loss by an upscaling and requantization\r
+   of the gain for the first stage (section 3.7)\r
+   \r
+   The following sections provide an in-depth description of the\r
+   different blocks of figure 3.4.\r
+   \r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     18\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+ 3.6.1 Codebook Memory\r
+   \r
+   The codebook memory is based on the already encoded sub-blocks so\r
+   the available data for encoding increases for each new sub-block\r
+   that has been encoded. Until enough sub-blocks have been encoded to\r
+   fill the codebook memory with data it is padded with zeros. The\r
+   following figure shows an example of the order in which the sub-\r
+   blocks are encoded for the 30 ms frame size if the start state is\r
+   located in the last 58 samples of sub-block 2 and 3.\r
+   \r
+   +-----------------------------------------------------+\r
+   |  5     | 1  |///|////////|    2   |    3   |    4   |\r
+   +-----------------------------------------------------+\r
+   \r
+   Figure 3.5. The order from 1 to 5 in which the sub-blocks are\r
+   encoded. The slashed area is the start state.\r
+   \r
+   The first target sub-block to be encoded is number 1 and the\r
+   corresponding codebook memory is shown in the following figure.\r
+   Since the target vector is before the start state in time the\r
+   codebook memory and target vector are time reversed. By reversing\r
+   them in time, the search algorithm can be reused. Since only the\r
+   start state has been encoded so far the last samples of the codebook\r
+   memory are padded with zeros.\r
+   \r
+   +-------------------------\r
+   |zeros|\\\\\\\\|\\\\|  1 |\r
+   +-------------------------\r
+   \r
+   Figure 3.6. The codebook memory, length lMem=85 samples, and the\r
+   target vector 1, length 22 samples.\r
+   \r
+   The next step is to encode sub-block 2 using the memory which now\r
+   has increased since sub-block 1 has been encoded. The following\r
+   figure shows the codebook memory for encoding of sub-block 2.\r
+   \r
+   +-----------------------------------\r
+   | zeros | 1  |///|////////|    2   |\r
+   +-----------------------------------\r
+\r
+\r
+   Figure 3.7. The codebook memory, length lMem=147 samples, and the\r
+   target vector 2, length 40 samples.\r
+   \r
+   The next step is to encode sub-block 3 using the memory which now\r
+   has increased yet again since sub-blocks 1 and 2 have been encoded\r
+   but it still has to be padded with a few zeros. The following figure\r
+   shows the codebook memory for encoding of sub-block 3.\r
+   \r
+   +------------------------------------------\r
+   |zeros| 1  |///|////////|    2   |   3    |\r
+   +------------------------------------------\r
+   \r
+   Figure 3.8. The codebook memory, length lMem=147 samples, and the\r
+   target vector 3, length 40 samples.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     19\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   The next step is to encode sub-block 4 using the memory which now\r
+   has increased yet again since sub-blocks 1, 2 and 3 have been\r
+   encoded. This time the memory does not have to be padded with zeros.\r
+   The following figure shows the codebook memory for encoding of sub-\r
+   block 4.\r
+   \r
+   +------------------------------------------\r
+   |1|///|////////|    2   |   3    |   4    |\r
+   +------------------------------------------\r
+   \r
+   Figure 3.9. The codebook memory, length lMem=147 samples, and the\r
+   target vector 4, length 40 samples.\r
+   \r
+   The final target sub-block to be encoded is number 5 and the\r
+   corresponding codebook memory is shown in the following figure.\r
+   Since the target vector is before the start state in time the\r
+   codebook memory and target vector are time reversed.\r
+   \r
+   +-------------------------------------------\r
+   |  3  |   2    |\\\\\\\\|\\\\|  1 |   5    |\r
+   +-------------------------------------------\r
+   \r
+   Figure 3.10. The codebook memory, length lMem=147 samples, and the\r
+   target vector 5, length 40 samples.\r
+   \r
+   For the case of 20 ms frames the encoding procedure looks almost\r
+   exactly the same. The only difference is that the size of the start\r
+   state is 57 samples and that there are only 3 sub-blocks to be\r
+   encoded. The encoding order is the same as above starting with the\r
+   23 sample target and then encoding the two remaining 40 sample sub-\r
+   blocks, first going forward in time and then going backwards in time\r
+   relative to the start state.\r
+   \r
+ 3.6.2 Perceptual Weighting of Codebook Memory and Target\r
+   \r
+   To provide a perceptual weighting of the coding error, a\r
+   concatenation of the codebook memory and the target to be coded is\r
+   all pole filtered with the perceptual weighting filter specified in\r
+   section 3.4. The filter state of the weighting filter is set to\r
+   zero.\r
+   \r
+      in(0..(lMem-1))            = unweighted codebook memory\r
+      in(lMem..(lMem+lTarget-1)) = unweighted target signal\r
+\r
+\r
+      in -> Wk(z) -> filtered, \r
+          where Wk(z) is taken from the sub-block of the target\r
+   \r
+      weighted codebook memory = filtered(0..(lMem-1))\r
+      weighted target signal = filtered(lMem..(lMem+lTarget-1))\r
+   \r
+   The codebook search is done using the weighted codebook memory and\r
+   the weighted target, while the decoding and the codebook memory\r
+   update uses the unweighted codebook memory.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     20\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+\r
+\r
+ 3.6.3 Codebook Creation\r
+   \r
+   The codebook for the search is created from the perceptually\r
+   weighted codebook memory. It consists of two sections where the\r
+   first is referred to as the base codebook and the second as the\r
+   expanded codebook since it is created by linear combinations of the\r
+   first. Each of these two sections also has a subsection referred to\r
+   as the augmented codebook. The augmented codebook is only created\r
+   and used for the coding of the 40 sample sub-blocks and not for the\r
+   23/22 sample sub-block case. The codebook size used for the\r
+   different sub-blocks and different stages are summarized in the\r
+   table below.\r
+   \r
+                              Stage\r
+                        1               2 & 3\r
+           --------------------------------------------\r
+                22     128  (64+0)*2     128 (64+0)*2\r
+   Sub-    1:st 40     256  (108+20)*2   128 (44+20)*2\r
+   Blocks  2:nd 40     256  (108+20)*2   256 (108+20)*2\r
+           3:rd 40     256  (108+20)*2   256 (108+20)*2\r
+           4:th 40     256  (108+20)*2   256 (108+20)*2\r
+   \r
+   Table 3.1. Codebook sizes for the 30 ms mode\r
+   \r
+   The table 3.1 shows the codebook size for the different sub-blocks\r
+   and stages for 30 ms frames. Inside the parenthesis it shows how the\r
+   number of codebook vectors is distributed, within the two sections,\r
+   between the base/expanded codebook and the augmented base/expanded\r
+   codebook. It should be interpreted in the following way:\r
+   (base/expanded cb + augmented base/expanded cb). The total number of\r
+   codebook vectors for a specific sub-block and stage is given by the\r
+   following formula:\r
+   \r
+   Tot. cb vectors = base cb + aug. base cb + exp. cb + aug. exp. cb\r
+   \r
+   The corresponding values to figure 3.1 for 20 ms frames are only\r
+   slightly modified. The short sub-block is 23 instead of 22 samples\r
+   and the 3:rd and 4:th sub-frame are not present.\r
+\r
+\r
+ 3.6.3.1 Creation of a Base Codebook\r
+   \r
+   The base codebook is given by the perceptually weighted codebook\r
+   memory that is mentioned in section 3.5.3. The different codebook\r
+   vectors are given by sliding a window of length 23/22 or 40, given\r
+   by variable lTarget, over the lMem long perceptually weighted\r
+   codebook memory. The indices are ordered so that the codebook vector\r
+   containing sample(lMem-lTarget-n) to (lMem-n-1) of the codebook\r
+   memory vector has index n, where n=0..lMem-lTarget. Thus the total\r
+   number of base codebook vectors is lMem-lTarget+1 and the indices\r
+   are ordered from sample delay lTarget (23/22 or 40) to lMem+1 (86 or\r
+   148).\r
+   \r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     21\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+ 3.6.3.2 Codebook Expansion\r
+   \r
+   The base codebook is expanded by a factor of 2, creating an\r
+   additional section in the codebook. This new section is obtained by\r
+   filtering the base codebook, base_cb, with a FIR filter with filter\r
+   length CB_FILTERLEN=8. The delay of four samples introduced by the\r
+   FIR filter is compensated for in the construction of the expanded\r
+   codebook.\r
+   \r
+   cbfiltersTbl[CB_FILTERLEN]={-0.033691, 0.083740, -0.144043, \r
+                  0.713379, 0.806152, -0.184326, \r
+                  0.108887, -0.034180};\r
+   \r
+                   ___\r
+                   \\r
+      exp_cb(k)=  + > cbfiltersTbl(i)*x(k-i+4)\r
+                   /__\r
+             i=0...(LPC_FILTERORDER-1)\r
+   \r
+      where x(j) = base_cb(j) for j=0..lMem-1 and 0 otherwise\r
+   \r
+   The individual codebook vectors of the new filtered codebook,\r
+   exp_cb, and their indices are obtained in the same fashion as\r
+   described above for the base codebook.\r
+\r
+\r
+ 3.6.3.3 Codebook Augmentation\r
+   \r
+   For the cases when encoding entire sub-blocks, i.e. cbveclen=40, the\r
+\r
+\r
+   base and expanded codebooks are augmented to increase codebook\r
+   richness. The codebooks are augmented by vectors produced by\r
+   interpolation of segments. The base and expanded codebook,\r
+   constructed above, consists of vectors corresponding to sample\r
+   delays in the range from cbveclen to lMem. The codebook augmentation\r
+   attempts to augment these codebooks with vectors corresponding to\r
+   sample delays from 20 to 39. However, not all of these samples are\r
+   present in the base codebook and expanded codebook respectively.\r
+   Therefore, the augmentation vectors are constructed as linear\r
+   combinations between samples corresponding to sample delays in the\r
+   range 20 to 39. The general idea of this procedure is presented in\r
+   the following figures and text. The procedure is performed for both\r
+   the base codebook and the expanded codebook.\r
+   \r
+       - - ------------------------|\r
+    codebook memory                |\r
+       - - ------------------------|\r
+                  |-5-|---15---|-5-|\r
+                  pi  pp       po\r
+   \r
+                      |        |                       Codebook vector\r
+                      |---15---|-5-|-----20-----|   <- corresponding to\r
+                          i     ii      iii            sample delay 20\r
+   \r
+   Figure 3.11. Generation of the first augmented codebook\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     22\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   The figure 3.11 shows the codebook memory with pointers pi, pp and\r
+   po where pi points to sample 25, pp to sample 20 and po to sample 5.\r
+   Below the codebook memory, the augmented codebook vector\r
+   corresponding to sample delay 20 is drawn. Segment i consists of 15\r
+   samples from pointer pp and forward in time. Segment ii consists of\r
+   5 interpolated samples from pi and forward and from po and forward.\r
+   The samples are linearly interpolated with weights [0.0, 0.2, 0.4,\r
+   0.6, 0.8] for pi and weights [1.0, 0.8, 0.6, 0.4, 0.2] for po.\r
+   Segment iii consists of 20 samples from pp and forward. The\r
+   augmented codebook vector corresponding to sample delay 21 is\r
+   produced by moving pointers pp and pi one sample backwards in time.\r
+   That gives us the following figure.\r
+   \r
+       - - ------------------------|\r
+    codebook memory                |\r
+       - - ------------------------|\r
+                  |-5-|---16---|-5-|\r
+                  pi  pp       po\r
+   \r
+                      |        |                       Codebook vector\r
+                      |---16---|-5-|-----19-----|   <- corresponding to\r
+                          i     ii      iii            sample delay 21\r
+   \r
+   Figure 3.12. Generation of the second augmented codebook\r
+   \r
+   The figure 3.12 shows the codebook memory with pointers pi, pp and\r
+   po where pi points to sample 26, pp to sample 21 and po to sample 5.\r
+   Below the codebook memory, the augmented codebook vector\r
+   corresponding to sample delay 21 is drawn. Segment i does now\r
+   consist of 16 samples from pp and forward. Segment ii consists of 5\r
+   interpolated samples from pi and forward and po and forward and the\r
+   interpolation weights are the same throughout the procedure. Segment\r
+   iii consists of 19 samples from pp and forward. The same procedure\r
+   of moving the two pointers is continued until the last augmented\r
+   vector corresponding to sample delay 39 has been created. This gives\r
+   a total of 20 new codebook vectors to each of the two sections. Thus\r
+   the total number of codebook vectors for each of the two sections,\r
+   when including the augmented codebook becomes lMem-SUBL+1+SUBL/2.\r
+   This is provided that augmentation is evoked, i.e., that\r
+   lTarget=SUBL.\r
+\r
+\r
+ 3.6.4 Codebook Search\r
+   \r
+   The codebook search uses the codebooks described in the sections\r
+   above to find the best match of the perceptually weighted target,\r
+   see section 3.6.2. The search method is a multi-stage gain-shape\r
+   matching performed as follows. At each stage the best shape vector\r
+   is identified, then the gain is calculated and quantized, and\r
+   finally the target is updated in preparation for the next codebook\r
+   search stage. The number of stages is CB_NSTAGES=3.\r
+   \r
+   If the target is the 23/22 sample vector the codebooks are indexed\r
+   in the order: base codebook followed by the expanded codebook. If\r
+   the target is 40 samples the order is: base codebook, augmented base\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     23\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   codebook, expanded codebook and finally augmented expanded codebook.\r
+   The size of each codebook section and its corresponding augmented\r
+   section is given by table 3.1 in section 3.6.3.\r
+   \r
+   For example when coding the second 40 sample sub-block indices 0-107\r
+   correspond to the base codebook, 108-127 correspond to the augmented\r
+   base codebook, 128-235 correspond to the expanded codebook and\r
+   finally indices 236-255 correspond to the augmented expanded\r
+   codebook. The indices are divided in the same fashion for all stages\r
+   in the example. Only in the case of coding the first 40 sample sub-\r
+   block is there a difference between stages (see Table 3.1).\r
+\r
+\r
+ 3.6.4.1 Codebook Search at Each Stage\r
+   \r
+   The codebooks are searched to find the best match to the target at\r
+   each stage. When the best match is found the target is updated and\r
+   the next-stage search is started. The three chosen codebook vectors\r
+   and their corresponding gains constitute the encoded sub-block. The\r
+   best match is decided by the following three criteria:\r
+   \r
+   1. Compute the measure\r
+   \r
+         (target*cbvec)^2 / ||cbvec||^2\r
+   \r
+   for all codebook vectors, cbvec, and choose the codebook vector\r
+   maximizing the measure. The expression (target*cbvec) is the dot\r
+   product between the target vector to be coded and the codebook\r
+   vector for which we compute the measure. The norm, ||x||, is defined\r
+   as the square root of (x*x).\r
+   \r
+   2. The absolute value of the gain, corresponding to the chosen\r
+   codebook vector, cbvec, must be smaller than a fixed limit,\r
+   CB_MAXGAIN=1.3:\r
+   \r
+         |gain| < CB_MAXGAIN\r
+   \r
+   where the gain is computed in the following way:\r
+   \r
+         gain = (target*cbvec) / ||cbvec||^2\r
+   \r
+   3. For the first stage the dot product of the chosen codebook vector\r
+   and target must be positive:\r
+   \r
+         target*cbvec > 0\r
+   \r
+   In practice the above criteria are used in a sequential search\r
+   through all codebook vectors. The best match is found by registering\r
+   a new max measure and index whenever the previously registered max\r
+   measure is surpassed and all other criteria are fulfilled. If none\r
+   of the codebook vectors fulfill (2) and (3), the first codebook\r
+   vector is selected.\r
+\r
+\r
+ 3.6.4.2 Gain Quantization at Each Stage\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     24\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   The gain follows as a result of the computation:\r
+   \r
+           gain = (target*cbvec) / ||cbvec||^2\r
+   \r
+   for the optimal codebook vector that was found by the procedure from\r
+   section 3.6.4.1.\r
+   \r
+   The three stages quantize the gain using 5, 4 and 3 bits\r
+   respectively. In the first stage, the gain is limited to positive\r
+   values. This gain is quantized by finding the nearest value in the\r
+   quantization table gain_sq5Tbl.\r
+   \r
+   gain_sq5Tbl[32]={0.037476, 0.075012, 0.112488, 0.150024, 0.187500, \r
+                  0.224976, 0.262512, 0.299988, 0.337524, 0.375000,\r
+                  0.412476, 0.450012, 0.487488, 0.525024, 0.562500,\r
+                  0.599976, 0.637512, 0.674988, 0.712524, 0.750000,\r
+                  0.787476, 0.825012, 0.862488, 0.900024, 0.937500,\r
+                  0.974976, 1.012512, 1.049988, 1.087524, 1.125000,\r
+                  1.162476, 1.200012}\r
+   \r
+   The gains of the subsequent two stages can be either positive or\r
+   negative. The gains are quantized using a quantization table times a\r
+   scale factor. The second stage uses the table gain_sq4Tbl and the\r
+   third stage uses gain_sq3Tbl. The scale factor equates 0.1 or the\r
+   absolute value of the quantized gain representation value obtained\r
+   in the previous stage, whichever is the larger. Again, the resulting\r
+   gain index is the index to the nearest value of the quantization\r
+   table times the scale factor.\r
+   \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     25\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+        gainQ = scaleFact * gain_sqXTbl[index]\r
+   \r
+   gain_sq4Tbl[16]={-1.049988, -0.900024, -0.750000, -0.599976, \r
+                  -0.450012, -0.299988, -0.150024, 0.000000, 0.150024,\r
+                  0.299988, 0.450012, 0.599976, 0.750000, 0.900024,\r
+                  1.049988, 1.200012}\r
+   \r
+   gain_sq3Tbl[8]={-1.000000, -0.659973, -0.330017,0.000000,\r
+                  0.250000, 0.500000, 0.750000, 1.00000}\r
+\r
+\r
+ 3.6.4.3 Preparation of Target for Next Stage\r
+   \r
+   Before performing the search for the next stage the perceptually\r
+   weighted target vector is updated by subtracting from it the\r
+   selected codebook vector (from the perceptually weighted codebook)\r
+   times the corresponding quantized gain.\r
+   \r
+        target[i] = target[i] - gainQ * selected_vec[i];\r
+   \r
+   A reference implementation of the codebook encoding is found in\r
+   Appendix A.34.\r
+\r
+\r
+3.7 Gain Correction Encoding\r
+   \r
+   The start state is quantized in a relatively model independent\r
+   manner using 3 bits per sample. In contrast to this, the remaining\r
+   parts of the block is encoded using an adaptive codebook. This\r
+   codebook will produce high matching accuracy whenever there is a\r
+   high correlation between the target and the best codebook vector.\r
+   For unvoiced speech segments and background noises, this is not\r
+   necessarily so, which, due to the nature of the squared error\r
+   criterion, results in a coded signal with less power than the target\r
+   signal. As the coded start state has good power matching to the\r
+   target, the result is a power fluctuation within the encoded frame.\r
+   Perceptually, the main problem with this is that the time envelope\r
+   of the signal energy becomes unsteady. To overcome this problem, the\r
+   gains for the codebooks are re-scaled after the codebook encoding by\r
+   searching for a new gain factor for the first stage codebook that\r
+   provides better power matching.\r
+   \r
+   First the energy for the target signal, tene, is computed along with\r
+   the energy for the coded signal, cene, given by the addition of the\r
+   3 gain scaled codebook vectors. Since the gains of the 2nd and 3rd\r
+   stage scale with the gain of the first stage, by changing the first\r
+   stage gain from gain[0] to gain_sq5Tbl[i], the energy of the coded\r
+   signal changes from cene to\r
+         \r
+         cene*(gain_sq5Tbl[i]*gain_sq5Tbl[i])/(gain[0]*gain[0])\r
+         \r
+   where gain[0] is the gain for the first stage found in the original\r
+   codebook search. A refined search is performed by testing the gain\r
+   indices i=0 to 31, and as long as the new codebook energy as given\r
+   above is less than tene, the gain index for stage 1 is increased. A\r
+   restriction is applied so that the new gain value for stage 1 cannot\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     26\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   be more than 2 times higher than the original value found in the\r
+   codebook search. Note that by using this method the shape of the\r
+   encoded vector is not changed, only the gain or amplitude.\r
+\r
+\r
+3.8 Bitstream Definition\r
+   \r
+   The total number of bits used to describe one frame of 20 ms speech\r
+   is 304, which fits in 38 bytes and results in a bit rate of 15.20\r
+   kbit/s. For the case with a frame length of 30 ms speech the total\r
+   number of bits used is 400, which fits in 50 bytes and results in a\r
+   bit rate of 13.33 kbit/s. In the bitstream definition the bits are\r
+   distributed into three classes according to their bit error or loss\r
+   sensitivity. The most sensitive bits (class 1) are placed first in\r
+   the bitstream for each frame. The less sensitive bits (class 2) are\r
+   placed after the class 1 bits. The least sensitive bits (class 3)\r
+   are placed at the end of the bitstream for each frame.\r
+   \r
+   Looking at the 20/30 ms frame length cases for each class: The class\r
+   1 bits occupy a total of 6/8 bytes (48/64 bits), the class 2 bits\r
+   occupy 8/12 bytes (64/96 bits), and the class 3 bits occupy 24/30\r
+   bytes (191/239 bits). This distribution of the bits enable the use\r
+   of uneven level protection (ULP) as is exploited in the payload\r
+   format definition for iLBC [1]. The detailed bit allocation is shown\r
+   in the table below. When a quantization index is distributed between\r
+   more classes the more significant bits belong to the lowest class.\r
+   \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     27\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   Bitstream structure:\r
+   \r
+   ------------------------------------------------------------------+\r
+   Parameter                         |       Bits Class <1,2,3>      |\r
+                                     |  20 ms frame  |  30 ms frame  |\r
+   ----------------------------------+---------------+---------------+\r
+                            Split 1  |   6 <6,0,0>   |   6 <6,0,0>   |\r
+                   LSF 1    Split 2  |   7 <7,0,0>   |   7 <7,0,0>   |\r
+   LSF                      Split 3  |   7 <7,0,0>   |   7 <7,0,0>   |\r
+                   ------------------+---------------+---------------+\r
+                            Split 1  | NA (Not Appl.)|   6 <6,0,0>   |\r
+                   LSF 2    Split 2  |      NA       |   7 <7,0,0>   |\r
+                            Split 3  |      NA       |   7 <7,0,0>   |\r
+                   ------------------+---------------+---------------+\r
+                   Sum               |  20 <20,0,0>  |  40 <40,0,0>  |\r
+   ----------------------------------+---------------+---------------+\r
+   Block Class.                      |   2 <2,0,0>   |   3 <3,0,0>   |\r
+   ----------------------------------+---------------+---------------+\r
+   Position 22 sample segment        |   1 <1,0,0>   |   1 <1,0,0>   |\r
+   ----------------------------------+---------------+---------------+\r
+   Scale Factor State Coder          |   6 <6,0,0>   |   6 <6,0,0>   |\r
+   ----------------------------------+---------------+---------------+\r
+                   Sample 0          |   3 <0,1,2>   |   3 <0,1,2>   |\r
+   Quantized       Sample 1          |   3 <0,1,2>   |   3 <0,1,2>   |\r
+   Residual           :              |   :    :      |   :    :      |\r
+   State              :              |   :    :      |   :    :      |\r
+   Samples            :              |   :    :      |   :    :      |\r
+                   Sample 56         |   3 <0,1,2>   |   3 <0,1,2>   |\r
+                   Sample 57         |      NA       |   3 <0,1,2>   |\r
+                   ------------------+---------------+---------------+\r
+                   Sum               | 171 <0,57,114>| 174 <0,58,116>|\r
+   ----------------------------------+---------------+---------------+\r
+                            Stage 1  |   7 <6,0,1>   |   7 <4,2,1>   |\r
+   CB for 22/23             Stage 2  |   7 <0,0,7>   |   7 <0,0,7>   |\r
+   sample block             Stage 3  |   7 <0,0,7>   |   7 <0,0,7>   |\r
+                   ------------------+---------------+---------------+\r
+                   Sum               |  21 <6,0,15>  |  21 <4,2,15>  |\r
+   ----------------------------------+---------------+---------------+\r
+                            Stage 1  |   5 <2,0,3>   |   5 <1,1,3>   |\r
+   Gain for 22/23           Stage 2  |   4 <1,1,2>   |   4 <1,1,2>   |\r
+   sample block             Stage 3  |   3 <0,0,3>   |   3 <0,0,3>   |\r
+                   ------------------+---------------+---------------+\r
+                   Sum               |  12 <3,1,8>   |  12 <2,2,8>   |\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     28\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   ----------------------------------+---------------+---------------+\r
+                            Stage 1  |   8 <7,0,1>   |   8 <6,1,1>   |\r
+               sub-block 1  Stage 2  |   7 <0,0,7>   |   7 <0,0,7>   |\r
+                            Stage 3  |   7 <0,0,7>   |   7 <0,0,7>   |\r
+                   ------------------+---------------+---------------+\r
+                            Stage 1  |   8 <0,0,8>   |   8 <0,7,1>   |\r
+               sub-block 2  Stage 2  |   8 <0,0,8>   |   8 <0,0,8>   |\r
+   Indices                  Stage 3  |   8 <0,0,8>   |   8 <0,0,8>   |\r
+   for CB          ------------------+---------------+---------------+\r
+   sub-blocks               Stage 1  |      NA       |   8 <0,7,1>   |\r
+               sub-block 3  Stage 2  |      NA       |   8 <0,0,8>   |\r
+                            Stage 3  |      NA       |   8 <0,0,8>   |\r
+                   ------------------+---------------+---------------+\r
+                            Stage 1  |      NA       |   8 <0,7,1>   |\r
+               sub-block 4  Stage 2  |      NA       |   8 <0,0,8>   |\r
+                            Stage 3  |      NA       |   8 <0,0,8>   |\r
+                   ------------------+---------------+---------------+\r
+                   Sum               |  46 <7,0,39>  |  94 <6,22,66> |\r
+   ----------------------------------+---------------+---------------+\r
+                            Stage 1  |   5 <1,2,2>   |   5 <1,2,2>   |\r
+               sub-block 1  Stage 2  |   4 <1,1,2>   |   4 <1,2,1>   |\r
+                            Stage 3  |   3 <0,0,3>   |   3 <0,0,3>   |\r
+                   ------------------+---------------+---------------+\r
+                            Stage 1  |   5 <1,1,3>   |   5 <0,2,3>   |\r
+               sub-block 2  Stage 2  |   4 <0,2,2>   |   4 <0,2,2>   |\r
+                            Stage 3  |   3 <0,0,3>   |   3 <0,0,3>   |\r
+   Gains for       ------------------+---------------+---------------+\r
+   sub-blocks               Stage 1  |      NA       |   5 <0,1,4>   |\r
+               sub-block 3  Stage 2  |      NA       |   4 <0,1,3>   |\r
+                            Stage 3  |      NA       |   3 <0,0,3>   |\r
+                   ------------------+---------------+---------------+\r
+                            Stage 1  |      NA       |   5 <0,1,4>   |\r
+               sub-block 4  Stage 2  |      NA       |   4 <0,1,3>   |\r
+                            Stage 3  |      NA       |   3 <0,0,3>   |\r
+                   ------------------+---------------+---------------+\r
+                   Sum               |  24 <3,6,15>  |  48 <2,12,34> |\r
+   ----------------------------------+---------------+---------------+\r
+   Empty frame indicator             |   1 <0,0,1>   |   1 <0,0,1>   |\r
+   -------------------------------------------------------------------\r
+   SUM                                 304 <48,64,192> 400 <64,96,240>\r
+   \r
+   Table 3.2. The bitstream definition for iLBC for both the 20 ms\r
+   frame size mode and the 30 ms frame size mode. \r
+   \r
+   When packetized into the payload the bits MUST be sorted as: All the\r
+   class 1 bits in the order (from top to bottom) as they were\r
+   specified in the table, all the class 2 bits (from top to bottom)\r
+   and finally all the class 3 bits in the same sequential order. \r
+   The last bit, the empty frame indicator, SHOULD be set to zero by\r
+   the encoder. If this bit is set to one the decoder SHOULD treat the\r
+   data as a lost frame. For example this bit can be set to 1 to\r
+   indicate lost frame for file storage format as in [1].\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     29\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+4. DECODER PRINCIPLES\r
+   \r
+   This section describes the principles of each component of the\r
+   decoder algorithm.\r
+   \r
+               +-------------+    +--------+    +---------------+\r
+    payload -> | 1. Get para | -> | 2. LPC | -> | 3. Sc Dequant | ->\r
+               +-------------+    +--------+    +---------------+\r
+   \r
+               +-------------+    +------------------+\r
+            -> | 4 Mem setup | -> | 5. Construct res |------->\r
+            |  +-------------+    +-------------------   |\r
+            ---------<-----------<-----------<------------\r
+                      Sub-frame 0...2/4 (20 ms/30 ms)\r
+   \r
+               +----------------+    +----------+\r
+            -> | 6. Enhance res | -> | 7. Synth | ------------>\r
+               +----------------+    +----------+\r
+   \r
+               +-----------------+\r
+            -> | 8. Post Process | ----------------> decoded speech\r
+               +-----------------+\r
+   \r
+   Figure 4.1. Flow chart of the iLBC decoder. If a frame was lost\r
+   steps 1 to 5 SHOULD be replaced by a PLC algorithm.\r
+   \r
+   1. Extract the parameters from the bitstream\r
+   2. Decode the LPC and interpolate (section 4.1)\r
+   3. Construct the 57/58 sample start state (section 4.2)\r
+   4. Set up the memory using data from the decoded residual. This\r
+   memory is used for codebook construction. For blocks preceding the\r
+   start state, both the decoded residual and the target are time\r
+   reversed. Sub-frames are decoded in the same order as they were\r
+   encoded\r
+   5. Construct the residuals of this sub-frame (gain[0]*cbvec[0] +\r
+   gain[1]*cbvec[1] + gain[2]*cbvec[2]). Repeat 4 and 5 until the\r
+   residual of all sub-blocks have been constructed\r
+   6. Enhance the residual with the post filter (section 4.6)\r
+   7. Synthesis of the residual (section 4.7)\r
+   8. Post process with HP filter if desired (section 4.8)\r
+   \r
+4.1 LPC Filter Reconstruction\r
+   \r
+   The decoding of the LP filter parameters is very straightforward.\r
+   For a set of three/six indices the corresponding LSF vector(s) are\r
+   found by simple table look up. For each of the LSF vectors the three\r
+   split vectors are concatenated to obtain qlsf1 and qlsf2,\r
+   respectively (in the 20 ms mode only one LSF vector, qlsf, is\r
+   constructed). The next step is the stability check described in\r
+   Section 3.2.5 followed by the interpolation scheme described in\r
+   Section 3.2.6 (3.2.7 for 20 ms frames). The only difference is that\r
+   only the quantized LSFs are known at the decoder and hence the\r
+   unquantized LSFs are not processed.\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     30\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   A reference implementation of the LPC filter reconstruction is given\r
+   in Appendix A.36.\r
+\r
+\r
+4.2 Start State Reconstruction\r
+   \r
+   The scalar encoded STATE_SHORT_LEN=58 (STATE_SHORT_LEN=57 in the 2\r
+0\r
+   ms mode) state samples are reconstructed by 1) forming a set of\r
+   samples (by table look-up) from the index stream idxVec[n] 2)\r
+   multiplying the set with 1/scal=(10^qmax)/4.5 3) time reversing the\r
+   57/58 samples 4) filtering the time reversed block with the\r
+   dispersion (all-pass) filter used in the encoder (as described in\r
+   section 3.5.2). This compensates for the phase distortion of the\r
+   earlier filter operation. 5) Reversing the 57/58 samples from the\r
+   previous step\r
+   \r
+      in(0..(STATE_SHORT_LEN-1)) = time reversed samples from table \r
+                                   look-up, \r
+                                   idxVecDec((STATE_SHORT_LEN-1)..0)\r
+   \r
+      in(STATE_SHORT_LEN..(2*STATE_SHORT_LEN-1)) = 0\r
+   \r
+      Pk(z) = A~rk(z)/A~k(z), where\r
+                                     ___\r
+                                     \\r
+      A~rk(z)= z^(-LPC_FILTERORDER) + > a~ki*z^(i-(LPC_FILTERORDER-1))\r
+                                     /__\r
+                                 i=0...(LPC_FILTERORDER-1)\r
+   \r
+      and A~k(z) is taken from the block where the start state begins\r
+   \r
+      in -> Pk(z) -> filtered\r
+   \r
+      out(k) = filtered(STATE_SHORT_LEN-1-k) + \r
+                              filtered(2*STATE_SHORT_LEN-1-k),\r
+                                            k=0..(STATE_SHORT_LEN-1)\r
+   \r
+   The remaining 23/22 samples in the state are reconstructed by the\r
+   same adaptive codebook technique as described in section 4.3. The\r
+   location bit determines whether these are the first or the last\r
+   23/22 samples of the 80 sample state vector. If the remaining 23/22\r
+   samples are the first samples of the state vector, then the scalar\r
+   encoded STATE_SHORT_LEN state samples are time-reversed before\r
+   initialization of the adaptive codebook memory vector.\r
+   \r
+   A reference implementation of the start state reconstruction is\r
+   given in Appendix A.44.\r
+\r
+\r
+4.3 Excitation Decoding Loop\r
+   \r
+   The decoding of the LPC excitation vector proceeds in the same order\r
+   in which the residual was encoded at the encoder. That is, after the\r
+   decoding of the entire 80 sample state vector, the forward sub-\r
+   blocks (corresponding to samples occurring after the state vector\r
+   samples) are decoded, and then the backward sub-blocks\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     31\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (corresponding to samples occurring before the state vector) are\r
+   decoded, resulting in a fully decoded block of excitation signal\r
+   samples.\r
+   \r
+   In particular, each sub-block is decoded using the multistage\r
+   adaptive codebook decoding module which is described in section 4.4.\r
+   This module relies upon an adaptive codebook memory that is\r
+   constructed before each run of the adaptive codebook decoding. The\r
+   construction of the adaptive codebook memory in the decoder is\r
+   identical to the method outlined in section 3.6.3, except that it is\r
+   done on the codebook memory without perceptual weighting.\r
+   \r
+   For the initial forward sub-block, the last STATE_LEN=80 samples of\r
+   the length CB_LMEM=147 adaptive codebook memory are filled with the\r
+   samples of the state vector. For subsequent forward sub-blocks, the\r
+   first SUBL=40 samples of the adaptive codebook memory are discarded,\r
+\r
+\r
+   the remaining samples are shifted by SUBL samples towards the\r
+   beginning of the vector, while the newly decoded SUBL=40 samples are\r
+\r
+\r
+   placed at the end of the adaptive codebook memory. For backward sub-\r
+   blocks, the construction is similar except that every vector of\r
+   samples involved is first time-reversed.\r
+   \r
+   A reference implementation of the excitation decoding loop is found\r
+   in Appendix A.5.\r
+\r
+\r
+4.4 Multistage Adaptive Codebook Decoding\r
+   \r
+   The Multistage Adaptive Codebook Decoding module is used at both the\r
+   sender (encoder) and the receiver (decoder) ends to produce a\r
+   synthetic signal in the residual domain that is eventually used to\r
+   produce synthetic speech. The module takes the index values used to\r
+   construct vectors that are scaled and summed together to produce a\r
+   synthetic signal that is the output of the module.\r
+\r
+\r
+ 4.4.1 Construction of the Decoded Excitation Signal\r
+   \r
+   The unpacked index values provided at the input to the module are\r
+   references to extended codebooks, which are constructed as described\r
+   in Section 3.6.3 with the only difference that it is based on the\r
+   codebook memory without the perceptual weighting. The unpacked 3\r
+   indices are used to look up 3 codebook vectors. The unpacked 3 gain\r
+   indices are used to decode the corresponding 3 gains. In this\r
+   decoding the successive rescaling as described in Section 3.6.4.2 is\r
+   applied.\r
+   \r
+   A reference implementation of the adaptive codebook decoding is\r
+   listed in Appendix A.32.\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     32\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+4.5 Packet Loss Concealment\r
+   \r
+   If packet loss occurs, the decoder receives a signal saying that\r
+   information regarding a block is lost. For such blocks it is\r
+   RECOMMENDED to use a Packet Loss Concealment (PLC) unit to create a\r
+   decoded signal which masks the effect of that packet loss. In the\r
+   following we will describe an example of a PLC unit that can be used\r
+   with the iLBC codec. As the PLC unit is used only at the decoder,\r
+   the PLC unit does not affect interoperability between\r
+   implementations. Other PLC implementations MAY therefore be used.\r
+   \r
+   The example PLC described operates on the LP filters and the\r
+   excitation signals and is based on the following principles:\r
+\r
+\r
+ 4.5.1 Block Received Correctly and Previous Block also Received\r
+   \r
+   If the block is received correctly, the PLC only records state\r
+   information of the current block that can be used in case the next\r
+   block is lost. The LP filter coefficients for each sub-block and the\r
+   entire decoded excitation signal are all saved in the decoder state\r
+   structure. All this information will be needed if the following\r
+   block is lost.\r
+\r
+\r
+ 4.5.2 Block Not Received\r
+   \r
+   If the block is not received, the block substitution is based on\r
+   doing a pitch synchronous repetition of the excitation signal which\r
+   is filtered by the last LP filter of the previous block. The\r
+   previous block's information is stored in the decoder state\r
+   structure.\r
+   \r
+   A correlation analysis is performed on the previous block's\r
+   excitation signal in order to detect the amount of pitch periodicity\r
+   and a pitch value. The correlation measure is also used to decide on\r
+   the voicing level (the degree to which the previous block's\r
+   excitation was a voiced or roughly periodic signal).  The excitation\r
+   in the previous block is used to create an excitation for the block\r
+   to be substituted such that the pitch of the previous block is\r
+   maintained. Therefore, the new excitation is constructed in a pitch\r
+   synchronous manner. In order to avoid a buzzy sounding substituted\r
+   block, a random excitation is mixed with the new pitch periodic\r
+   excitation and the relative use of the two components is computed\r
+   from the correlation measure (voicing level).\r
+   \r
+   For the block to be substituted, the newly constructed excitation\r
+   signal is then passed through the LP filter to produce the speech\r
+   that will be substituted for the lost block.\r
+   \r
+   For several consecutive lost blocks, the packet loss concealment\r
+   continues in a similar manner. The correlation measure of the last\r
+   received block is still used along with the same pitch value. The LP\r
+   filters of the last received block are also used again.  The energy\r
+   of the substituted excitation for consecutive lost blocks is\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     33\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   decreased, leading to a dampened excitation, and therefore dampened\r
+   speech.\r
+\r
+\r
+ 4.5.3 Block Received Correctly When Previous Block Not Received\r
+   \r
+   For the case in which a block is received correctly when the\r
+   previous block was not received, the correctly received block's\r
+   directly decoded speech (based solely on the received block) is not\r
+   used as the actual output. The reason for this is that the directly\r
+   decoded speech does not necessarily smoothly merge into the\r
+   synthetic speech generated for the previous lost block. If the two\r
+   signals are not smoothly merged, an audible discontinuity is\r
+   accidentally produced. Therefore, a correlation analysis between the\r
+   two blocks of excitation signal (the excitation of the previous\r
+   concealed block and the excitation of the current received block) is\r
+   performed to find the best phase match. Then a simple overlap-add\r
+   procedure is performed to smoothly merge the previous excitation\r
+   into the current block's excitation.\r
+   \r
+   The exact implementation of the packet loss concealment does not\r
+   influence interoperability of the codec.\r
+   \r
+   A reference implementation of the packet loss concealment is\r
+   suggested in Appendix A.14. Exact compliance with this suggested\r
+   algorithm is not needed for a reference implementation to be fully\r
+   compatible with the overall codec specification. \r
+\r
+\r
+4.6 Enhancement \r
+   \r
+   The decoder contains an enhancement unit that operates on the\r
+   reconstructed excitation signal. The enhancement unit increases the\r
+   perceptual quality of the reconstructed signal by reducing the\r
+   speech-correlated noise in the voiced speech segments. Compared to\r
+   traditional postfilters, the enhancer has the advantage that it can\r
+   only modify the excitation signal slightly. This means that there is\r
+   no risk of over enhancement. The enhancer works very similar for\r
+   both the 20 ms frame size mode and for the 30 ms frame size mode.\r
+   \r
+   For the mode with 20 ms frame size, the enhancer uses a memory of\r
+   six 80 sample excitation blocks prior in time plus the two new 80\r
+   sample excitation blocks. For each block of 160 new unenhanced\r
+   excitation samples, 160 enhanced excitation samples are produced.\r
+   The enhanced excitation is 40 sample delayed compared to the\r
+   unenhanced excitation since the enhancer algorithm uses lookahead.\r
+   \r
+   For the mode with 30 ms frame size, the enhancer uses a memory of\r
+   five 80 sample excitation blocks prior in time plus the three new 80\r
+   sample excitation blocks. For each block of 240 new unenhanced\r
+   excitation samples, 240 enhanced excitation samples are produced.\r
+   The enhanced excitation is 80 sample delayed compared to the\r
+   unenhanced excitation since the enhancer algorithm uses lookahead.\r
+   \r
+   OUTLINE of Enhancer\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     34\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   The speech enhancement unit operates on sub-blocks of 80 samples,\r
+   which means that there are two/three 80 sample sub-blocks per frame.\r
+   Each of these two/three sub-blocks is enhanced separately, but in an\r
+   analogous manner. \r
+   \r
+   unenhanced residual\r
+           |\r
+           |   +---------------+    +--------------+\r
+           +-> | 1. Pitch Est  | -> | 2. Find PSSQ | -------->\r
+               +---------------+  | +--------------+\r
+                                  +-----<-------<------<--+\r
+               +------------+         enh block 0..1/2    |\r
+            -> | 3. Smooth  |                             |\r
+               +------------+                             |\r
+                 \                                        |\r
+                 /\                                       |\r
+                /  \   Already                            |\r
+               / 4. \----------->----------->-----------+ |\r
+               \Crit/ Fulfilled                         | |\r
+                \? /                                    v |\r
+                 \/                                     | |\r
+                  \  +-----------------+    +---------+ | |\r
+              Not +->| 5. Use Constr.  | -> | 6. Mix  | ----->\r
+           Fulfilled +-----------------+    +---------+\r
+   \r
+            ---------------> enhanced residual \r
+   \r
+   Figure 4.2. Flow chart of the enhancer\r
+   \r
+   1. Pitch estimation of each of the two/three new 80 sample blocks\r
+   2. Find the pitch-period-synchronous sequence n (for block k) by a\r
+   search around the estimated pitch value. Do this for \r
+                           n=1,2,3,-1,-2,-3\r
+   3. Calculate the smoothed residual generated by the 6 pitch-period-\r
+   synchronous sequences from prior step\r
+   4. Check if the smoothed residual satisfies the criterion (section\r
+   4.6.4)\r
+   5. Use constraint to calculate mixing factor (section 4.6.5)\r
+   6. Mix smoothed signal with unenhanced residual (pssq(n) n=0)\r
+   \r
+   The main idea of the enhancer is to find three 80 sample blocks\r
+   before and three 80 sample blocks after the analyzed unenhanced sub-\r
+   block and use these to improve the quality of the excitation in that\r
+   sub-block. The six blocks are chosen so that they have the highest\r
+   possible correlation with the unenhanced sub-block that is being\r
+   enhanced. In other words the 6 blocks are pitch-period-synchronous\r
+   sequences to the unenhanced sub-block.\r
+   \r
+   A linear combination of the six pitch-period-synchronous sequences\r
+   is calculated that approximates the sub-block. If the squared error\r
+   between the approximation and the unenhanced sub-block is small\r
+   enough, the enhanced residual is set equal to this approximation.\r
+   For the cases when the squared error criterion is not fulfilled, a\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     35\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   linear combination of the approximation and the unenhanced residual\r
+   forms the enhanced residual.\r
+   \r
+ 4.6.1 Estimating the pitch\r
+   \r
+   Pitch estimates are needed to determine the locations of the pitch-\r
+   period-synchronous sequences in a complexity efficient way. For each\r
+   of the new two/three sub-blocks a pitch estimate is calculated by\r
+   finding the maximum correlation in the range from lag 20 to lag 120.\r
+   \r
+   These pitch estimates are used to narrow down the search for the\r
+   best possible pitch-period-synchronous sequences.\r
+\r
+\r
+ 4.6.2 Determination of the Pitch-Synchronous Sequences\r
+   \r
+   Upon receiving the pitch estimates from the prior step, the enhancer\r
+   analyzes and enhances one 80 sample sub-block at a time. The pitch-\r
+   period-synchronous-sequences pssq(n) can be viewed as vectors of\r
+   length 80 samples each shifted n*lag samples from the current sub-\r
+   block. The six pitch-period-synchronous-sequences, pssq(-3) to\r
+   pssq(-1) and pssq(1) to pssq(3), are found one at a time by the\r
+   steps below: \r
+   \r
+   1) Calculate the estimate of the position of the pssq(n). For\r
+      pssq(n) in front of pssq(0) (n > 0), the location of the pssq(n)\r
+      is estimated by moving one pitch estimate forward in time from\r
+      the exact location of pssq(n-1). Similarly for pssq(n) behind\r
+      pssq(0) (n < 0) is estimated by moving one pitch estimate\r
+      backward in time from the exact location of pssq(n+1). If the\r
+      estimated pssq(n) vector location is totally within the enhancer\r
+      memory (figure 4.3) step 2,3, and 4 are performed, otherwise the\r
+      pssq(n) is set to zeros.\r
+   \r
+   2) Compute the correlation between the unenhanced excitation and\r
+      vectors around the estimated location interval of pssq(n). The\r
+      correlation is calculated in the interval estimated location +/-\r
+      2 samples. This results in 5 correlation values.\r
+      \r
+   3) The 5 correlation values are upsampled by a factor 4, using sinc\r
+      upsampling filters (four MA filters with coefficients upsFilter1\r
+      .. upsFilter4). Within these the maximum value is found, which\r
+      specifies the best pitch-period with a resolution of a quarter of\r
+      a sample.\r
+\r
+\r
+        upsFilter1[7]={0.000000 0.000000 0.000000 1.000000 \r
+               0.000000 0.000000 0.000000}\r
+        upsFilter2[7]={0.015625 -0.076904 0.288330 0.862061 \r
+              -0.106445 0.018799 -0.015625}\r
+        upsFilter3[7]={0.023682 -0.124268 0.601563 0.601563 \r
+              -0.124268 0.023682 -0.023682} \r
+        upsFilter4[7]={0.018799 -0.106445 0.862061 0.288330 \r
+              -0.076904 0.015625 -0.018799}\r
+   \r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     36\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   4) Generate the pssq(n) vector by upsampling of the excitation\r
+      memory and extracting the sequence that corresponds to the lag\r
+      delay that was calculated in prior step.\r
+   \r
+   With the steps above all the pssq(n) can be found in an iterative\r
+   manner, first moving backward in time from pssq(0) and then forward\r
+   in time from pssq(0).\r
+\r
+\r
+   0              159             319             479             639\r
+   +---------------------------------------------------------------+\r
+   |  -5   |  -4   |  -3   |  -2   |  -1   |   0   |   1   |   2   |\r
+   +---------------------------------------------------------------+\r
+                                               |pssq 0 |\r
+                                          |pssq -1| |pssq 1 |\r
+                                       |pssq -2|       |pssq 2 |\r
+                                    |pssq -3|             |pssq 3 |\r
+   \r
+   Figure 4.3. Enhancement for 20 ms frame size\r
+   \r
+   Figure 4.3. depicts pitch-period-synchronous sequences in the\r
+   enhancement of the first 80 sample block in the 20 ms frame size\r
+   mode. The unenhanced signal input is stored in the two last sub-\r
+   blocks (1-2), and the six other sub-blocks contain unenhanced\r
+   residual prior-in-time. We perform the enhancement algorithm on two\r
+   blocks of 80 samples, where the first of the two blocks consist of\r
+   the last 40 samples of sub-block 0 and the first 40 samples of sub-\r
+   block 1. The second 80 sample block consists of the last 40 samples\r
+   of sub-block 1 and the first 40 samples of sub-block 2.\r
+\r
+\r
+   0              159             319             479             639\r
+   +---------------------------------------------------------------+\r
+   |  -4   |  -3   |  -2   |  -1   |   0   |   1   |   2   |   3   |\r
+   +---------------------------------------------------------------+\r
+                                   |pssq 0 |\r
+                              |pssq -1| |pssq 1 |\r
+                           |pssq -2|       |pssq 2 |\r
+                        |pssq -3|             |pssq 3 |\r
+   \r
+   Figure 4.4. Enhancement for 30 ms frame size\r
+   \r
+   Figure 4.4. depicts pitch-period-synchronous sequences in the\r
+   enhancement of the first 80 sample block in the 30 ms frame size\r
+   mode. The unenhanced signal input is stored in the three last sub-\r
+   blocks (1-3). The five other sub-blocks contain unenhanced residual\r
+   prior-in-time. The enhancement algorithm is performed on the three\r
+   80 sample sub-blocks 0, 1 and 2.\r
+\r
+\r
+ 4.6.3 Calculation of the smoothed excitation\r
+   \r
+   A linear combination of the six pssq(n) (n!=0) form a smoothed\r
+   approximation, z, of pssq(0). Most of the weight is put on the\r
+   sequences that are close to pssq(0) since these are most likely to\r
+   be most similar to pssq(0). The smoothed vector is also rescaled, so\r
+   that the energy of z is the same as the energy of pssq(0).\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     37\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+         ___\r
+         \\r
+      y = > pssq(i) * pssq_weight(i)\r
+         /__\r
+      i=-3,-2,-1,1,2,3\r
+   \r
+      pssq_weight(i) = 0.5*(1-cos(2*pi*(i+4)/(2*3+2)))\r
+   \r
+      z = C * y, where C = ||pssq(0)||/||y||\r
+   \r
+ 4.6.4 Enhancer criterion\r
+   \r
+   The criterion of the enhancer is that the enhanced excitation is not\r
+   allowed to differ much from the unenhanced excitation. This\r
+   criterion is checked for each 80 sample sub-block.\r
+   \r
+      e < (b * ||pssq(0)||^2), where b=0.05 and   (Constraint 1)\r
+   \r
+      e = (pssq(0)-z)*(pssq(0)-z), and "*" means the dot product\r
+   \r
+ 4.6.5 Enhancing the excitation\r
+   \r
+   From the criterion in the previous section it is clear that the\r
+   excitation is not allowed to change much. The purpose of this\r
+   constraint is to prevent the creation of an enhanced signal that is\r
+   significantly different from the original signal. This also means\r
+   that the constraint limits the numerical size of the errors that the\r
+   enhancement procedure can make. That is especially important in\r
+   unvoiced segments and background noise segments where increased\r
+   periodicity could lead to lower perceived quality.\r
+   \r
+   When the constraint in the prior section is not met, the enhanced\r
+   residual is instead calculated through a constrained optimization\r
+   using the Lagrange multiplier technique. The new constraint is that:\r
+   \r
+      e = (b * ||pssq(0)||^2)                     (Constraint 2)\r
+   \r
+   We distinguish two solution regions for the optimization: 1) the\r
+   region where the first constraint is fulfilled and 2) the region\r
+   where the first constraint is not fulfilled so the second constraint\r
+   must be used.\r
+   \r
+   In the first case, where the second constraint is not needed, the\r
+   optimized re-estimated vector is simply z, the energy scaled version\r
+   of y.\r
+\r
+\r
+   In the second case, where the second constraint is activated and\r
+   becomes an equality constraint, we have that\r
+   \r
+      z= A*y + B*pssq(0) \r
+    \r
+   where\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     38\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+      A = sqrt((b-b^2/4)*(w00*w00)/ (w11*w00 + w10*w10)) and\r
+         \r
+      w11 = pssq(0)*pssq(0)\r
+      w00 = y*y\r
+      w10 = y*pssq(0)    (* symbolizes the dot product)\r
+\r
+\r
+   and \r
+   \r
+      B = 1 - b/2 - A * w10/w00\r
+   \r
+   Appendix A.16 contains a listing of a reference implementation for\r
+   the enhancement method.\r
+\r
+\r
+4.7 Synthesis Filtering\r
+   \r
+   Upon decoding or PLC of the LP excitation block, the decoded speech\r
+   block is obtained by running the decoded LP synthesis filter,\r
+   1/A~k(z), over the block. The synthesis filters have to be shifted\r
+   to compensate for the delay in the enhancer. For 20 ms frame size\r
+   mode they SHOULD be shifted one 40 sample sub-block and for 30 ms\r
+   frame size mode they SHOULD be shifted two 40 sample sub-blocks. The\r
+   LP coefficients SHOULD be changed at the first sample of every sub-\r
+   block while keeping the filter state. For PLC blocks, one solution\r
+   is to apply the last LP coefficients of the last decoded speech\r
+   block for all sub-blocks.\r
+   \r
+   The reference implementation for the synthesis filtering can be\r
+   found in Appendix A.48.\r
+\r
+\r
+4.8 Post Filtering\r
+\r
+\r
+   If desired the decoded block can be filtered by a high-pass filter.\r
+   This removes the low frequencies of the decoded signal. A reference\r
+   implementation of this, with cut off at 65 Hz, is shown in Appendix\r
+   A.30.\r
+\r
+\r
+\r
+5. IANA CONSIDERATIONS\r
+   \r
+   This algorithm for the coding of speech signals does not have any\r
+   IANA considerations that need to be addressed.\r
+\r
+\r
+   \r
+6. SECURITY CONSIDERATIONS\r
+\r
+\r
+   This algorithm for the coding of speech signals is not subject of\r
+   any known security consideration; however, its RTP payload format\r
+   [1] is subject of several considerations which are addressed there.\r
+   Confidentiality of the media streams is achieved by encryption,\r
+   therefore external mechanisms, such as SRTP [5], MAY be used for\r
+   that purpose.\r
+\r
+\r
+7. EVALUATION OF THE ILBC IMPLEMENTATIONS\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     39\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   It is possible and suggested to evaluate certain iLBC implementation\r
+   by utilizing methodology and tools available at\r
+   http://www.ilbcfreeware.org/evaluation.html\r
+\r
+\r
+8. REFERENCES\r
+   \r
+8.1 Normative\r
+   \r
+   [1] A. Duric and S. V. Andersen, "RTP Payload Format for iLBC\r
+      Speech", IETF Draft, May 2004\r
+   \r
+   [2] S. Bradner, "Key words for use in RFCs to Indicate requirement\r
+      Levels", BCP 14, RFC 2119, March 1997.\r
+   \r
+   [3] PacketCable(TM) Audio/Video Codecs Specification, Cable\r
+      Television Laboratories, Inc.\r
+   \r
+8.2 Informative\r
+   \r
+   [4] ITU-T Recommendation G.711, available online from the ITU\r
+      bookstore at http://www.itu.int.\r
+   \r
+   [5] Baugher, et al., "The Secure Real Time Transport Protocol", IETF\r
+      RFC 3711, March 2004.\r
+\r
+\r
+9. ACKNOWLEDGEMENTS\r
+\r
+\r
+   This extensive work, beside listed authors, has the following\r
+   authors, which could not been listed among "official" authors (due\r
+   to IESG confines in number of authors which can be listed):\r
+   \r
+        Manohar N Murthi (Dpt of El and Comp Eng, University of Miami),\r
+        Fredrik Galschiodt, Julian Spittka and Jan Skoglund (Global IP\r
+        Sound)\r
+   \r
+   The authors are deeply indebted to them all and thank them\r
+   sincerely:\r
+   \r
+         Henry Sinnreich, Patrik Faltstrom and Alan Johnston\r
+   \r
+   for great support of the iLBC initiative and for valuable feedback\r
+   and comments.\r
+   \r
+         Peter Vary, Frank Mertz and Christoph Erdmann (RWTH Aachen);\r
+         Vladimir Cuperman (Niftybox LLC); Thomas Eriksson (Chalmers\r
+         Univ of Tech) and Gernot Kubin (TU Graz)\r
+         \r
+   for thorough review of the iLBC draft and their valuable feedback\r
+   and remarks.\r
+   \r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     40\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+10. AUTHOR'S ADDRESSES\r
+   \r
+   Soren Vang Andersen\r
+   Department of Communication Technology\r
+   Aalborg University\r
+   Fredrik Bajers Vej 7A\r
+   9200 Aalborg\r
+   Denmark\r
+   Phone:  ++45 9 6358627\r
+   Email:  sva@kom.auc.dk\r
+   \r
+   Alan Duric\r
+   Telio AS\r
+   Stortingsgt. 8\r
+   Oslo, N-0161\r
+   Norway\r
+   Phone:  +47 21673555\r
+   Email:  alan.duric@telio.no\r
+   \r
+   Henrik Astrom\r
+   Global IP Sound AB\r
+   Rosenlundsgatan 54 \r
+   Stockholm, S-11863\r
+   Sweden\r
+   Phone:  +46 8 54553040\r
+   Email:  henrik.astrom@globalipsound.com\r
+   \r
+   Roar Hagen\r
+   Global IP Sound AB\r
+   Rosenlundsgatan 54\r
+   Stockholm, S-11863\r
+   Sweden\r
+   Phone:  +46 8 54553040\r
+   Email:  roar.hagen@globalipsound.com\r
+   \r
+   W. Bastiaan Kleijn\r
+   Global IP Sound AB\r
+   Rosenlundsgatan 54\r
+   Stockholm, S-11863\r
+   Sweden\r
+   Phone:  +46 8 54553040\r
+   Email:  bastiaan.kleijn@globalipsound.com\r
+\r
+\r
+   Jan Linden\r
+   Global IP Sound Inc.\r
+   900 Kearny Street, suite 500\r
+   San Francisco, CA-94133\r
+   USA\r
+   Phone: +1 415 397 2555\r
+   Email: jan.linden@globalipsound.com\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     41\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+Full Copyright Statement\r
+\r
+\r
+   Copyright (C) The Internet Society (2004).  This document is subject\r
+   to the rights, licenses and restrictions contained in BCP 78 and\r
+   except as set forth therein, the authors retain all their rights.\r
+\r
+\r
+   This document and the information contained herein are provided on\r
+   "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE\r
+   REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE\r
+   INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR\r
+   IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF\r
+   THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED\r
+   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.\r
+\r
+\r
+Intellectual Property\r
+\r
+\r
+   The IETF takes no position regarding the validity or scope of any\r
+   Intellectual Property Rights or other rights that might be claimed\r
+   to pertain to the implementation or use of the technology described\r
+   in this document or the extent to which any license under such\r
+   rights might or might not be available; nor does it represent that\r
+   it has made any independent effort to identify any such rights. \r
+   Information on the procedures with respect to rights in RFC\r
+   documents can be found in BCP 78 and BCP 79.\r
+\r
+\r
+   Copies of IPR disclosures made to the IETF Secretariat and any\r
+   assurances of licenses to be made available, or the result of an\r
+   attempt made to obtain a general license or permission for the use\r
+   of such proprietary rights by implementers or users of this\r
+   specification can be obtained from the IETF on-line IPR repository\r
+   at http://www.ietf.org/ipr.\r
+\r
+\r
+   The IETF invites any interested party to bring to its attention any\r
+   copyrights, patents or patent applications, or other proprietary\r
+   rights that may cover technology that may be required to implement\r
+   this standard. Please address the information to the IETF at ietf-\r
+   ipr@ietf.org.\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     42\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+APPENDIX A REFERENCE IMPLEMENTATION\r
+                                                               \r
+   This appendix contains the complete c-code for a reference\r
+   implementation of encoder and decoder for the specified codec.\r
+   \r
+   The c-code consists of the following files with highest level\r
+   functions:\r
+         \r
+         iLBC_test.c: main function for evaluation purpose\r
+         iLBC_encode.h: encoder header\r
+         iLBC_encode.c: encoder function\r
+         iLBC_decode.h: decoder header\r
+         iLBC_decode.c: decoder function\r
+   \r
+   the following files containing global defines and constants:\r
+   \r
+         iLBC_define.h: global defines\r
+         constants.h: global constants header\r
+         constants.c: global constants memory allocations\r
+   \r
+   and the following files containing subroutines:\r
+   \r
+         anaFilter.h: lpc analysis filter header\r
+         anaFilter.c: lpc analysis filter function\r
+         createCB.h: codebook construction header\r
+         createCB.c: codebook construction function\r
+         doCPLC.h: packet loss concealment header\r
+         doCPLC.c: packet loss concealment function\r
+         enhancer.h: signal enhancement header\r
+         enhancer.c: signal enhancement function\r
+         filter.h: general filter header\r
+         filter.c: general filter functions\r
+         FrameClassify.h: start state classification header\r
+         FrameClassify.c: start state classification function\r
+         gainquant.h: gain quantization header\r
+         gainquant.c: gain quantization function\r
+         getCBvec.h: codebook vector construction header\r
+         getCBvec.c: codebook vector construction function\r
+         helpfun.h: general purpose header\r
+         helpfun.c: general purpose functions\r
+         hpInput.h: input high pass filter header\r
+         hpInput.c: input high pass filter function\r
+         hpOutput.h: output high pass filter header\r
+         hpOutput.c: output high pass filter function\r
+         iCBConstruct.h: excitation decoding header\r
+         iCBConstruct.c: excitation decoding function\r
+         iCBSearch.h: excitation encoding header\r
+         iCBSearch.c: excitation encoding function\r
+         LPCdecode.h: lpc decoding header\r
+         LPCdecode.c: lpc decoding function\r
+         LPCencode.h: lpc encoding header\r
+         LPCencode.c: lpc encoding function\r
+         lsf.h: line spectral frequencies header\r
+         lsf.c: line spectral frequencies functions\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     43\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+         packing.h: bitstream packetization header\r
+         packing.c: bitstream packetization functions\r
+         StateConstructW.h: state decoding header\r
+         StateConstructW.c: state decoding functions\r
+         StateSearchW.h: state encoding header\r
+         StateSearchW.c: state encoding function\r
+         syntFilter.h: lpc synthesis filter header\r
+         syntFilter.c: lpc synthesis filter function\r
+         \r
+   The implementation is portable and should work on many different\r
+   platforms. However, it is not difficult to optimize the\r
+   implementation on particular platforms, an exercise left to the\r
+   reader.\r
+   \r
+   \r
+A.1 iLBC_test.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_test.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   #include <stdio.h>\r
+   #include <string.h>\r
+   #include "iLBC_define.h"\r
+   #include "iLBC_encode.h"\r
+   #include "iLBC_decode.h"\r
+   \r
+   /* Runtime statistics */\r
+   #include <time.h>\r
+   \r
+   #define ILBCNOOFWORDS_MAX   (NO_OF_BYTES_30MS/2)\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Encoder interface function \r
+    *---------------------------------------------------------------*/\r
+   \r
+   short encode(   /* (o) Number of bytes encoded */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                                   /* (i/o) Encoder instance */ \r
+       short *encoded_data,    /* (o) The encoded bytes */\r
+       short *data                 /* (i) The signal block to encode*/\r
+   ){\r
+       float block[BLOCKL_MAX];\r
+       int k;\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     44\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       /* convert signal to float */\r
+   \r
+       for (k=0; k<iLBCenc_inst->blockl; k++) \r
+           block[k] = (float)data[k];\r
+   \r
+       /* do the actual encoding */\r
+   \r
+       iLBC_encode((unsigned char *)encoded_data, block, iLBCenc_inst);\r
+   \r
+   \r
+       return (iLBCenc_inst->no_of_bytes);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Decoder interface function \r
+    *---------------------------------------------------------------*/\r
+   \r
+   short decode(       /* (o) Number of decoded samples */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+       short *decoded_data,        /* (o) Decoded signal block*/\r
+       short *encoded_data,        /* (i) Encoded bytes */\r
+       short mode                       /* (i) 0=PL, 1=Normal */\r
+   ){\r
+       int k;\r
+       float decblock[BLOCKL_MAX], dtmp;\r
+   \r
+       /* check if mode is valid */\r
+   \r
+       if (mode<0 || mode>1) {\r
+           printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);}\r
+   \r
+       /* do actual decoding of block */\r
+   \r
+       iLBC_decode(decblock, (unsigned char *)encoded_data, \r
+           iLBCdec_inst, mode);\r
+   \r
+       /* convert to short */\r
+   \r
+       for (k=0; k<iLBCdec_inst->blockl; k++){ \r
+           dtmp=decblock[k];\r
+   \r
+           if (dtmp<MIN_SAMPLE)\r
+               dtmp=MIN_SAMPLE;\r
+           else if (dtmp>MAX_SAMPLE)\r
+               dtmp=MAX_SAMPLE;\r
+           decoded_data[k] = (short) dtmp;\r
+       }\r
+   \r
+       return (iLBCdec_inst->blockl);\r
+   }\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  Main program to test iLBC encoding and decoding \r
+    *\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     45\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+    *  Usage:\r
+    *    exefile_name.exe <infile> <bytefile> <outfile> <channel>\r
+    *\r
+    *    <infile>   : Input file, speech for encoder (16-bit pcm file)\r
+    *    <bytefile> : Bit stream output from the encoder\r
+    *    <outfile>  : Output file, decoded speech (16-bit pcm file)\r
+    *    <channel>  : Bit error file, optional (16-bit)\r
+    *                     1 - Packet received correctly\r
+    *                     0 - Packet Lost\r
+    *\r
+    *--------------------------------------------------------------*/\r
+   \r
+   int main(int argc, char* argv[])\r
+   {\r
+   \r
+       /* Runtime statistics */\r
+   \r
+       float starttime;\r
+       float runtime;\r
+       float outtime;\r
+   \r
+       FILE *ifileid,*efileid,*ofileid, *cfileid;\r
+       short data[BLOCKL_MAX];\r
+       short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];\r
+       int len;\r
+       short pli, mode;\r
+       int blockcount = 0;\r
+       int packetlosscount = 0;\r
+   \r
+       /* Create structs */\r
+       iLBC_Enc_Inst_t Enc_Inst;\r
+       iLBC_Dec_Inst_t Dec_Inst;\r
+   \r
+       /* get arguments and open files */\r
+   \r
+       if ((argc!=5) && (argc!=6)) {\r
+           fprintf(stderr, \r
+           "\n*-----------------------------------------------*\n");\r
+           fprintf(stderr, \r
+           "   %s <20,30> input encoded decoded (channel)\n\n",\r
+               argv[0]);\r
+           fprintf(stderr, \r
+           "   mode    : Frame size for the encoding/decoding\n");\r
+           fprintf(stderr, \r
+           "                 20 - 20 ms\n");\r
+           fprintf(stderr, \r
+           "                 30 - 30 ms\n");\r
+           fprintf(stderr, \r
+           "   input   : Speech for encoder (16-bit pcm file)\n");\r
+           fprintf(stderr, \r
+           "   encoded : Encoded bit stream\n");\r
+           fprintf(stderr, \r
+           "   decoded : Decoded speech (16-bit pcm file)\n");\r
+           fprintf(stderr, \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     46\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           "   channel : Packet loss pattern, optional (16-bit)\n");\r
+           fprintf(stderr, \r
+           "                  1 - Packet received correctly\n");\r
+           fprintf(stderr, \r
+           "                  0 - Packet Lost\n");\r
+           fprintf(stderr, \r
+           "*-----------------------------------------------*\n\n");\r
+           exit(1);\r
+       }\r
+       mode=atoi(argv[1]);\r
+       if (mode != 20 && mode != 30) {\r
+           fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", \r
+               argv[1]);\r
+           exit(2);\r
+       }\r
+       if ( (ifileid=fopen(argv[2],"rb")) == NULL) {\r
+           fprintf(stderr,"Cannot open input file %s\n", argv[2]);\r
+           exit(2);}\r
+       if ( (efileid=fopen(argv[3],"wb")) == NULL) {\r
+           fprintf(stderr, "Cannot open encoded file file %s\n", \r
+               argv[3]); exit(1);}\r
+       if ( (ofileid=fopen(argv[4],"wb")) == NULL) {\r
+           fprintf(stderr, "Cannot open decoded file %s\n", \r
+               argv[4]); exit(1);}\r
+       if (argc==6) {\r
+           if( (cfileid=fopen(argv[5],"rb")) == NULL) {\r
+               fprintf(stderr, "Cannot open channel file %s\n", \r
+                   argv[5]); \r
+               exit(1);\r
+           }\r
+       } else {\r
+           cfileid=NULL;\r
+       }\r
+   \r
+       /* print info */\r
+   \r
+       fprintf(stderr, "\n");\r
+       fprintf(stderr, \r
+           "*---------------------------------------------------*\n");\r
+       fprintf(stderr, \r
+           "*                                                   *\n");\r
+       fprintf(stderr, \r
+           "*      iLBC test program                            *\n");\r
+       fprintf(stderr, \r
+           "*                                                   *\n");\r
+       fprintf(stderr, \r
+           "*                                                   *\n");\r
+       fprintf(stderr, \r
+           "*---------------------------------------------------*\n");\r
+       fprintf(stderr,"\nMode           : %2d ms\n", mode);\r
+       fprintf(stderr,"Input file     : %s\n", argv[2]);\r
+       fprintf(stderr,"Encoded file   : %s\n", argv[3]);\r
+       fprintf(stderr,"Output file    : %s\n", argv[4]);\r
+       if (argc==6) {\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     47\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           fprintf(stderr,"Channel file   : %s\n", argv[5]);\r
+       }\r
+       fprintf(stderr,"\n");\r
+   \r
+       /* Initialization */\r
+   \r
+       initEncode(&Enc_Inst, mode);\r
+       initDecode(&Dec_Inst, mode, 1);\r
+   \r
+       /* Runtime statistics */\r
+   \r
+       starttime=clock()/(float)CLOCKS_PER_SEC; \r
+   \r
+       /* loop over input blocks */\r
+   \r
+       while (fread(data,sizeof(short),Enc_Inst.blockl,ifileid)==\r
+               Enc_Inst.blockl) {\r
+           \r
+           blockcount++;\r
+           \r
+           /* encoding */\r
+   \r
+           fprintf(stderr, "--- Encoding block %i --- ",blockcount);\r
+           len=encode(&Enc_Inst, encoded_data, data);\r
+           fprintf(stderr, "\r");\r
+   \r
+           /* write byte file */\r
+   \r
+           fwrite(encoded_data, sizeof(unsigned char), len, efileid);\r
+   \r
+           /* get channel data if provided */\r
+           if (argc==6) {\r
+               if (fread(&pli, sizeof(short), 1, cfileid)) {\r
+                   if ((pli!=0)&&(pli!=1)) {\r
+                       fprintf(stderr, "Error in channel file\n");\r
+                       exit(0);\r
+                   }\r
+                   if (pli==0) {\r
+                       /* Packet loss -> remove info from frame */\r
+                       memset(encoded_data, 0, \r
+                           sizeof(short)*ILBCNOOFWORDS_MAX);\r
+                       packetlosscount++;\r
+                   }\r
+               } else {\r
+                   fprintf(stderr, "Error. Channel file too short\n");\r
+                   exit(0);\r
+               }\r
+           } else {\r
+               pli=1;\r
+           }\r
+           \r
+           /* decoding */\r
+   \r
+           fprintf(stderr, "--- Decoding block %i --- ",blockcount);\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     48\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           len=decode(&Dec_Inst, decoded_data, encoded_data, pli);\r
+           fprintf(stderr, "\r");\r
+   \r
+           /* write output file */\r
+   \r
+           fwrite(decoded_data,sizeof(short),len,ofileid);\r
+       }\r
+   \r
+       /* Runtime statistics */\r
+   \r
+       runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime);\r
+       outtime = (float)((float)blockcount*(float)mode/1000.0);\r
+       printf("\n\nLength of speech file: %.1f s\n", outtime);\r
+       printf("Packet loss          : %.1f%%\n", \r
+           100.0*(float)packetlosscount/(float)blockcount);\r
+       printf("Time to run iLBC     :");\r
+       printf(" %.1f s (%.1f %% of realtime)\n\n", runtime, \r
+           (100*runtime/outtime));\r
+       \r
+       /* close files */\r
+   \r
+       fclose(ifileid);  fclose(efileid); fclose(ofileid);\r
+       if (argc==6) {\r
+           fclose(cfileid);\r
+       }\r
+       return(0);\r
+   }\r
+   \r
+   \r
+A.2 iLBC_encode.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_encode.h    \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ILBCENCODE_H\r
+   #define __iLBC_ILBCENCODE_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   short initEncode(                   /* (o) Number of bytes \r
+                                              encoded */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
+       int mode                    /* (i) frame size mode */\r
+   );\r
+   \r
+   void iLBC_encode(\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     49\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
+       float *block,                   /* (o) speech vector to \r
+                                              encode */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
+                                              state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+\r
+\r
+A.3 iLBC_encode.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_encode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "LPCencode.h"\r
+   #include "FrameClassify.h"\r
+   #include "StateSearchW.h"\r
+   #include "StateConstructW.h"\r
+   #include "helpfun.h"\r
+   #include "constants.h"\r
+   #include "packing.h"\r
+   #include "iCBSearch.h"\r
+   #include "iCBConstruct.h"\r
+   #include "hpInput.h"\r
+   #include "anaFilter.h"\r
+   #include "syntFilter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Initiation of encoder instance.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   short initEncode(                   /* (o) Number of bytes \r
+                                              encoded */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
+       int mode                    /* (i) frame size mode */\r
+   ){\r
+       iLBCenc_inst->mode = mode;\r
+       if (mode==30) {\r
+           iLBCenc_inst->blockl = BLOCKL_30MS;\r
+           iLBCenc_inst->nsub = NSUB_30MS;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     50\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           iLBCenc_inst->nasub = NASUB_30MS;\r
+           iLBCenc_inst->lpc_n = LPC_N_30MS;\r
+           iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
+           iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;\r
+           iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
+           /* ULP init */\r
+           iLBCenc_inst->ULP_inst=&ULP_30msTbl;\r
+       }\r
+       else if (mode==20) {\r
+           iLBCenc_inst->blockl = BLOCKL_20MS;\r
+           iLBCenc_inst->nsub = NSUB_20MS;\r
+           iLBCenc_inst->nasub = NASUB_20MS;\r
+           iLBCenc_inst->lpc_n = LPC_N_20MS;\r
+           iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
+           iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;\r
+           iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
+           /* ULP init */\r
+           iLBCenc_inst->ULP_inst=&ULP_20msTbl;\r
+       }\r
+       else {\r
+           exit(2);\r
+       }\r
+   \r
+       memset((*iLBCenc_inst).anaMem, 0, \r
+           LPC_FILTERORDER*sizeof(float));\r
+       memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,\r
+           LPC_FILTERORDER*sizeof(float));\r
+       memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,\r
+           LPC_FILTERORDER*sizeof(float));\r
+       memset((*iLBCenc_inst).lpc_buffer, 0, \r
+           (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));\r
+       memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));\r
+   \r
+       return (iLBCenc_inst->no_of_bytes);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  main encoder function \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iLBC_encode(\r
+       unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
+       float *block,                   /* (o) speech vector to \r
+                                              encode */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
+                                              state */\r
+   ){\r
+       \r
+       float data[BLOCKL_MAX];\r
+       float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];\r
+   \r
+       int start, idxForMax, idxVec[STATE_LEN];\r
+       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
+       int n, k, meml_gotten, Nfor, Nback, i, pos;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     51\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       int gain_index[CB_NSTAGES*NASUB_MAX], \r
+           extra_gain_index[CB_NSTAGES];\r
+       int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];\r
+       int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
+       unsigned char *pbytes;\r
+       int diff, start_pos, state_first;\r
+       float en1, en2;\r
+       int index, ulp, firstpart;\r
+       int subcount, subframe;\r
+       float weightState[LPC_FILTERORDER];\r
+       float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+       float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+       float decresidual[BLOCKL_MAX];\r
+   \r
+       /* high pass filtering of input signal if such is not done \r
+              prior to calling this function */\r
+   \r
+       hpInput(block, iLBCenc_inst->blockl, \r
+                   data, (*iLBCenc_inst).hpimem);\r
+   \r
+       /* otherwise simply copy */\r
+   \r
+       /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/\r
+           \r
+       /* LPC of hp filtered input data */\r
+   \r
+       LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);\r
+   \r
+   \r
+       /* inverse filter to get residual */\r
+   \r
+       for (n=0; n<iLBCenc_inst->nsub; n++) {\r
+           anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], \r
+               SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);\r
+       }\r
+   \r
+       /* find state location */\r
+   \r
+       start = FrameClassify(iLBCenc_inst, residual);\r
+       \r
+       /* check if state should be in first or last part of the \r
+       two subframes */\r
+   \r
+       diff = STATE_LEN - iLBCenc_inst->state_short_len;\r
+       en1 = 0;\r
+       index = (start-1)*SUBL;\r
+       for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
+           en1 += residual[index+i]*residual[index+i];\r
+       }\r
+       en2 = 0;\r
+       index = (start-1)*SUBL+diff;\r
+       for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
+           en2 += residual[index+i]*residual[index+i];\r
+       }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     52\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       \r
+       \r
+       if (en1 > en2) {\r
+           state_first = 1;\r
+           start_pos = (start-1)*SUBL;\r
+       } else {\r
+           state_first = 0;\r
+           start_pos = (start-1)*SUBL + diff;\r
+       }\r
+   \r
+       /* scalar quantization of state */\r
+   \r
+       StateSearchW(iLBCenc_inst, &residual[start_pos], \r
+           &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+           &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, \r
+           idxVec, iLBCenc_inst->state_short_len, state_first);\r
+   \r
+       StateConstructW(idxForMax, idxVec, \r
+           &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+           &decresidual[start_pos], iLBCenc_inst->state_short_len);\r
+   \r
+       /* predictive quantization in state */\r
+       \r
+       if (state_first) { /* put adaptive part in the end */\r
+           \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, \r
+               (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));\r
+           memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, \r
+               decresidual+start_pos, \r
+               iLBCenc_inst->state_short_len*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+           /* encode sub-frames */\r
+   \r
+           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
+               &residual[start_pos+iLBCenc_inst->state_short_len], \r
+               mem+CB_MEML-stMemLTbl,\r
+               stMemLTbl, diff, CB_NSTAGES, \r
+               &weightdenum[start*(LPC_FILTERORDER+1)], \r
+               weightState, 0);\r
+   \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(\r
+               &decresidual[start_pos+iLBCenc_inst->state_short_len],\r
+               extra_cb_index, extra_gain_index, \r
+               mem+CB_MEML-stMemLTbl, \r
+               stMemLTbl, diff, CB_NSTAGES);\r
+       \r
+       } \r
+       else { /* put adaptive part in the beginning */\r
+           \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     53\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           /* create reversed vectors for prediction */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               reverseResidual[k] = residual[(start+1)*SUBL-1\r
+                   -(k+iLBCenc_inst->state_short_len)];\r
+           }\r
+           \r
+           /* setup memory */\r
+   \r
+           meml_gotten = iLBCenc_inst->state_short_len;\r
+           for (k=0; k<meml_gotten; k++) { \r
+               mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
+           } \r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+           \r
+           /* encode sub-frames */\r
+   \r
+           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
+               reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
+               diff, CB_NSTAGES, \r
+               &weightdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+               weightState, 0);\r
+   \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(reverseDecresidual, extra_cb_index, \r
+               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
+               diff, CB_NSTAGES);\r
+           \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               decresidual[start_pos-1-k] = reverseDecresidual[k];\r
+           }\r
+       }\r
+   \r
+       /* counter for predicted sub-frames */\r
+   \r
+       subcount=0;\r
+   \r
+       /* forward prediction of sub-frames */\r
+   \r
+       Nfor = iLBCenc_inst->nsub-start-1;\r
+   \r
+       \r
+       if ( Nfor > 0 ) {\r
+           \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
+           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, \r
+               STATE_LEN*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     54\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+           /* loop over sub-frames to encode */\r
+   \r
+           for (subframe=0; subframe<Nfor; subframe++) {\r
+   \r
+               /* encode sub-frame */\r
+   \r
+               iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   &residual[(start+1+subframe)*SUBL], \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES, \r
+                   &weightdenum[(start+1+subframe)*\r
+                               (LPC_FILTERORDER+1)],\r
+                   weightState, subcount+1);\r
+   \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &decresidual[(start+1+subframe)*SUBL], \r
+                   SUBL*sizeof(float));\r
+               memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+               subcount++;\r
+           }\r
+       }\r
+       \r
+   \r
+       /* backward prediction of sub-frames */\r
+   \r
+       Nback = start-1;\r
+   \r
+       \r
+       if ( Nback > 0 ) {\r
+                  \r
+           /* create reverse order vectors */\r
+   \r
+           for (n=0; n<Nback; n++) {\r
+               for (k=0; k<SUBL; k++) {\r
+                   reverseResidual[n*SUBL+k] = \r
+                       residual[(start-1)*SUBL-1-n*SUBL-k];\r
+                   reverseDecresidual[n*SUBL+k] = \r
+                       decresidual[(start-1)*SUBL-1-n*SUBL-k];\r
+               }\r
+           }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     55\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+           /* setup memory */\r
+   \r
+           meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);\r
+   \r
+           \r
+           if ( meml_gotten > CB_MEML ) { \r
+               meml_gotten=CB_MEML;\r
+           }\r
+           for (k=0; k<meml_gotten; k++) { \r
+               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
+           } \r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+           /* loop over sub-frames to encode */\r
+   \r
+           for (subframe=0; subframe<Nback; subframe++) {\r
+               \r
+               /* encode sub-frame */\r
+   \r
+               iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   &reverseResidual[subframe*SUBL], \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES, \r
+                   &weightdenum[(start-2-subframe)*\r
+                               (LPC_FILTERORDER+1)], \r
+                   weightState, subcount+1);\r
+   \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &reverseDecresidual[subframe*SUBL],\r
+                   SUBL*sizeof(float));\r
+               memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+               subcount++;\r
+   \r
+           }\r
+   \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (i=0; i<SUBL*Nback; i++) {\r
+               decresidual[SUBL*Nback - i - 1] = \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     56\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                   reverseDecresidual[i];\r
+           }\r
+       }\r
+       /* end encoding part */\r
+   \r
+       /* adjust index */\r
+       index_conv_enc(cb_index);\r
+   \r
+       /* pack bytes */\r
+   \r
+       pbytes=bytes;\r
+       pos=0;\r
+   \r
+       /* loop over the 3 ULP classes */\r
+   \r
+       for (ulp=0; ulp<3; ulp++) {\r
+       \r
+           /* LSF */\r
+           for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {\r
+               packsplit(&lsf_i[k], &firstpart, &lsf_i[k], \r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], \r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+\r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
+           }\r
+   \r
+           /* Start block info */\r
+   \r
+           packsplit(&start, &firstpart, &start, \r
+               iLBCenc_inst->ULP_inst->start_bits[ulp], \r
+               iLBCenc_inst->ULP_inst->start_bits[ulp]+\r
+               iLBCenc_inst->ULP_inst->start_bits[ulp+1]+\r
+               iLBCenc_inst->ULP_inst->start_bits[ulp+2]);\r
+           dopack( &pbytes, firstpart, \r
+               iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);\r
+   \r
+           packsplit(&state_first, &firstpart, &state_first, \r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp], \r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+\r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+\r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);\r
+           dopack( &pbytes, firstpart, \r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
+   \r
+           packsplit(&idxForMax, &firstpart, &idxForMax, \r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp], \r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp]+\r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+\r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);\r
+           dopack( &pbytes, firstpart, \r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     57\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           for (k=0; k<iLBCenc_inst->state_short_len; k++) {\r
+               packsplit(idxVec+k, &firstpart, idxVec+k, \r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp], \r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp]+\r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);\r
+           }\r
+   \r
+           /* 23/22 (20ms/30ms) sample block */\r
+   \r
+           for (k=0;k<CB_NSTAGES;k++) {\r
+               packsplit(extra_cb_index+k, &firstpart, \r
+                   extra_cb_index+k, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                   &pos);\r
+           }\r
+   \r
+           for (k=0;k<CB_NSTAGES;k++) {\r
+               packsplit(extra_gain_index+k, &firstpart, \r
+                   extra_gain_index+k, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                   &pos);\r
+           }\r
+               \r
+           /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
+   \r
+           for (i=0; i<iLBCenc_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   packsplit(cb_index+i*CB_NSTAGES+k, &firstpart, \r
+                       cb_index+i*CB_NSTAGES+k, \r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+\r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+\r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);\r
+                   dopack( &pbytes, firstpart, \r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
+                       &pos);\r
+               }\r
+           }\r
+           \r
+           for (i=0; i<iLBCenc_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     58\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                   packsplit(gain_index+i*CB_NSTAGES+k, &firstpart, \r
+                       gain_index+i*CB_NSTAGES+k, \r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+\r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+\r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);\r
+                   dopack( &pbytes, firstpart, \r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                       &pos);\r
+               }\r
+           }\r
+       }\r
+   \r
+       /* set the last bit to zero (otherwise the decoder \r
+          will treat it as a lost frame) */\r
+       dopack( &pbytes, 0, 1, &pos);\r
+   }\r
+   \r
+\r
+\r
+A.4 iLBC_decode.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_decode.h    \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ILBCDECODE_H\r
+   #define __iLBC_ILBCDECODE_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   short initDecode(                   /* (o) Number of decoded \r
+                                              samples */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+       int mode,                       /* (i) frame size mode */\r
+       int use_enhancer                /* (i) 1 to use enhancer\r
+                                              0 to run without \r
+                                                enhancer */\r
+   );\r
+   \r
+   void iLBC_decode( \r
+       float *decblock,            /* (o) decoded signal block */\r
+       unsigned char *bytes,           /* (i) encoded signal bits */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                                structure */\r
+       int mode                    /* (i) 0: bad packet, PLC, \r
+                                              1: normal */\r
+   );\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     59\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   #endif\r
+   \r
+   \r
+A.5 iLBC_decode.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_decode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "StateConstructW.h"\r
+   #include "LPCdecode.h"\r
+   #include "iCBConstruct.h"\r
+   #include "doCPLC.h"\r
+   #include "helpfun.h"\r
+   #include "constants.h"\r
+   #include "packing.h"\r
+   #include "string.h"\r
+   #include "enhancer.h"\r
+   #include "hpOutput.h"\r
+   #include "syntFilter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Initiation of decoder instance.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   short initDecode(                   /* (o) Number of decoded \r
+                                              samples */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+       int mode,                       /* (i) frame size mode */\r
+       int use_enhancer                /* (i) 1 to use enhancer\r
+                                              0 to run without \r
+                                                enhancer */\r
+   ){\r
+       int i;\r
+   \r
+       iLBCdec_inst->mode = mode;\r
+   \r
+       if (mode==30) {\r
+           iLBCdec_inst->blockl = BLOCKL_30MS;\r
+           iLBCdec_inst->nsub = NSUB_30MS;\r
+           iLBCdec_inst->nasub = NASUB_30MS;\r
+           iLBCdec_inst->lpc_n = LPC_N_30MS;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     60\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
+           iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;\r
+           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
+           /* ULP init */\r
+           iLBCdec_inst->ULP_inst=&ULP_30msTbl;\r
+       }\r
+       else if (mode==20) {\r
+           iLBCdec_inst->blockl = BLOCKL_20MS;\r
+           iLBCdec_inst->nsub = NSUB_20MS;\r
+           iLBCdec_inst->nasub = NASUB_20MS;\r
+           iLBCdec_inst->lpc_n = LPC_N_20MS;\r
+           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
+           iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;\r
+           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
+           /* ULP init */\r
+           iLBCdec_inst->ULP_inst=&ULP_20msTbl;\r
+       }\r
+       else {\r
+           exit(2);\r
+       }\r
+   \r
+       memset(iLBCdec_inst->syntMem, 0, \r
+           LPC_FILTERORDER*sizeof(float));\r
+       memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, \r
+           LPC_FILTERORDER*sizeof(float));\r
+   \r
+       memset(iLBCdec_inst->old_syntdenum, 0, \r
+           ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));\r
+       for (i=0; i<NSUB_MAX; i++)\r
+           iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;\r
+   \r
+       iLBCdec_inst->last_lag = 20;\r
+   \r
+       iLBCdec_inst->prevLag = 120;\r
+       iLBCdec_inst->per = 0.0;\r
+       iLBCdec_inst->consPLICount = 0;\r
+       iLBCdec_inst->prevPLI = 0;\r
+       iLBCdec_inst->prevLpc[0] = 1.0;\r
+       memset(iLBCdec_inst->prevLpc+1,0,\r
+           LPC_FILTERORDER*sizeof(float));\r
+       memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));\r
+       iLBCdec_inst->seed=777;\r
+   \r
+       memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));\r
+   \r
+       iLBCdec_inst->use_enhancer = use_enhancer;\r
+       memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));\r
+       for (i=0;i<ENH_NBLOCKS_TOT;i++) \r
+           iLBCdec_inst->enh_period[i]=(float)40.0;\r
+   \r
+       iLBCdec_inst->prev_enh_pl = 0;\r
+   \r
+       return (iLBCdec_inst->blockl);\r
+   }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     61\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  frame residual decoder function (subrutine to iLBC_decode) \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void Decode(\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                                structure */\r
+       float *decresidual,             /* (o) decoded residual frame */\r
+       int start,                      /* (i) location of start \r
+                                              state */\r
+       int idxForMax,                  /* (i) codebook index for the \r
+                                              maximum value */\r
+       int *idxVec,                /* (i) codebook indexes for the \r
+                                              samples  in the start \r
+                                              state */\r
+       float *syntdenum,               /* (i) the decoded synthesis\r
+                                              filter coefficients */\r
+       int *cb_index,                  /* (i) the indexes for the \r
+                                              adaptive codebook */\r
+       int *gain_index,            /* (i) the indexes for the \r
+                                              corresponding gains */\r
+       int *extra_cb_index,        /* (i) the indexes for the \r
+                                              adaptive codebook part \r
+                                              of start state */\r
+       int *extra_gain_index,          /* (i) the indexes for the \r
+                                              corresponding gains */\r
+       int state_first                 /* (i) 1 if non adaptive part \r
+                                              of start state comes \r
+                                              first 0 if that part \r
+                                              comes last */\r
+   ){\r
+       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
+       int k, meml_gotten, Nfor, Nback, i;\r
+       int diff, start_pos;\r
+       int subcount, subframe;\r
+   \r
+       diff = STATE_LEN - iLBCdec_inst->state_short_len;\r
+       \r
+       if (state_first == 1) {\r
+           start_pos = (start-1)*SUBL;\r
+       } else {\r
+           start_pos = (start-1)*SUBL + diff;\r
+       }\r
+   \r
+       /* decode scalar part of start state */\r
+   \r
+       StateConstructW(idxForMax, idxVec, \r
+           &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+           &decresidual[start_pos], iLBCdec_inst->state_short_len);\r
+   \r
+       \r
+       if (state_first) { /* put adaptive part in the end */\r
+                   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     62\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, \r
+               (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));\r
+           memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, \r
+               decresidual+start_pos, \r
+               iLBCdec_inst->state_short_len*sizeof(float));\r
+           \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(\r
+               &decresidual[start_pos+iLBCdec_inst->state_short_len],\r
+               extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,\r
+               stMemLTbl, diff, CB_NSTAGES);\r
+       \r
+       } \r
+       else {/* put adaptive part in the beginning */\r
+           \r
+           /* create reversed vectors for prediction */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               reverseDecresidual[k] = \r
+                   decresidual[(start+1)*SUBL-1-\r
+                           (k+iLBCdec_inst->state_short_len)];\r
+           }\r
+           \r
+           /* setup memory */\r
+   \r
+           meml_gotten = iLBCdec_inst->state_short_len;\r
+           for (k=0; k<meml_gotten; k++){ \r
+               mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
+           } \r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+           \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(reverseDecresidual, extra_cb_index, \r
+               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,\r
+               diff, CB_NSTAGES);\r
+           \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               decresidual[start_pos-1-k] = reverseDecresidual[k];\r
+           }\r
+       }\r
+   \r
+       /* counter for predicted sub-frames */\r
+   \r
+       subcount=0;\r
+   \r
+       /* forward prediction of sub-frames */\r
+   \r
+       Nfor = iLBCdec_inst->nsub-start-1;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     63\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       \r
+       if ( Nfor > 0 ){\r
+           \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
+           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,\r
+               STATE_LEN*sizeof(float));\r
+   \r
+           /* loop over sub-frames to encode */\r
+   \r
+           for (subframe=0; subframe<Nfor; subframe++) {\r
+               \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &decresidual[(start+1+subframe)*SUBL],\r
+                   SUBL*sizeof(float));\r
+   \r
+               subcount++;\r
+   \r
+           }\r
+   \r
+       }\r
+       \r
+       /* backward prediction of sub-frames */\r
+   \r
+       Nback = start-1;\r
+   \r
+       if ( Nback > 0 ) {\r
+   \r
+           /* setup memory */\r
+   \r
+           meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);\r
+           \r
+           if ( meml_gotten > CB_MEML ) { \r
+               meml_gotten=CB_MEML;\r
+           }\r
+           for (k=0; k<meml_gotten; k++) { \r
+               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
+           }\r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+   \r
+           /* loop over subframes to decode */\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     64\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           for (subframe=0; subframe<Nback; subframe++) {\r
+               \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount], \r
+                   SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &reverseDecresidual[subframe*SUBL],\r
+                   SUBL*sizeof(float));\r
+   \r
+               subcount++;\r
+           }\r
+   \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (i=0; i<SUBL*Nback; i++)\r
+               decresidual[SUBL*Nback - i - 1] = \r
+               reverseDecresidual[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  main decoder function \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iLBC_decode( \r
+       float *decblock,            /* (o) decoded signal block */\r
+       unsigned char *bytes,           /* (i) encoded signal bits */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                                structure */\r
+       int mode                    /* (i) 0: bad packet, PLC, \r
+                                              1: normal */\r
+   ){\r
+       float data[BLOCKL_MAX];\r
+       float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];\r
+       float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];\r
+       float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];\r
+       int k, i, start, idxForMax, pos, lastpart, ulp;\r
+       int lag, ilag;\r
+       float cc, maxcc;\r
+       int idxVec[STATE_LEN];\r
+       int check;\r
+       int gain_index[NASUB_MAX*CB_NSTAGES], \r
+           extra_gain_index[CB_NSTAGES];\r
+       int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];\r
+       int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
+       int state_first;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     65\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       int last_bit;\r
+       unsigned char *pbytes;\r
+       float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
+       int order_plus_one;\r
+       float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+       float decresidual[BLOCKL_MAX];\r
+       \r
+       if (mode>0) { /* the data are good */\r
+   \r
+           /* decode data */\r
+           \r
+           pbytes=bytes;\r
+           pos=0;\r
+   \r
+           /* Set everything to zero before decoding */\r
+   \r
+           for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {\r
+               lsf_i[k]=0;\r
+           }\r
+           start=0;\r
+           state_first=0;\r
+           idxForMax=0;\r
+           for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
+               idxVec[k]=0;\r
+           }\r
+           for (k=0; k<CB_NSTAGES; k++) {\r
+               extra_cb_index[k]=0;\r
+           }\r
+           for (k=0; k<CB_NSTAGES; k++) {\r
+               extra_gain_index[k]=0;\r
+           }\r
+           for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   cb_index[i*CB_NSTAGES+k]=0;\r
+               }\r
+           }\r
+           for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   gain_index[i*CB_NSTAGES+k]=0;\r
+               }\r
+           }\r
+   \r
+           /* loop over ULP classes */\r
+   \r
+           for (ulp=0; ulp<3; ulp++) {\r
+           \r
+               /* LSF */\r
+               for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
+                   packcombine(&lsf_i[k], lastpart,\r
+                       iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);\r
+               }\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     66\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               /* Start block info */\r
+   \r
+               unpack( &pbytes, &lastpart, \r
+                   iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);\r
+               packcombine(&start, lastpart, \r
+                   iLBCdec_inst->ULP_inst->start_bits[ulp]);\r
+   \r
+               unpack( &pbytes, &lastpart, \r
+                   iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
+               packcombine(&state_first, lastpart,\r
+                   iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);\r
+   \r
+               unpack( &pbytes, &lastpart, \r
+                   iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);\r
+               packcombine(&idxForMax, lastpart, \r
+                   iLBCdec_inst->ULP_inst->scale_bits[ulp]);\r
+   \r
+               for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);\r
+                   packcombine(idxVec+k, lastpart,\r
+                       iLBCdec_inst->ULP_inst->state_bits[ulp]);\r
+               }\r
+   \r
+               /* 23/22 (20ms/30ms) sample block */\r
+   \r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                       &pos);\r
+                   packcombine(extra_cb_index+k, lastpart, \r
+                       iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);\r
+               }\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                       &pos);\r
+                   packcombine(extra_gain_index+k, lastpart,\r
+                       iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);\r
+               }\r
+                   \r
+               /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
+   \r
+               for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+                   for (k=0; k<CB_NSTAGES; k++) {\r
+                       unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->cb_index[i][k][ulp], \r
+                           &pos);\r
+                       packcombine(cb_index+i*CB_NSTAGES+k, lastpart, \r
+                       iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);\r
+                   }\r
+               }\r
+               \r
+               for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     67\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                   for (k=0; k<CB_NSTAGES; k++) {\r
+                       unpack( &pbytes, &lastpart, \r
+   \r
+                       iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                           &pos);\r
+                       packcombine(gain_index+i*CB_NSTAGES+k, lastpart,\r
+                           iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);\r
+                   }\r
+               }\r
+           }\r
+           /* Extract last bit. If it is 1 this indicates an \r
+              empty/lost frame */\r
+           unpack( &pbytes, &last_bit, 1, &pos);\r
+   \r
+           /* Check for bit errors or empty/lost frames */\r
+           if (start<1)\r
+               mode = 0;\r
+           if (iLBCdec_inst->mode==20 && start>3)\r
+               mode = 0;\r
+           if (iLBCdec_inst->mode==30 && start>5)\r
+               mode = 0;\r
+           if (last_bit==1)\r
+               mode = 0;\r
+   \r
+           if (mode==1) { /* No bit errors was detected, \r
+                             continue decoding */\r
+                   \r
+               /* adjust index */\r
+               index_conv_dec(cb_index);\r
+   \r
+               /* decode the lsf */\r
+   \r
+               SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);\r
+               check=LSF_check(lsfdeq, LPC_FILTERORDER, \r
+                   iLBCdec_inst->lpc_n);\r
+               DecoderInterpolateLSF(syntdenum, weightdenum, \r
+                   lsfdeq, LPC_FILTERORDER, iLBCdec_inst);\r
+           \r
+               Decode(iLBCdec_inst, decresidual, start, idxForMax, \r
+                   idxVec, syntdenum, cb_index, gain_index, \r
+                   extra_cb_index, extra_gain_index, \r
+                   state_first);\r
+   \r
+               /* preparing the plc for a future loss! */\r
+   \r
+               doThePLC(PLCresidual, PLClpc, 0, decresidual, \r
+                   syntdenum + \r
+                   (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),\r
+                   (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
+   \r
+           \r
+               memcpy(decresidual, PLCresidual, \r
+                   iLBCdec_inst->blockl*sizeof(float));\r
+           }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     68\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           \r
+       }\r
+       \r
+       if (mode == 0) {\r
+           /* the data is bad (either a PLC call\r
+            * was made or a severe bit error was detected)\r
+            */\r
+           \r
+           /* packet loss conceal */\r
+   \r
+           memset(zeros, 0, BLOCKL_MAX*sizeof(float));\r
+           \r
+           one[0] = 1;\r
+           memset(one+1, 0, LPC_FILTERORDER*sizeof(float));\r
+           \r
+           start=0;\r
+           \r
+           doThePLC(PLCresidual, PLClpc, 1, zeros, one,\r
+               (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
+           memcpy(decresidual, PLCresidual, \r
+               iLBCdec_inst->blockl*sizeof(float));\r
+           \r
+           order_plus_one = LPC_FILTERORDER + 1;\r
+           for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
+               memcpy(syntdenum+(i*order_plus_one), PLClpc, \r
+                   order_plus_one*sizeof(float));\r
+           }\r
+       }\r
+   \r
+       if (iLBCdec_inst->use_enhancer == 1) {\r
+   \r
+           /* post filtering */\r
+           \r
+           iLBCdec_inst->last_lag = \r
+               enhancerInterface(data, decresidual, iLBCdec_inst);\r
+   \r
+           /* synthesis filtering */\r
+           \r
+           if (iLBCdec_inst->mode==20) {\r
+               /* Enhancer has 40 samples delay */\r
+               i=0;\r
+               syntFilter(data + i*SUBL, \r
+                   iLBCdec_inst->old_syntdenum + \r
+                   (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), \r
+                   SUBL, iLBCdec_inst->syntMem);\r
+               for (i=1; i < iLBCdec_inst->nsub; i++) {\r
+                   syntFilter(data + i*SUBL, \r
+                       syntdenum + (i-1)*(LPC_FILTERORDER+1), \r
+                       SUBL, iLBCdec_inst->syntMem);\r
+               }\r
+           } else if (iLBCdec_inst->mode==30) {\r
+               /* Enhancer has 80 samples delay */\r
+               for (i=0; i < 2; i++) {\r
+                   syntFilter(data + i*SUBL, \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     69\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                       iLBCdec_inst->old_syntdenum + \r
+                       (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),\r
+                       SUBL, iLBCdec_inst->syntMem);\r
+               }\r
+               for (i=2; i < iLBCdec_inst->nsub; i++) {\r
+                   syntFilter(data + i*SUBL, \r
+                       syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,\r
+                       iLBCdec_inst->syntMem);\r
+               }\r
+           }\r
+   \r
+       } else {\r
+   \r
+           /* Find last lag */\r
+           lag = 20;\r
+           maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
+               &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);\r
+           \r
+           for (ilag=21; ilag<120; ilag++) {\r
+               cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
+                   &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], \r
+                   ENH_BLOCKL);\r
+           \r
+               if (cc > maxcc) {\r
+                   maxcc = cc;\r
+                   lag = ilag;\r
+               }\r
+           }\r
+           iLBCdec_inst->last_lag = lag;\r
+   \r
+           /* copy data and run synthesis filter */\r
+   \r
+           memcpy(data, decresidual, \r
+               iLBCdec_inst->blockl*sizeof(float));\r
+           for (i=0; i < iLBCdec_inst->nsub; i++) {\r
+               syntFilter(data + i*SUBL, \r
+                   syntdenum + i*(LPC_FILTERORDER+1), SUBL, \r
+                   iLBCdec_inst->syntMem);\r
+           }\r
+       }\r
+   \r
+       /* high pass filtering on output if desired, otherwise \r
+          copy to out */\r
+   \r
+       hpOutput(data, iLBCdec_inst->blockl, \r
+                   decblock,iLBCdec_inst->hpomem);\r
+   \r
+       /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/\r
+   \r
+       memcpy(iLBCdec_inst->old_syntdenum, syntdenum, \r
+   \r
+           iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));\r
+   \r
+       iLBCdec_inst->prev_enh_pl=0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     70\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+       if (mode==0) { /* PLC was used */\r
+           iLBCdec_inst->prev_enh_pl=1;\r
+       }\r
+   }\r
+   \r
+   \r
+A.6 iLBC_define.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_define.h    \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   #include <string.h>\r
+   \r
+   #ifndef __iLBC_ILBCDEFINE_H\r
+   #define __iLBC_ILBCDEFINE_H\r
+   \r
+   /* general codec settings */\r
+   \r
+   #define FS                      (float)8000.0\r
+   #define BLOCKL_20MS             160\r
+   #define BLOCKL_30MS             240\r
+   #define BLOCKL_MAX              240\r
+   #define NSUB_20MS               4\r
+   #define NSUB_30MS               6\r
+   #define NSUB_MAX            6\r
+   #define NASUB_20MS              2\r
+   #define NASUB_30MS              4\r
+   #define NASUB_MAX               4\r
+   #define SUBL                40\r
+   #define STATE_LEN               80\r
+   #define STATE_SHORT_LEN_30MS    58\r
+   #define STATE_SHORT_LEN_20MS    57\r
+   \r
+   /* LPC settings */\r
+   \r
+   #define LPC_FILTERORDER         10\r
+   #define LPC_CHIRP_SYNTDENUM     (float)0.9025\r
+   #define LPC_CHIRP_WEIGHTDENUM   (float)0.4222\r
+   #define LPC_LOOKBACK        60\r
+   #define LPC_N_20MS              1\r
+   #define LPC_N_30MS              2\r
+   #define LPC_N_MAX               2\r
+   #define LPC_ASYMDIFF        20\r
+   #define LPC_BW                  (float)60.0\r
+   #define LPC_WN                  (float)1.0001\r
+   #define LSF_NSPLIT              3\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     71\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   #define LSF_NUMBER_OF_STEPS     4\r
+   #define LPC_HALFORDER           (LPC_FILTERORDER/2)\r
+   \r
+   /* cb settings */\r
+   \r
+   #define CB_NSTAGES              3\r
+   #define CB_EXPAND               2\r
+   #define CB_MEML                 147\r
+   #define CB_FILTERLEN        2*4\r
+   #define CB_HALFFILTERLEN    4\r
+   #define CB_RESRANGE             34\r
+   #define CB_MAXGAIN              (float)1.3 \r
+   \r
+   /* enhancer */\r
+   \r
+   #define ENH_BLOCKL              80  /* block length */\r
+   #define ENH_BLOCKL_HALF         (ENH_BLOCKL/2)\r
+   #define ENH_HL                  3   /* 2*ENH_HL+1 is number blocks\r
+                                          in said second sequence */\r
+   #define ENH_SLOP            2   /* max difference estimated and\r
+                                          correct pitch period */\r
+   #define ENH_PLOCSL              20  /* pitch-estimates and pitch-\r
+                                          locations buffer length */\r
+   #define ENH_OVERHANG        2\r
+   #define ENH_UPS0            4   /* upsampling rate */\r
+   #define ENH_FL0                 3   /* 2*FLO+1 is the length of \r
+                                          each filter */\r
+   #define ENH_VECTL               (ENH_BLOCKL+2*ENH_FL0)\r
+   #define ENH_CORRDIM             (2*ENH_SLOP+1)\r
+   #define ENH_NBLOCKS             (BLOCKL_MAX/ENH_BLOCKL)\r
+   #define ENH_NBLOCKS_EXTRA       5\r
+   #define ENH_NBLOCKS_TOT         8   /* ENH_NBLOCKS + \r
+                                          ENH_NBLOCKS_EXTRA */\r
+   #define ENH_BUFL            (ENH_NBLOCKS_TOT)*ENH_BLOCKL\r
+   #define ENH_ALPHA0              (float)0.05\r
+   \r
+   /* Down sampling */\r
+   \r
+   #define FILTERORDER_DS          7\r
+   #define DELAY_DS            3\r
+   #define FACTOR_DS               2\r
+   \r
+   /* bit stream defs */\r
+   \r
+   #define NO_OF_BYTES_20MS    38\r
+   #define NO_OF_BYTES_30MS    50\r
+   #define NO_OF_WORDS_20MS    19\r
+   #define NO_OF_WORDS_30MS    25\r
+   #define STATE_BITS              3\r
+   #define BYTE_LEN            8\r
+   #define ULP_CLASSES             3\r
+   \r
+   /* help parameters */\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     72\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   #define FLOAT_MAX               (float)1.0e37\r
+   #define EPS                     (float)2.220446049250313e-016\r
+   #define PI                      (float)3.14159265358979323846\r
+   #define MIN_SAMPLE              -32768\r
+   #define MAX_SAMPLE              32767\r
+   #define TWO_PI                  (float)6.283185307\r
+   #define PI2                     (float)0.159154943\r
+   \r
+   /* type definition encoder instance */\r
+   typedef struct iLBC_ULP_Inst_t_ {\r
+       int lsf_bits[6][ULP_CLASSES+2];\r
+       int start_bits[ULP_CLASSES+2];\r
+       int startfirst_bits[ULP_CLASSES+2];\r
+       int scale_bits[ULP_CLASSES+2];\r
+       int state_bits[ULP_CLASSES+2];\r
+       int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];\r
+       int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];\r
+       int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
+       int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
+   } iLBC_ULP_Inst_t;\r
+   \r
+   /* type definition encoder instance */\r
+   typedef struct iLBC_Enc_Inst_t_ {\r
+   \r
+       /* flag for frame size mode */\r
+       int mode;\r
+   \r
+       /* basic parameters for different frame sizes */\r
+       int blockl;\r
+       int nsub;\r
+       int nasub;\r
+       int no_of_bytes, no_of_words;\r
+       int lpc_n;\r
+       int state_short_len;\r
+       const iLBC_ULP_Inst_t *ULP_inst;\r
+   \r
+       /* analysis filter state */\r
+       float anaMem[LPC_FILTERORDER];\r
+   \r
+       /* old lsf parameters for interpolation */\r
+       float lsfold[LPC_FILTERORDER];\r
+       float lsfdeqold[LPC_FILTERORDER];\r
+   \r
+       /* signal buffer for LP analysis */\r
+       float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];\r
+   \r
+       /* state of input HP filter */\r
+       float hpimem[4];\r
+   \r
+   } iLBC_Enc_Inst_t;\r
+   \r
+   /* type definition decoder instance */\r
+   typedef struct iLBC_Dec_Inst_t_ {\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     73\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       /* flag for frame size mode */\r
+       int mode;\r
+   \r
+       /* basic parameters for different frame sizes */\r
+       int blockl;\r
+       int nsub;\r
+       int nasub;\r
+       int no_of_bytes, no_of_words;\r
+       int lpc_n;\r
+       int state_short_len;\r
+       const iLBC_ULP_Inst_t *ULP_inst;\r
+   \r
+       /* synthesis filter state */\r
+       float syntMem[LPC_FILTERORDER];\r
+   \r
+       /* old LSF for interpolation */\r
+       float lsfdeqold[LPC_FILTERORDER];\r
+   \r
+       /* pitch lag estimated in enhancer and used in PLC */\r
+       int last_lag;\r
+   \r
+       /* PLC state information */\r
+       int prevLag, consPLICount, prevPLI, prev_enh_pl;\r
+       float prevLpc[LPC_FILTERORDER+1];\r
+       float prevResidual[NSUB_MAX*SUBL];\r
+       float per;\r
+       unsigned long seed;\r
+   \r
+       /* previous synthesis filter parameters */\r
+       float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
+   \r
+       /* state of output HP filter */\r
+       float hpomem[4];\r
+   \r
+       /* enhancer state information */\r
+       int use_enhancer;\r
+       float enh_buf[ENH_BUFL];\r
+       float enh_period[ENH_NBLOCKS_TOT];\r
+   \r
+   } iLBC_Dec_Inst_t;\r
+   \r
+   #endif\r
+   \r
+   \r
+A.7 constants.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       constants.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     74\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_CONSTANTS_H\r
+   #define __iLBC_CONSTANTS_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   \r
+   /* ULP bit allocation */\r
+   \r
+   extern const iLBC_ULP_Inst_t ULP_20msTbl;\r
+   extern const iLBC_ULP_Inst_t ULP_30msTbl;\r
+   \r
+   /* high pass filters */\r
+   \r
+   extern float hpi_zero_coefsTbl[];\r
+   extern float hpi_pole_coefsTbl[];\r
+   extern float hpo_zero_coefsTbl[];\r
+   extern float hpo_pole_coefsTbl[];  \r
+   \r
+   /* low pass filters */\r
+   extern float lpFilt_coefsTbl[];\r
+   \r
+   /* LPC analysis and quantization */\r
+   \r
+   extern float lpc_winTbl[];\r
+   extern float lpc_asymwinTbl[];\r
+   extern float lpc_lagwinTbl[];\r
+   extern float lsfCbTbl[];\r
+   extern float lsfmeanTbl[];\r
+   extern int   dim_lsfCbTbl[];\r
+   extern int   size_lsfCbTbl[];\r
+   extern float lsf_weightTbl_30ms[]; \r
+   extern float lsf_weightTbl_20ms[];\r
+   \r
+   /* state quantization tables */\r
+   \r
+   extern float state_sq3Tbl[];\r
+   extern float state_frgqTbl[];\r
+   \r
+   /* gain quantization tables */\r
+   \r
+   extern float gain_sq3Tbl[];\r
+   extern float gain_sq4Tbl[];\r
+   extern float gain_sq5Tbl[];\r
+   \r
+   /* adaptive codebook definitions */\r
+   \r
+   extern int search_rangeTbl[5][CB_NSTAGES];\r
+   extern int memLfTbl[];\r
+   extern int stMemLTbl;\r
+   extern float cbfiltersTbl[CB_FILTERLEN];\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     75\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   /* enhancer definitions */\r
+   \r
+   extern float polyphaserTbl[];\r
+   extern float enh_plocsTbl[];\r
+   \r
+   #endif\r
+   \r
+A.8 constants.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       constants.c\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /* ULP bit allocation */\r
+   \r
+       /* 20 ms frame */\r
+   \r
+   const iLBC_ULP_Inst_t ULP_20msTbl = {\r
+       /* LSF */\r
+       {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
+           {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+       /* Start state location, gain and samples */\r
+       {2,0,0,0,0},\r
+       {1,0,0,0,0},\r
+       {6,0,0,0,0},\r
+       {0,1,2,0,0},\r
+       /* extra CB index and extra CB gain */\r
+       {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+       {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+       /* CB index and CB gain */\r
+       {   {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+           {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},\r
+       {   {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+           {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},\r
+           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}\r
+   };\r
+   \r
+       /* 30 ms frame */\r
+   \r
+   const iLBC_ULP_Inst_t ULP_30msTbl = {\r
+       /* LSF */\r
+       {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     76\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},\r
+       /* Start state location, gain and samples */\r
+       {3,0,0,0,0},\r
+       {1,0,0,0,0},\r
+       {6,0,0,0,0},\r
+       {0,1,2,0,0},\r
+       /* extra CB index and extra CB gain */\r
+       {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+       {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},\r
+       /* CB index and CB gain */\r
+       {   {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},\r
+           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},\r
+           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},\r
+       {   {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},\r
+           {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},\r
+           {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},\r
+           {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}\r
+   };\r
+   \r
+   /* HP Filters */\r
+   \r
+   float hpi_zero_coefsTbl[3] = {\r
+       (float)0.92727436, (float)-1.8544941, (float)0.92727436\r
+   };\r
+   float hpi_pole_coefsTbl[3] = {\r
+       (float)1.0, (float)-1.9059465, (float)0.9114024\r
+   };\r
+   float hpo_zero_coefsTbl[3] = {\r
+       (float)0.93980581, (float)-1.8795834, (float)0.93980581\r
+   };\r
+   float hpo_pole_coefsTbl[3] = {\r
+       (float)1.0, (float)-1.9330735, (float)0.93589199\r
+   };\r
+   \r
+   /* LP Filter */\r
+   \r
+   float lpFilt_coefsTbl[FILTERORDER_DS]={\r
+       (float)-0.066650, (float)0.125000, (float)0.316650, \r
+       (float)0.414063, (float)0.316650, \r
+       (float)0.125000, (float)-0.066650\r
+   };\r
+   \r
+   /* State quantization tables */\r
+   \r
+   float state_sq3Tbl[8] = {\r
+       (float)-3.719849, (float)-2.177490, (float)-1.130005, \r
+       (float)-0.309692, (float)0.444214, (float)1.329712, \r
+       (float)2.436279, (float)3.983887\r
+   };\r
+   \r
+   float state_frgqTbl[64] = {\r
+       (float)1.000085, (float)1.071695, (float)1.140395, \r
+       (float)1.206868, (float)1.277188, (float)1.351503, \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     77\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       (float)1.429380, (float)1.500727, (float)1.569049, \r
+       (float)1.639599, (float)1.707071, (float)1.781531, \r
+       (float)1.840799, (float)1.901550, (float)1.956695, \r
+       (float)2.006750, (float)2.055474, (float)2.102787, \r
+       (float)2.142819, (float)2.183592, (float)2.217962, \r
+       (float)2.257177, (float)2.295739, (float)2.332967, \r
+       (float)2.369248, (float)2.402792, (float)2.435080, \r
+       (float)2.468598, (float)2.503394, (float)2.539284, \r
+       (float)2.572944, (float)2.605036, (float)2.636331, \r
+       (float)2.668939, (float)2.698780, (float)2.729101, \r
+       (float)2.759786, (float)2.789834, (float)2.818679, \r
+       (float)2.848074, (float)2.877470, (float)2.906899, \r
+       (float)2.936655, (float)2.967804, (float)3.000115, \r
+       (float)3.033367, (float)3.066355, (float)3.104231, \r
+       (float)3.141499, (float)3.183012, (float)3.222952, \r
+       (float)3.265433, (float)3.308441, (float)3.350823, \r
+       (float)3.395275, (float)3.442793, (float)3.490801, \r
+       (float)3.542514, (float)3.604064, (float)3.666050, \r
+       (float)3.740994, (float)3.830749, (float)3.938770, \r
+       (float)4.101764\r
+   };\r
+   \r
+   /* CB tables */\r
+   \r
+   int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, \r
+               {108,108,108}, {108,108,108}, {108,108,108}};\r
+   int stMemLTbl=85;\r
+   int memLfTbl[NASUB_MAX]={147,147,147,147};\r
+   \r
+   /* expansion filter(s) */\r
+   \r
+   float cbfiltersTbl[CB_FILTERLEN]={\r
+       (float)-0.034180, (float)0.108887, (float)-0.184326,\r
+       (float)0.806152,  (float)0.713379, (float)-0.144043,\r
+       (float)0.083740,  (float)-0.033691\r
+   };\r
+   \r
+   /* Gain Quantization */\r
+   \r
+   float gain_sq3Tbl[8]={\r
+       (float)-1.000000,  (float)-0.659973,  (float)-0.330017,\r
+       (float)0.000000, (float)0.250000, (float)0.500000, \r
+       (float)0.750000, (float)1.00000};\r
+   \r
+   float gain_sq4Tbl[16]={\r
+       (float)-1.049988, (float)-0.900024, (float)-0.750000, \r
+       (float)-0.599976, (float)-0.450012, (float)-0.299988, \r
+       (float)-0.150024, (float)0.000000, (float)0.150024, \r
+       (float)0.299988, (float)0.450012, (float)0.599976, \r
+       (float)0.750000, (float)0.900024, (float)1.049988, \r
+       (float)1.200012};\r
+   \r
+   float gain_sq5Tbl[32]={\r
+       (float)0.037476, (float)0.075012, (float)0.112488, \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     78\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       (float)0.150024, (float)0.187500, (float)0.224976, \r
+       (float)0.262512, (float)0.299988, (float)0.337524, \r
+       (float)0.375000, (float)0.412476, (float)0.450012, \r
+       (float)0.487488, (float)0.525024, (float)0.562500, \r
+       (float)0.599976, (float)0.637512, (float)0.674988, \r
+       (float)0.712524, (float)0.750000, (float)0.787476, \r
+       (float)0.825012, (float)0.862488, (float)0.900024, \r
+       (float)0.937500, (float)0.974976, (float)1.012512, \r
+       (float)1.049988, (float)1.087524, (float)1.125000, \r
+       (float)1.162476, (float)1.200012};\r
+   \r
+   /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */\r
+   float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ \r
+       (float)0.000000, (float)0.000000, (float)0.000000,\r
+   (float)1.000000, \r
+           (float)0.000000, (float)0.000000, (float)0.000000, \r
+       (float)0.015625, (float)-0.076904, (float)0.288330,\r
+   (float)0.862061, \r
+           (float)-0.106445, (float)0.018799, (float)-0.015625, \r
+       (float)0.023682, (float)-0.124268, (float)0.601563,\r
+   (float)0.601563, \r
+           (float)-0.124268, (float)0.023682, (float)-0.023682, \r
+       (float)0.018799, (float)-0.106445, (float)0.862061,\r
+   (float)0.288330, \r
+           (float)-0.076904, (float)0.015625, (float)-0.018799};\r
+   \r
+   float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, \r
+               (float)200.0, (float)280.0, (float)360.0, \r
+               (float)440.0, (float)520.0, (float)600.0};\r
+   \r
+   /* LPC analysis and quantization */ \r
+   \r
+   int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};\r
+   int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};\r
+   \r
+   \r
+   float lsfmeanTbl[LPC_FILTERORDER] = { \r
+       (float)0.281738, (float)0.445801, (float)0.663330, \r
+       (float)0.962524, (float)1.251831, (float)1.533081, \r
+       (float)1.850586, (float)2.137817, (float)2.481445, \r
+       (float)2.777344};\r
+   \r
+   float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,\r
+   (float)(2.0/3.0), \r
+       (float)(1.0/3.0), (float)0.0, (float)0.0};\r
+   \r
+   float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), \r
+       (float)(1.0/4.0), (float)(0.0)};\r
+   \r
+   /* Hanning LPC window */\r
+   float lpc_winTbl[BLOCKL_MAX]={\r
+       (float)0.000183, (float)0.000671, (float)0.001526,\r
+       (float)0.002716, (float)0.004242, (float)0.006104,\r
+       (float)0.008301, (float)0.010834, (float)0.013702,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     79\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       (float)0.016907, (float)0.020416, (float)0.024261,\r
+       (float)0.028442, (float)0.032928, (float)0.037750,\r
+       (float)0.042877, (float)0.048309, (float)0.054047,\r
+       (float)0.060089, (float)0.066437, (float)0.073090,\r
+       (float)0.080017, (float)0.087219, (float)0.094727,\r
+       (float)0.102509, (float)0.110535, (float)0.118835,\r
+       (float)0.127411, (float)0.136230, (float)0.145294,\r
+       (float)0.154602, (float)0.164154, (float)0.173920,\r
+       (float)0.183899, (float)0.194122, (float)0.204529,\r
+       (float)0.215149, (float)0.225952, (float)0.236938,\r
+       (float)0.248108, (float)0.259460, (float)0.270966,\r
+       (float)0.282654, (float)0.294464, (float)0.306396,\r
+       (float)0.318481, (float)0.330688, (float)0.343018,\r
+       (float)0.355438, (float)0.367981, (float)0.380585,\r
+       (float)0.393280, (float)0.406067, (float)0.418884,\r
+       (float)0.431763, (float)0.444702, (float)0.457672,\r
+       (float)0.470673, (float)0.483704, (float)0.496735,\r
+       (float)0.509766, (float)0.522797, (float)0.535828,\r
+       (float)0.548798, (float)0.561768, (float)0.574677,\r
+       (float)0.587524, (float)0.600342, (float)0.613068,\r
+       (float)0.625732, (float)0.638306, (float)0.650787,\r
+       (float)0.663147, (float)0.675415, (float)0.687561,\r
+       (float)0.699585, (float)0.711487, (float)0.723206,\r
+       (float)0.734802, (float)0.746216, (float)0.757477,\r
+       (float)0.768585, (float)0.779480, (float)0.790192,\r
+       (float)0.800720, (float)0.811005, (float)0.821106,\r
+       (float)0.830994, (float)0.840668, (float)0.850067,\r
+       (float)0.859253, (float)0.868225, (float)0.876892,\r
+       (float)0.885345, (float)0.893524, (float)0.901428,\r
+       (float)0.909058, (float)0.916412, (float)0.923492,\r
+       (float)0.930267, (float)0.936768, (float)0.942963,\r
+       (float)0.948853, (float)0.954437, (float)0.959717,\r
+       (float)0.964691, (float)0.969360, (float)0.973694,\r
+       (float)0.977692, (float)0.981384, (float)0.984741,\r
+       (float)0.987762, (float)0.990479, (float)0.992828,\r
+       (float)0.994873, (float)0.996552, (float)0.997925,\r
+       (float)0.998932, (float)0.999603, (float)0.999969,\r
+       (float)0.999969, (float)0.999603, (float)0.998932,\r
+       (float)0.997925, (float)0.996552, (float)0.994873,\r
+       (float)0.992828, (float)0.990479, (float)0.987762,\r
+       (float)0.984741, (float)0.981384, (float)0.977692,\r
+       (float)0.973694, (float)0.969360, (float)0.964691,\r
+       (float)0.959717, (float)0.954437, (float)0.948853,\r
+       (float)0.942963, (float)0.936768, (float)0.930267,\r
+       (float)0.923492, (float)0.916412, (float)0.909058,\r
+       (float)0.901428, (float)0.893524, (float)0.885345,\r
+       (float)0.876892, (float)0.868225, (float)0.859253,\r
+       (float)0.850067, (float)0.840668, (float)0.830994,\r
+       (float)0.821106, (float)0.811005, (float)0.800720,\r
+       (float)0.790192, (float)0.779480, (float)0.768585,\r
+       (float)0.757477, (float)0.746216, (float)0.734802,\r
+       (float)0.723206, (float)0.711487, (float)0.699585,\r
+       (float)0.687561, (float)0.675415, (float)0.663147,\r
+       (float)0.650787, (float)0.638306, (float)0.625732,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     80\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       (float)0.613068, (float)0.600342, (float)0.587524,\r
+       (float)0.574677, (float)0.561768, (float)0.548798,\r
+       (float)0.535828, (float)0.522797, (float)0.509766,\r
+       (float)0.496735, (float)0.483704, (float)0.470673,\r
+       (float)0.457672, (float)0.444702, (float)0.431763,\r
+       (float)0.418884, (float)0.406067, (float)0.393280,\r
+       (float)0.380585, (float)0.367981, (float)0.355438,\r
+       (float)0.343018, (float)0.330688, (float)0.318481,\r
+       (float)0.306396, (float)0.294464, (float)0.282654,\r
+       (float)0.270966, (float)0.259460, (float)0.248108,\r
+       (float)0.236938, (float)0.225952, (float)0.215149,\r
+       (float)0.204529, (float)0.194122, (float)0.183899,\r
+       (float)0.173920, (float)0.164154, (float)0.154602,\r
+       (float)0.145294, (float)0.136230, (float)0.127411,\r
+       (float)0.118835, (float)0.110535, (float)0.102509,\r
+       (float)0.094727, (float)0.087219, (float)0.080017,\r
+       (float)0.073090, (float)0.066437, (float)0.060089,\r
+       (float)0.054047, (float)0.048309, (float)0.042877,\r
+       (float)0.037750, (float)0.032928, (float)0.028442,\r
+       (float)0.024261, (float)0.020416, (float)0.016907,\r
+       (float)0.013702, (float)0.010834, (float)0.008301,\r
+       (float)0.006104, (float)0.004242, (float)0.002716,\r
+       (float)0.001526, (float)0.000671, (float)0.000183\r
+   };\r
+   \r
+   /* Asymmetric LPC window */\r
+   float lpc_asymwinTbl[BLOCKL_MAX]={\r
+       (float)0.000061, (float)0.000214, (float)0.000458,\r
+       (float)0.000824, (float)0.001282, (float)0.001831,\r
+       (float)0.002472, (float)0.003235, (float)0.004120,\r
+       (float)0.005066, (float)0.006134, (float)0.007294,\r
+       (float)0.008545, (float)0.009918, (float)0.011383,\r
+       (float)0.012939, (float)0.014587, (float)0.016357,\r
+       (float)0.018219, (float)0.020172, (float)0.022217,\r
+       (float)0.024353, (float)0.026611, (float)0.028961,\r
+       (float)0.031372, (float)0.033905, (float)0.036530,\r
+       (float)0.039276, (float)0.042084, (float)0.044983,\r
+       (float)0.047974, (float)0.051086, (float)0.054260,\r
+       (float)0.057526, (float)0.060883, (float)0.064331,\r
+       (float)0.067871, (float)0.071503, (float)0.075226,\r
+       (float)0.079010, (float)0.082916, (float)0.086884,\r
+       (float)0.090942, (float)0.095062, (float)0.099304,\r
+       (float)0.103607, (float)0.107971, (float)0.112427,\r
+       (float)0.116974, (float)0.121582, (float)0.126282,\r
+       (float)0.131073, (float)0.135895, (float)0.140839,\r
+       (float)0.145813, (float)0.150879, (float)0.156006,\r
+       (float)0.161224, (float)0.166504, (float)0.171844,\r
+       (float)0.177246, (float)0.182709, (float)0.188263,\r
+       (float)0.193848, (float)0.199524, (float)0.205231,\r
+       (float)0.211029, (float)0.216858, (float)0.222778,\r
+       (float)0.228729, (float)0.234741, (float)0.240814,\r
+       (float)0.246918, (float)0.253082, (float)0.259308,\r
+       (float)0.265564, (float)0.271881, (float)0.278259,\r
+       (float)0.284668, (float)0.291107, (float)0.297607,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     81\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       (float)0.304138, (float)0.310730, (float)0.317322,\r
+       (float)0.323975, (float)0.330658, (float)0.337372,\r
+       (float)0.344147, (float)0.350922, (float)0.357727,\r
+       (float)0.364594, (float)0.371460, (float)0.378357,\r
+       (float)0.385284, (float)0.392212, (float)0.399170,\r
+       (float)0.406158, (float)0.413177, (float)0.420197,\r
+       (float)0.427246, (float)0.434296, (float)0.441376,\r
+       (float)0.448456, (float)0.455536, (float)0.462646,\r
+       (float)0.469757, (float)0.476868, (float)0.483978,\r
+       (float)0.491089, (float)0.498230, (float)0.505341,\r
+       (float)0.512451, (float)0.519592, (float)0.526703,\r
+       (float)0.533813, (float)0.540924, (float)0.548004,\r
+       (float)0.555084, (float)0.562164, (float)0.569244,\r
+       (float)0.576294, (float)0.583313, (float)0.590332,\r
+       (float)0.597321, (float)0.604309, (float)0.611267,\r
+       (float)0.618195, (float)0.625092, (float)0.631989,\r
+       (float)0.638855, (float)0.645660, (float)0.652466,\r
+       (float)0.659241, (float)0.665985, (float)0.672668,\r
+       (float)0.679352, (float)0.685974, (float)0.692566,\r
+       (float)0.699127, (float)0.705658, (float)0.712128,\r
+       (float)0.718536, (float)0.724945, (float)0.731262,\r
+       (float)0.737549, (float)0.743805, (float)0.750000,\r
+       (float)0.756134, (float)0.762238, (float)0.768280,\r
+       (float)0.774261, (float)0.780182, (float)0.786072,\r
+       (float)0.791870, (float)0.797638, (float)0.803314,\r
+       (float)0.808960, (float)0.814514, (float)0.820038,\r
+       (float)0.825470, (float)0.830841, (float)0.836151,\r
+       (float)0.841400, (float)0.846558, (float)0.851654,\r
+       (float)0.856689, (float)0.861633, (float)0.866516,\r
+       (float)0.871338, (float)0.876068, (float)0.880737,\r
+       (float)0.885315, (float)0.889801, (float)0.894226,\r
+       (float)0.898560, (float)0.902832, (float)0.907013,\r
+       (float)0.911102, (float)0.915100, (float)0.919037,\r
+       (float)0.922882, (float)0.926636, (float)0.930328,\r
+       (float)0.933899, (float)0.937408, (float)0.940796,\r
+       (float)0.944122, (float)0.947357, (float)0.950470,\r
+       (float)0.953522, (float)0.956482, (float)0.959351,\r
+       (float)0.962097, (float)0.964783, (float)0.967377,\r
+       (float)0.969849, (float)0.972229, (float)0.974518,\r
+       (float)0.976715, (float)0.978821, (float)0.980835,\r
+       (float)0.982727, (float)0.984528, (float)0.986237,\r
+       (float)0.987854, (float)0.989380, (float)0.990784,\r
+       (float)0.992096, (float)0.993317, (float)0.994415,\r
+       (float)0.995422, (float)0.996338, (float)0.997162,\r
+       (float)0.997864, (float)0.998474, (float)0.998962,\r
+       (float)0.999390, (float)0.999695, (float)0.999878,\r
+       (float)0.999969, (float)0.999969, (float)0.996918,\r
+       (float)0.987701, (float)0.972382, (float)0.951050,\r
+       (float)0.923889, (float)0.891022, (float)0.852631,\r
+       (float)0.809021, (float)0.760406, (float)0.707092,\r
+       (float)0.649445, (float)0.587799, (float)0.522491,\r
+       (float)0.453979, (float)0.382690, (float)0.309021,\r
+       (float)0.233459, (float)0.156433, (float)0.078461\r
+   };\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     82\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   /* Lag window for LPC */\r
+   float lpc_lagwinTbl[LPC_FILTERORDER + 1]={\r
+       (float)1.000100, (float)0.998890, (float)0.995569,\r
+           (float)0.990057, (float)0.982392,\r
+       (float)0.972623, (float)0.960816, (float)0.947047,\r
+           (float)0.931405, (float)0.913989, (float)0.894909};\r
+   \r
+   /* LSF quantization*/\r
+   float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {\r
+   (float)0.155396, (float)0.273193, (float)0.451172,\r
+   (float)0.390503, (float)0.648071, (float)1.002075,\r
+   (float)0.440186, (float)0.692261, (float)0.955688,\r
+   (float)0.343628, (float)0.642334, (float)1.071533,\r
+   (float)0.318359, (float)0.491577, (float)0.670532,\r
+   (float)0.193115, (float)0.375488, (float)0.725708,\r
+   (float)0.364136, (float)0.510376, (float)0.658691,\r
+   (float)0.297485, (float)0.527588, (float)0.842529,\r
+   (float)0.227173, (float)0.365967, (float)0.563110,\r
+   (float)0.244995, (float)0.396729, (float)0.636475,\r
+   (float)0.169434, (float)0.300171, (float)0.520264,\r
+   (float)0.312866, (float)0.464478, (float)0.643188,\r
+   (float)0.248535, (float)0.429932, (float)0.626099,\r
+   (float)0.236206, (float)0.491333, (float)0.817139,\r
+   (float)0.334961, (float)0.625122, (float)0.895752,\r
+   (float)0.343018, (float)0.518555, (float)0.698608,\r
+   (float)0.372803, (float)0.659790, (float)0.945435,\r
+   (float)0.176880, (float)0.316528, (float)0.581421,\r
+   (float)0.416382, (float)0.625977, (float)0.805176,\r
+   (float)0.303223, (float)0.568726, (float)0.915039,\r
+   (float)0.203613, (float)0.351440, (float)0.588135,\r
+   (float)0.221191, (float)0.375000, (float)0.614746,\r
+   (float)0.199951, (float)0.323364, (float)0.476074,\r
+   (float)0.300781, (float)0.433350, (float)0.566895,\r
+   (float)0.226196, (float)0.354004, (float)0.507568,\r
+   (float)0.300049, (float)0.508179, (float)0.711670,\r
+   (float)0.312012, (float)0.492676, (float)0.763428,\r
+   (float)0.329956, (float)0.541016, (float)0.795776,\r
+   (float)0.373779, (float)0.604614, (float)0.928833,\r
+   (float)0.210571, (float)0.452026, (float)0.755249,\r
+   (float)0.271118, (float)0.473267, (float)0.662476,\r
+   (float)0.285522, (float)0.436890, (float)0.634399,\r
+   (float)0.246704, (float)0.565552, (float)0.859009,\r
+   (float)0.270508, (float)0.406250, (float)0.553589,\r
+   (float)0.361450, (float)0.578491, (float)0.813843,\r
+   (float)0.342651, (float)0.482788, (float)0.622437,\r
+   (float)0.340332, (float)0.549438, (float)0.743164,\r
+   (float)0.200439, (float)0.336304, (float)0.540894,\r
+   (float)0.407837, (float)0.644775, (float)0.895142,\r
+   (float)0.294678, (float)0.454834, (float)0.699097,\r
+   (float)0.193115, (float)0.344482, (float)0.643188,\r
+   (float)0.275757, (float)0.420776, (float)0.598755,\r
+   (float)0.380493, (float)0.608643, (float)0.861084,\r
+   (float)0.222778, (float)0.426147, (float)0.676514,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     83\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (float)0.407471, (float)0.700195, (float)1.053101,\r
+   (float)0.218384, (float)0.377197, (float)0.669922,\r
+   (float)0.313232, (float)0.454102, (float)0.600952,\r
+   (float)0.347412, (float)0.571533, (float)0.874146,\r
+   (float)0.238037, (float)0.405396, (float)0.729492,\r
+   (float)0.223877, (float)0.412964, (float)0.822021,\r
+   (float)0.395264, (float)0.582153, (float)0.743896,\r
+   (float)0.247925, (float)0.485596, (float)0.720581,\r
+   (float)0.229126, (float)0.496582, (float)0.907715,\r
+   (float)0.260132, (float)0.566895, (float)1.012695,\r
+   (float)0.337402, (float)0.611572, (float)0.978149,\r
+   (float)0.267822, (float)0.447632, (float)0.769287,\r
+   (float)0.250610, (float)0.381714, (float)0.530029,\r
+   (float)0.430054, (float)0.805054, (float)1.221924,\r
+   (float)0.382568, (float)0.544067, (float)0.701660,\r
+   (float)0.383545, (float)0.710327, (float)1.149170,\r
+   (float)0.271362, (float)0.529053, (float)0.775513,\r
+   (float)0.246826, (float)0.393555, (float)0.588623,\r
+   (float)0.266846, (float)0.422119, (float)0.676758,\r
+   (float)0.311523, (float)0.580688, (float)0.838623,\r
+   (float)1.331177, (float)1.576782, (float)1.779541,\r
+   (float)1.160034, (float)1.401978, (float)1.768188,\r
+   (float)1.161865, (float)1.525146, (float)1.715332,\r
+   (float)0.759521, (float)0.913940, (float)1.119873,\r
+   (float)0.947144, (float)1.121338, (float)1.282471,\r
+   (float)1.015015, (float)1.557007, (float)1.804932,\r
+   (float)1.172974, (float)1.402100, (float)1.692627,\r
+   (float)1.087524, (float)1.474243, (float)1.665405,\r
+   (float)0.899536, (float)1.105225, (float)1.406250,\r
+   (float)1.148438, (float)1.484741, (float)1.796265,\r
+   (float)0.785645, (float)1.209839, (float)1.567749,\r
+   (float)0.867798, (float)1.166504, (float)1.450684,\r
+   (float)0.922485, (float)1.229858, (float)1.420898,\r
+   (float)0.791260, (float)1.123291, (float)1.409546,\r
+   (float)0.788940, (float)0.966064, (float)1.340332,\r
+   (float)1.051147, (float)1.272827, (float)1.556641,\r
+   (float)0.866821, (float)1.181152, (float)1.538818,\r
+   (float)0.906738, (float)1.373535, (float)1.607910,\r
+   (float)1.244751, (float)1.581421, (float)1.933838,\r
+   (float)0.913940, (float)1.337280, (float)1.539673,\r
+   (float)0.680542, (float)0.959229, (float)1.662720,\r
+   (float)0.887207, (float)1.430542, (float)1.800781,\r
+   (float)0.912598, (float)1.433594, (float)1.683960,\r
+   (float)0.860474, (float)1.060303, (float)1.455322,\r
+   (float)1.005127, (float)1.381104, (float)1.706909,\r
+   (float)0.800781, (float)1.363892, (float)1.829102,\r
+   (float)0.781860, (float)1.124390, (float)1.505981,\r
+   (float)1.003662, (float)1.471436, (float)1.684692,\r
+   (float)0.981323, (float)1.309570, (float)1.618042,\r
+   (float)1.228760, (float)1.554321, (float)1.756470,\r
+   (float)0.734375, (float)0.895752, (float)1.225586,\r
+   (float)0.841797, (float)1.055664, (float)1.249268,\r
+   (float)0.920166, (float)1.119385, (float)1.486206,\r
+   (float)0.894409, (float)1.539063, (float)1.828979,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     84\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (float)1.283691, (float)1.543335, (float)1.858276,\r
+   (float)0.676025, (float)0.933105, (float)1.490845,\r
+   (float)0.821289, (float)1.491821, (float)1.739868,\r
+   (float)0.923218, (float)1.144653, (float)1.580566,\r
+   (float)1.057251, (float)1.345581, (float)1.635864,\r
+   (float)0.888672, (float)1.074951, (float)1.353149,\r
+   (float)0.942749, (float)1.195435, (float)1.505493,\r
+   (float)1.492310, (float)1.788086, (float)2.039673,\r
+   (float)1.070313, (float)1.634399, (float)1.860962,\r
+   (float)1.253296, (float)1.488892, (float)1.686035,\r
+   (float)0.647095, (float)0.864014, (float)1.401855,\r
+   (float)0.866699, (float)1.254883, (float)1.453369,\r
+   (float)1.063965, (float)1.532593, (float)1.731323,\r
+   (float)1.167847, (float)1.521484, (float)1.884033,\r
+   (float)0.956055, (float)1.502075, (float)1.745605,\r
+   (float)0.928711, (float)1.288574, (float)1.479614,\r
+   (float)1.088013, (float)1.380737, (float)1.570801,\r
+   (float)0.905029, (float)1.186768, (float)1.371948,\r
+   (float)1.057861, (float)1.421021, (float)1.617432,\r
+   (float)1.108276, (float)1.312500, (float)1.501465,\r
+   (float)0.979492, (float)1.416992, (float)1.624268,\r
+   (float)1.276001, (float)1.661011, (float)2.007935,\r
+   (float)0.993042, (float)1.168579, (float)1.331665,\r
+   (float)0.778198, (float)0.944946, (float)1.235962,\r
+   (float)1.223755, (float)1.491333, (float)1.815674,\r
+   (float)0.852661, (float)1.350464, (float)1.722290,\r
+   (float)1.134766, (float)1.593140, (float)1.787354,\r
+   (float)1.051392, (float)1.339722, (float)1.531006,\r
+   (float)0.803589, (float)1.271240, (float)1.652100,\r
+   (float)0.755737, (float)1.143555, (float)1.639404,\r
+   (float)0.700928, (float)0.837280, (float)1.130371,\r
+   (float)0.942749, (float)1.197876, (float)1.669800,\r
+   (float)0.993286, (float)1.378296, (float)1.566528,\r
+   (float)0.801025, (float)1.095337, (float)1.298950,\r
+   (float)0.739990, (float)1.032959, (float)1.383667,\r
+   (float)0.845703, (float)1.072266, (float)1.543823,\r
+   (float)0.915649, (float)1.072266, (float)1.224487,\r
+   (float)1.021973, (float)1.226196, (float)1.481323,\r
+   (float)0.999878, (float)1.204102, (float)1.555908,\r
+   (float)0.722290, (float)0.913940, (float)1.340210,\r
+   (float)0.673340, (float)0.835938, (float)1.259521,\r
+   (float)0.832397, (float)1.208374, (float)1.394165,\r
+   (float)0.962158, (float)1.576172, (float)1.912842,\r
+   (float)1.166748, (float)1.370850, (float)1.556763,\r
+   (float)0.946289, (float)1.138550, (float)1.400391,\r
+   (float)1.035034, (float)1.218262, (float)1.386475,\r
+   (float)1.393799, (float)1.717773, (float)2.000244,\r
+   (float)0.972656, (float)1.260986, (float)1.760620,\r
+   (float)1.028198, (float)1.288452, (float)1.484619,\r
+   (float)0.773560, (float)1.258057, (float)1.756714,\r
+   (float)1.080322, (float)1.328003, (float)1.742676,\r
+   (float)0.823975, (float)1.450806, (float)1.917725,\r
+   (float)0.859009, (float)1.016602, (float)1.191895,\r
+   (float)0.843994, (float)1.131104, (float)1.645020,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     85\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (float)1.189697, (float)1.702759, (float)1.894409,\r
+   (float)1.346680, (float)1.763184, (float)2.066040,\r
+   (float)0.980469, (float)1.253784, (float)1.441650,\r
+   (float)1.338135, (float)1.641968, (float)1.932739,\r
+   (float)1.223267, (float)1.424194, (float)1.626465,\r
+   (float)0.765747, (float)1.004150, (float)1.579102,\r
+   (float)1.042847, (float)1.269165, (float)1.647461,\r
+   (float)0.968750, (float)1.257568, (float)1.555786,\r
+   (float)0.826294, (float)0.993408, (float)1.275146,\r
+   (float)0.742310, (float)0.950439, (float)1.430542,\r
+   (float)1.054321, (float)1.439819, (float)1.828003,\r
+   (float)1.072998, (float)1.261719, (float)1.441895,\r
+   (float)0.859375, (float)1.036377, (float)1.314819,\r
+   (float)0.895752, (float)1.267212, (float)1.605591,\r
+   (float)0.805420, (float)0.962891, (float)1.142334,\r
+   (float)0.795654, (float)1.005493, (float)1.468506,\r
+   (float)1.105347, (float)1.313843, (float)1.584839,\r
+   (float)0.792236, (float)1.221802, (float)1.465698,\r
+   (float)1.170532, (float)1.467651, (float)1.664063,\r
+   (float)0.838257, (float)1.153198, (float)1.342163,\r
+   (float)0.968018, (float)1.198242, (float)1.391235,\r
+   (float)1.250122, (float)1.623535, (float)1.823608,\r
+   (float)0.711670, (float)1.058350, (float)1.512085,\r
+   (float)1.204834, (float)1.454468, (float)1.739136,\r
+   (float)1.137451, (float)1.421753, (float)1.620117,\r
+   (float)0.820435, (float)1.322754, (float)1.578247,\r
+   (float)0.798706, (float)1.005005, (float)1.213867,\r
+   (float)0.980713, (float)1.324951, (float)1.512939,\r
+   (float)1.112305, (float)1.438843, (float)1.735596,\r
+   (float)1.135498, (float)1.356689, (float)1.635742,\r
+   (float)1.101318, (float)1.387451, (float)1.686523,\r
+   (float)0.849854, (float)1.276978, (float)1.523438,\r
+   (float)1.377930, (float)1.627563, (float)1.858154,\r
+   (float)0.884888, (float)1.095459, (float)1.287476,\r
+   (float)1.289795, (float)1.505859, (float)1.756592,\r
+   (float)0.817505, (float)1.384155, (float)1.650513,\r
+   (float)1.446655, (float)1.702148, (float)1.931885,\r
+   (float)0.835815, (float)1.023071, (float)1.385376,\r
+   (float)0.916626, (float)1.139038, (float)1.335327,\r
+   (float)0.980103, (float)1.174072, (float)1.453735,\r
+   (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,\r
+   (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,\r
+   (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,\r
+   (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,\r
+   (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,\r
+   (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,\r
+   (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,\r
+   (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,\r
+   (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,\r
+   (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,\r
+   (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,\r
+   (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,\r
+   (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,\r
+   (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     86\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,\r
+   (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,\r
+   (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,\r
+   (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,\r
+   (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,\r
+   (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,\r
+   (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,\r
+   (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,\r
+   (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,\r
+   (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,\r
+   (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,\r
+   (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,\r
+   (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,\r
+   (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,\r
+   (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,\r
+   (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,\r
+   (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,\r
+   (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,\r
+   (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,\r
+   (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,\r
+   (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,\r
+   (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,\r
+   (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,\r
+   (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,\r
+   (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,\r
+   (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,\r
+   (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,\r
+   (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,\r
+   (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,\r
+   (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,\r
+   (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,\r
+   (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,\r
+   (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,\r
+   (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,\r
+   (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,\r
+   (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,\r
+   (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,\r
+   (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,\r
+   (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,\r
+   (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,\r
+   (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,\r
+   (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,\r
+   (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,\r
+   (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,\r
+   (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,\r
+   (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,\r
+   (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,\r
+   (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,\r
+   (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,\r
+   (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,\r
+   (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,\r
+   (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,\r
+   (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,\r
+   (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     87\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,\r
+   (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,\r
+   (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,\r
+   (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,\r
+   (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,\r
+   (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,\r
+   (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,\r
+   (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,\r
+   (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,\r
+   (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,\r
+   (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,\r
+   (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,\r
+   (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,\r
+   (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,\r
+   (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,\r
+   (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,\r
+   (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,\r
+   (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,\r
+   (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,\r
+   (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,\r
+   (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,\r
+   (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,\r
+   (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,\r
+   (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,\r
+   (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,\r
+   (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,\r
+   (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,\r
+   (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,\r
+   (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,\r
+   (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,\r
+   (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,\r
+   (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,\r
+   (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,\r
+   (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,\r
+   (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,\r
+   (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,\r
+   (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,\r
+   (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,\r
+   (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,\r
+   (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,\r
+   (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,\r
+   (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,\r
+   (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,\r
+   (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,\r
+   (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,\r
+   (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,\r
+   (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,\r
+   (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,\r
+   (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,\r
+   (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,\r
+   (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,\r
+   (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,\r
+   (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,\r
+   (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     88\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,\r
+   (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,\r
+   (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,\r
+   (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,\r
+   (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,\r
+   (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143\r
+   };\r
+   \r
+   \r
+A.9 anaFilter.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       anaFilter.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ANAFILTER_H\r
+   #define __iLBC_ANAFILTER_H\r
+   \r
+   void anaFilter(\r
+       float *In,  /* (i) Signal to be filtered */\r
+       float *a,   /* (i) LP parameters */\r
+       int len,/* (i) Length of signal */\r
+       float *Out, /* (o) Filtered signal */\r
+       float *mem  /* (i/o) Filter state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.10 anaFilter.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       anaFilter.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  LP analysis filter.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     89\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+    *---------------------------------------------------------------*/\r
+       \r
+   void anaFilter(\r
+       float *In,  /* (i) Signal to be filtered */\r
+       float *a,   /* (i) LP parameters */\r
+       int len,/* (i) Length of signal */\r
+       float *Out, /* (o) Filtered signal */\r
+       float *mem  /* (i/o) Filter state */\r
+   ){\r
+       int i, j;\r
+       float *po, *pi, *pm, *pa;\r
+   \r
+       po = Out;\r
+   \r
+       /* Filter first part using memory from past */\r
+       \r
+       for (i=0; i<LPC_FILTERORDER; i++) {\r
+           pi = &In[i];\r
+           pm = &mem[LPC_FILTERORDER-1];\r
+           pa = a;\r
+           *po=0.0;\r
+           for (j=0; j<=i; j++) {\r
+               *po+=(*pa++)*(*pi--);\r
+           }\r
+           for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
+   \r
+               *po+=(*pa++)*(*pm--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Filter last part where the state is entierly \r
+          in the input vector */\r
+   \r
+       for (i=LPC_FILTERORDER; i<len; i++) {\r
+           pi = &In[i];\r
+           pa = a;\r
+           *po=0.0;\r
+           for (j=0; j<LPC_FILTERORDER+1; j++) {\r
+               *po+=(*pa++)*(*pi--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Update state vector */\r
+   \r
+       memcpy(mem, &In[len-LPC_FILTERORDER], \r
+           LPC_FILTERORDER*sizeof(float));\r
+   }\r
+   \r
+   \r
+A.11 createCB.h\r
+   \r
+   /******************************************************************\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     90\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       createCB.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_CREATECB_H\r
+   #define __iLBC_CREATECB_H\r
+   \r
+   void filteredCBvecs(\r
+       float *cbvectors,   /* (o) Codebook vector for the \r
+                                  higher section */\r
+       float *mem,         /* (i) Buffer to create codebook \r
+                                  vectors from */\r
+       int lMem        /* (i) Length of buffer */\r
+   );\r
+   \r
+   void searchAugmentedCB(\r
+       int low,        /* (i) Start index for the search */\r
+       int high,           /* (i) End index for the search */\r
+       int stage,          /* (i) Current stage */\r
+       int startIndex,     /* (i) CB index for the first \r
+                                  augmented vector */\r
+       float *target,      /* (i) Target vector for encoding */\r
+       float *buffer,      /* (i) Pointer to the end of the \r
+                                  buffer for augmented codebook \r
+                                  construction */\r
+       float *max_measure, /* (i/o) Currently maximum measure */\r
+       int *best_index,/* (o) Currently the best index */\r
+       float *gain,    /* (o) Currently the best gain */\r
+       float *energy,      /* (o) Energy of augmented \r
+                                  codebook vectors */\r
+       float *invenergy/* (o) Inv energy of aug codebook \r
+                                  vectors */\r
+   );\r
+   \r
+   void createAugmentedVec(\r
+       int index,          /* (i) Index for the aug vector \r
+                                  to be created */\r
+       float *buffer,      /* (i) Pointer to the end of the \r
+                                  buffer for augmented codebook \r
+                                  construction */\r
+       float *cbVec    /* (o) The construced codebook vector */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.12 createCB.c\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     91\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       createCB.c\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include <string.h>\r
+   #include <math.h>\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Construct an additional codebook vector by filtering the\r
+    *  initial codebook buffer. This vector is then used to expand\r
+    *  the codebook with an additional section.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void filteredCBvecs(\r
+       float *cbvectors,   /* (o) Codebook vectors for the \r
+                                  higher section */\r
+       float *mem,         /* (i) Buffer to create codebook \r
+                                  vector from */\r
+       int lMem        /* (i) Length of buffer */\r
+   ){\r
+       int j, k;\r
+       float *pp, *pp1;\r
+       float tempbuff2[CB_MEML+CB_FILTERLEN];\r
+       float *pos;\r
+   \r
+       memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));\r
+       memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));\r
+       memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, \r
+           (CB_HALFFILTERLEN+1)*sizeof(float));\r
+   \r
+       /* Create codebook vector for higher section by filtering */\r
+   \r
+       /* do filtering */\r
+       pos=cbvectors;\r
+       memset(pos, 0, lMem*sizeof(float));\r
+       for (k=0; k<lMem; k++) {\r
+           pp=&tempbuff2[k];\r
+           pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+           for (j=0;j<CB_FILTERLEN;j++) {\r
+               (*pos)+=(*pp++)*(*pp1--);\r
+           }\r
+           pos++;\r
+       }\r
+   }\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     92\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Search the augmented part of the codebook to find the best\r
+    *  measure.\r
+    *----------------------------------------------------------------*/\r
+   \r
+   void searchAugmentedCB(\r
+       int low,        /* (i) Start index for the search */\r
+       int high,           /* (i) End index for the search */\r
+       int stage,          /* (i) Current stage */\r
+       int startIndex,     /* (i) Codebook index for the first \r
+                                  aug vector */\r
+       float *target,      /* (i) Target vector for encoding */\r
+       float *buffer,      /* (i) Pointer to the end of the buffer for\r
+                                  augmented codebook construction */\r
+       float *max_measure, /* (i/o) Currently maximum measure */\r
+       int *best_index,/* (o) Currently the best index */\r
+       float *gain,    /* (o) Currently the best gain */\r
+       float *energy,      /* (o) Energy of augmented codebook \r
+                                  vectors */\r
+       float *invenergy/* (o) Inv energy of augmented codebook \r
+                                  vectors */\r
+   ) {\r
+       int icount, ilow, j, tmpIndex;\r
+       float *pp, *ppo, *ppi, *ppe, crossDot, alfa; \r
+       float weighted, measure, nrjRecursive;\r
+       float ftmp;\r
+   \r
+       /* Compute the energy for the first (low-5) \r
+          noninterpolated samples */\r
+       nrjRecursive = (float) 0.0;\r
+       pp = buffer - low + 1;\r
+       for (j=0; j<(low-5); j++) {\r
+           nrjRecursive += ( (*pp)*(*pp) );\r
+           pp++;\r
+       }\r
+       ppe = buffer - low;\r
+   \r
+   \r
+       for (icount=low; icount<=high; icount++) {\r
+   \r
+           /* Index of the codebook vector used for retrieving \r
+              energy values */\r
+           tmpIndex = startIndex+icount-20;\r
+   \r
+           ilow = icount-4;\r
+               \r
+           /* Update the energy recursively to save complexity */\r
+           nrjRecursive = nrjRecursive + (*ppe)*(*ppe);\r
+           ppe--;\r
+           energy[tmpIndex] = nrjRecursive;\r
+   \r
+           /* Compute cross dot product for the first (low-5) \r
+              samples */\r
+           crossDot = (float) 0.0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     93\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           pp = buffer-icount;\r
+           for (j=0; j<ilow; j++) {\r
+               crossDot += target[j]*(*pp++);\r
+           }\r
+   \r
+           /* interpolation */\r
+           alfa = (float) 0.2;\r
+           ppo = buffer-4;\r
+           ppi = buffer-icount-4;\r
+           for (j=ilow; j<icount; j++) {\r
+               weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
+               ppo++;\r
+               ppi++;\r
+               energy[tmpIndex] += weighted*weighted;\r
+               crossDot += target[j]*weighted;\r
+               alfa += (float)0.2;\r
+           }\r
+   \r
+           /* Compute energy and cross dot product for the \r
+              remaining samples */\r
+           pp = buffer - icount;\r
+           for (j=icount; j<SUBL; j++) {\r
+               energy[tmpIndex] += (*pp)*(*pp);\r
+               crossDot += target[j]*(*pp++);\r
+           }\r
+           \r
+           if (energy[tmpIndex]>0.0) {\r
+               invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);\r
+           } else {\r
+               invenergy[tmpIndex] = (float) 0.0;\r
+           }\r
+           \r
+           if (stage==0) {\r
+               measure = (float)-10000000.0;\r
+               \r
+               if (crossDot > 0.0) {\r
+                   measure = crossDot*crossDot*invenergy[tmpIndex];\r
+               }\r
+           }\r
+           else {\r
+               measure = crossDot*crossDot*invenergy[tmpIndex];\r
+           }\r
+       \r
+           /* check if measure is better */\r
+           ftmp = crossDot*invenergy[tmpIndex];\r
+           \r
+           if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+               *best_index = tmpIndex;\r
+               *max_measure = measure;\r
+               *gain = ftmp;\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     94\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Recreate a specific codebook vector from the augmented part.\r
+    *\r
+    *----------------------------------------------------------------*/\r
+   \r
+   void createAugmentedVec(\r
+       int index,      /* (i) Index for the augmented vector \r
+                              to be created */\r
+       float *buffer,  /* (i) Pointer to the end of the buffer for\r
+                              augmented codebook construction */\r
+       float *cbVec/* (o) The construced codebook vector */\r
+   ) {\r
+       int ilow, j;\r
+       float *pp, *ppo, *ppi, alfa, alfa1, weighted;\r
+   \r
+       ilow = index-5;\r
+               \r
+       /* copy the first noninterpolated part */\r
+   \r
+       pp = buffer-index;\r
+       memcpy(cbVec,pp,sizeof(float)*index);\r
+   \r
+       /* interpolation */\r
+   \r
+       alfa1 = (float)0.2;\r
+       alfa = 0.0;\r
+       ppo = buffer-5;\r
+       ppi = buffer-index-5;\r
+       for (j=ilow; j<index; j++) {\r
+           weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);\r
+           ppo++;\r
+           ppi++;\r
+           cbVec[j] = weighted;\r
+           alfa += alfa1;\r
+       }\r
+   \r
+       /* copy the second noninterpolated part */\r
+   \r
+       pp = buffer - index;\r
+       memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));\r
+   }\r
+   \r
+   \r
+A.13 doCPLC.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       doCPLC.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     95\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_DOLPC_H\r
+   #define __iLBC_DOLPC_H\r
+   \r
+   void doThePLC(\r
+       float *PLCresidual, /* (o) concealed residual */ \r
+       float *PLClpc,      /* (o) concealed LP parameters */  \r
+       int PLI,        /* (i) packet loss indicator \r
+                                  0 - no PL, 1 = PL */ \r
+       float *decresidual, /* (i) decoded residual */\r
+       float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
+       int inlag,          /* (i) pitch lag */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i/o) decoder instance */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.14 doCPLC.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       doCPLC.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   #include <stdio.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Compute cross correlation and pitch gain for pitch prediction\r
+    *  of last subframe at given lag.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void compCorr(\r
+       float *cc,      /* (o) cross correlation coefficient */\r
+       float *gc,      /* (o) gain */\r
+       float *pm,\r
+       float *buffer,  /* (i) signal buffer */\r
+       int lag,    /* (i) pitch lag */\r
+       int bLen,       /* (i) length of buffer */\r
+       int sRange      /* (i) correlation search length */\r
+   ){\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     96\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       int i;\r
+       float ftmp1, ftmp2, ftmp3;\r
+   \r
+       /* Guard against getting outside buffer */\r
+       if ((bLen-sRange-lag)<0) {\r
+           sRange=bLen-lag;\r
+       }\r
+   \r
+       ftmp1 = 0.0;\r
+       ftmp2 = 0.0;\r
+       ftmp3 = 0.0;\r
+       for (i=0; i<sRange; i++) {\r
+           ftmp1 += buffer[bLen-sRange+i] *\r
+               buffer[bLen-sRange+i-lag];\r
+           ftmp2 += buffer[bLen-sRange+i-lag] * \r
+                   buffer[bLen-sRange+i-lag];\r
+           ftmp3 += buffer[bLen-sRange+i] * \r
+                   buffer[bLen-sRange+i];\r
+       }\r
+   \r
+       if (ftmp2 > 0.0) {\r
+           *cc = ftmp1*ftmp1/ftmp2;\r
+           *gc = (float)fabs(ftmp1/ftmp2);\r
+           *pm=(float)fabs(ftmp1)/\r
+               ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));\r
+       }\r
+       else {\r
+           *cc = 0.0;\r
+           *gc = 0.0;\r
+           *pm=0.0;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Packet loss concealment routine. Conceals a residual signal\r
+    *  and LP parameters. If no packet loss, update state.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void doThePLC(\r
+       float *PLCresidual, /* (o) concealed residual */ \r
+       float *PLClpc,      /* (o) concealed LP parameters */  \r
+       int PLI,        /* (i) packet loss indicator \r
+                                  0 - no PL, 1 = PL */ \r
+       float *decresidual, /* (i) decoded residual */\r
+       float *lpc,         /* (i) decoded LPC (only used for no PL) */\r
+       int inlag,          /* (i) pitch lag */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i/o) decoder instance */\r
+   ){\r
+       int lag=20, randlag;\r
+       float gain, maxcc;\r
+       float use_gain;\r
+       float gain_comp, maxcc_comp, per, max_per;\r
+       int i, pick, use_lag;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     97\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;\r
+               \r
+       /* Packet Loss */\r
+   \r
+       if (PLI == 1) {\r
+           \r
+           iLBCdec_inst->consPLICount += 1;\r
+           \r
+           /* if previous frame not lost, \r
+              determine pitch pred. gain */\r
+           \r
+           if (iLBCdec_inst->prevPLI != 1) {\r
+   \r
+               /* Search around the previous lag to find the \r
+                  best pitch period */\r
+               \r
+               lag=inlag-3;\r
+               compCorr(&maxcc, &gain, &max_per, \r
+                   iLBCdec_inst->prevResidual,\r
+                   lag, iLBCdec_inst->blockl, 60);\r
+               for (i=inlag-2;i<=inlag+3;i++) {\r
+                   compCorr(&maxcc_comp, &gain_comp, &per,\r
+                       iLBCdec_inst->prevResidual,\r
+                       i, iLBCdec_inst->blockl, 60);\r
+                   \r
+                   if (maxcc_comp>maxcc) {\r
+                       maxcc=maxcc_comp;\r
+                       gain=gain_comp;\r
+                       lag=i;\r
+                       max_per=per;\r
+                   }\r
+               }\r
+               \r
+           }\r
+   \r
+           /* previous frame lost, use recorded lag and periodicity */\r
+   \r
+           else {\r
+               lag=iLBCdec_inst->prevLag;\r
+               max_per=iLBCdec_inst->per;\r
+           }\r
+           \r
+           /* downscaling */\r
+   \r
+           use_gain=1.0;\r
+           if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)\r
+               use_gain=(float)0.9;\r
+           else if (iLBCdec_inst->consPLICount*\r
+                           iLBCdec_inst->blockl>2*320)\r
+               use_gain=(float)0.7;\r
+           else if (iLBCdec_inst->consPLICount*\r
+                           iLBCdec_inst->blockl>3*320)\r
+               use_gain=(float)0.5;\r
+           else if (iLBCdec_inst->consPLICount*\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     98\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                           iLBCdec_inst->blockl>4*320)\r
+               use_gain=(float)0.0;\r
+   \r
+           /* mix noise and pitch repeatition */\r
+           ftmp=(float)sqrt(max_per);\r
+           if (ftmp>(float)0.7)\r
+               pitchfact=(float)1.0;\r
+           else if (ftmp>(float)0.4)\r
+               pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);\r
+           else\r
+               pitchfact=0.0;\r
+   \r
+   \r
+           /* avoid repetition of same pitch cycle */\r
+           use_lag=lag;\r
+           if (lag<80) {\r
+               use_lag=2*lag;\r
+           }\r
+   \r
+           /* compute concealed residual */\r
+   \r
+           energy = 0.0;\r
+           for (i=0; i<iLBCdec_inst->blockl; i++) {\r
+   \r
+               /* noise component */\r
+   \r
+               iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & \r
+                   (0x80000000L-1);\r
+               randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;\r
+               pick = i - randlag;\r
+               \r
+               if (pick < 0) {\r
+                   randvec[i] = \r
+                       iLBCdec_inst->prevResidual[\r
+                                   iLBCdec_inst->blockl+pick];\r
+               } else {\r
+                   randvec[i] =  randvec[pick];\r
+               }\r
+   \r
+               /* pitch repeatition component */\r
+               pick = i - use_lag;\r
+               \r
+               if (pick < 0) {\r
+                   PLCresidual[i] =  \r
+                       iLBCdec_inst->prevResidual[\r
+                                   iLBCdec_inst->blockl+pick];\r
+               } else {\r
+                   PLCresidual[i] = PLCresidual[pick];\r
+               }\r
+   \r
+               /* mix random and periodicity component */\r
+   \r
+               if (i<80)\r
+                   PLCresidual[i] = use_gain*(pitchfact * \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004     99\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                               PLCresidual[i] +\r
+                               ((float)1.0 - pitchfact) * randvec[i]);\r
+               else if (i<160)\r
+                   PLCresidual[i] = (float)0.95*use_gain*(pitchfact * \r
+                               PLCresidual[i] +\r
+                               ((float)1.0 - pitchfact) * randvec[i]);\r
+               else\r
+                   PLCresidual[i] = (float)0.9*use_gain*(pitchfact * \r
+                               PLCresidual[i] +\r
+                               ((float)1.0 - pitchfact) * randvec[i]);\r
+   \r
+               energy += PLCresidual[i] * PLCresidual[i];\r
+           }\r
+           \r
+           /* less than 30 dB, use only noise */\r
+           \r
+           if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { \r
+               gain=0.0;\r
+               for (i=0; i<iLBCdec_inst->blockl; i++) {\r
+                   PLCresidual[i] = randvec[i];\r
+               }\r
+           }\r
+   \r
+           /* use old LPC */\r
+   \r
+           memcpy(PLClpc,iLBCdec_inst->prevLpc,\r
+               (LPC_FILTERORDER+1)*sizeof(float));\r
+           \r
+       }\r
+   \r
+       /* no packet loss, copy input */\r
+   \r
+       else {\r
+           memcpy(PLCresidual, decresidual, \r
+               iLBCdec_inst->blockl*sizeof(float));\r
+           memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));\r
+           iLBCdec_inst->consPLICount = 0;\r
+       }\r
+       \r
+       /* update state */\r
+   \r
+       if (PLI) {\r
+           iLBCdec_inst->prevLag = lag;\r
+           iLBCdec_inst->per=max_per;\r
+       }\r
+   \r
+       iLBCdec_inst->prevPLI = PLI;\r
+       memcpy(iLBCdec_inst->prevLpc, PLClpc, \r
+           (LPC_FILTERORDER+1)*sizeof(float));\r
+       memcpy(iLBCdec_inst->prevResidual, PLCresidual,\r
+           iLBCdec_inst->blockl*sizeof(float));\r
+   }\r
+   \r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    100\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+A.15 enhancer.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       enhancer.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __ENHANCER_H\r
+   #define __ENHANCER_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   float xCorrCoef( \r
+       float *target,      /* (i) first array */\r
+       float *regressor,   /* (i) second array */\r
+       int subl        /* (i) dimension arrays */\r
+   );\r
+   \r
+   int enhancerInterface(\r
+       float *out,         /* (o) the enhanced recidual signal */\r
+       float *in,          /* (i) the recidual signal to enhance */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i/o) the decoder state structure */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.16 enhancer.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       enhancer.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    101\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+    * Find index in array such that the array element with said\r
+    * index is the element of said array closest to "value" \r
+    * according to the squared-error criterion\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void NearestNeighbor(\r
+       int   *index,   /* (o) index of array element closest \r
+                              to value */\r
+       float *array,   /* (i) data array */\r
+       float value,/* (i) value */\r
+       int arlength/* (i) dimension of data array */\r
+   ){\r
+       int i;\r
+       float bestcrit,crit;\r
+   \r
+       crit=array[0]-value;\r
+       bestcrit=crit*crit;\r
+       *index=0;\r
+       for (i=1; i<arlength; i++) {\r
+           crit=array[i]-value;\r
+           crit=crit*crit;\r
+           \r
+           if (crit<bestcrit) {\r
+               bestcrit=crit;\r
+               *index=i;\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * compute cross correlation between sequences\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void mycorr1( \r
+       float* corr,    /* (o) correlation of seq1 and seq2 */\r
+       float* seq1,    /* (i) first sequence */\r
+       int dim1,           /* (i) dimension first seq1 */\r
+       const float *seq2,  /* (i) second sequence */\r
+       int dim2        /* (i) dimension seq2 */\r
+   ){\r
+       int i,j;\r
+   \r
+       for (i=0; i<=dim1-dim2; i++) {\r
+           corr[i]=0.0;\r
+           for (j=0; j<dim2; j++) {\r
+               corr[i] += seq1[i+j] * seq2[j];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * upsample finite array assuming zeros outside bounds\r
+    *---------------------------------------------------------------*/\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    102\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   void enh_upsample( \r
+       float* useq1,   /* (o) upsampled output sequence */\r
+       float* seq1,/* (i) unupsampled sequence */\r
+       int dim1,       /* (i) dimension seq1 */\r
+       int hfl         /* (i) polyphase filter length=2*hfl+1 */\r
+   ){\r
+       float *pu,*ps;\r
+       int i,j,k,q,filterlength,hfl2;\r
+       const float *polyp[ENH_UPS0]; /* pointers to \r
+                                        polyphase columns */\r
+       const float *pp;\r
+   \r
+       /* define pointers for filter */\r
+   \r
+       filterlength=2*hfl+1;\r
+       \r
+       if ( filterlength > dim1 ) {\r
+           hfl2=(int) (dim1/2);\r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;\r
+           }\r
+           hfl=hfl2;\r
+           filterlength=2*hfl+1;\r
+       }\r
+       else {\r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               polyp[j]=polyphaserTbl+j*filterlength;\r
+           }\r
+       }\r
+   \r
+       /* filtering: filter overhangs left side of sequence */\r
+   \r
+       pu=useq1;\r
+       for (i=hfl; i<filterlength; i++) { \r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               *pu=0.0;\r
+               pp = polyp[j];\r
+               ps = seq1+i;\r
+               for (k=0; k<=i; k++) {\r
+                   *pu += *ps-- * *pp++;\r
+               }\r
+               pu++;\r
+           }\r
+       }\r
+   \r
+       /* filtering: simple convolution=inner products */\r
+   \r
+       for (i=filterlength; i<dim1; i++) {\r
+           for (j=0;j<ENH_UPS0; j++){\r
+               *pu=0.0;\r
+               pp = polyp[j];\r
+               ps = seq1+i;\r
+               for (k=0; k<filterlength; k++) {\r
+                   *pu += *ps-- * *pp++;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    103\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               }\r
+               pu++;\r
+           }\r
+       }\r
+   \r
+       /* filtering: filter overhangs right side of sequence */\r
+   \r
+       for (q=1; q<=hfl; q++) { \r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               *pu=0.0;\r
+               pp = polyp[j]+q;\r
+               ps = seq1+dim1-1;\r
+               for (k=0; k<filterlength-q; k++) {\r
+                   *pu += *ps-- * *pp++;\r
+               }\r
+               pu++;\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    * find segment starting near idata+estSegPos that has highest \r
+    * correlation with idata+centerStartPos through \r
+    * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a \r
+    * resolution of ENH_UPSO times the original of the original \r
+    * sampling rate\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void refiner(\r
+       float *seg,         /* (o) segment array */\r
+       float *updStartPos, /* (o) updated start point */\r
+       float* idata,       /* (i) original data buffer */\r
+       int idatal,         /* (i) dimension of idata */\r
+       int centerStartPos, /* (i) beginning center segment */\r
+       float estSegPos,/* (i) estimated beginning other segment */\r
+       float period    /* (i) estimated pitch period */\r
+   ){\r
+       int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;\r
+       int tloc,tloc2,i,st,en,fraction;\r
+       float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;\r
+       float corrVecUps[ENH_CORRDIM*ENH_UPS0];\r
+   \r
+       /* defining array bounds */\r
+       \r
+       estSegPosRounded=(int)(estSegPos - 0.5);\r
+   \r
+       searchSegStartPos=estSegPosRounded-ENH_SLOP;\r
+       \r
+       if (searchSegStartPos<0) { \r
+           searchSegStartPos=0;\r
+       }\r
+       searchSegEndPos=estSegPosRounded+ENH_SLOP;\r
+       \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    104\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       if (searchSegEndPos+ENH_BLOCKL >= idatal) { \r
+           searchSegEndPos=idatal-ENH_BLOCKL-1;\r
+       }\r
+       corrdim=searchSegEndPos-searchSegStartPos+1;\r
+       \r
+       /* compute upsampled correlation (corr33) and find \r
+          location of max */\r
+   \r
+       mycorr1(corrVec,idata+searchSegStartPos,\r
+           corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);\r
+       enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);\r
+       tloc=0; maxv=corrVecUps[0];\r
+       for (i=1; i<ENH_UPS0*corrdim; i++) {\r
+           \r
+           if (corrVecUps[i]>maxv) {\r
+               tloc=i;\r
+               maxv=corrVecUps[i];\r
+           }\r
+       }\r
+       \r
+       /* make vector can be upsampled without ever running outside \r
+          bounds */\r
+       \r
+       *updStartPos= (float)searchSegStartPos + \r
+           (float)tloc/(float)ENH_UPS0+(float)1.0;\r
+       tloc2=(int)(tloc/ENH_UPS0);\r
+       \r
+       if (tloc>tloc2*ENH_UPS0) {\r
+           tloc2++;\r
+       }\r
+       st=searchSegStartPos+tloc2-ENH_FL0;\r
+       \r
+       if (st<0) {\r
+           memset(vect,0,-st*sizeof(float));\r
+           memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));\r
+       }\r
+       else {\r
+           en=st+ENH_VECTL;\r
+           \r
+           if (en>idatal) {\r
+               memcpy(vect, &idata[st], \r
+                   (ENH_VECTL-(en-idatal))*sizeof(float));\r
+               memset(&vect[ENH_VECTL-(en-idatal)], 0, \r
+                   (en-idatal)*sizeof(float));\r
+           }\r
+           else {\r
+               memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));\r
+           }\r
+       }\r
+       fraction=tloc2*ENH_UPS0-tloc;\r
+       \r
+       /* compute the segment (this is actually a convolution) */\r
+   \r
+       mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    105\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           2*ENH_FL0+1);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * find the smoothed output data\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void smath(\r
+       float *odata,   /* (o) smoothed output */\r
+       float *sseq,/* (i) said second sequence of waveforms */\r
+       int hl,         /* (i) 2*hl+1 is sseq dimension */\r
+       float alpha0/* (i) max smoothing energy fraction */\r
+   ){\r
+       int i,k;\r
+       float w00,w10,w11,A,B,C,*psseq,err,errs;\r
+       float surround[BLOCKL_MAX]; /* shape contributed by other than \r
+                                      current */\r
+       float wt[2*ENH_HL+1];       /* waveform weighting to get \r
+                                      surround shape */\r
+       float denom;\r
+       \r
+       /* create shape of contribution from all waveforms except the\r
+          current one */\r
+   \r
+       for (i=1; i<=2*hl+1; i++) {\r
+           wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); \r
+       }\r
+       wt[hl]=0.0; /* for clarity, not used */\r
+       for (i=0; i<ENH_BLOCKL; i++) {\r
+           surround[i]=sseq[i]*wt[0];\r
+       }\r
+       for (k=1; k<hl; k++) {\r
+           psseq=sseq+k*ENH_BLOCKL;\r
+           for(i=0;i<ENH_BLOCKL; i++) {\r
+               surround[i]+=psseq[i]*wt[k];\r
+           }\r
+       }\r
+       for (k=hl+1; k<=2*hl; k++) {\r
+           psseq=sseq+k*ENH_BLOCKL;\r
+           for(i=0;i<ENH_BLOCKL; i++) {\r
+               surround[i]+=psseq[i]*wt[k];\r
+           }\r
+       }\r
+       \r
+       /* compute some inner products */\r
+   \r
+       w00 = w10 = w11 = 0.0;\r
+       psseq=sseq+hl*ENH_BLOCKL; /* current block  */\r
+       for (i=0; i<ENH_BLOCKL;i++) {\r
+           w00+=psseq[i]*psseq[i];\r
+           w11+=surround[i]*surround[i];\r
+           w10+=surround[i]*psseq[i];\r
+       }\r
+       \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    106\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       if (fabs(w11) < 1.0) {\r
+           w11=1.0;\r
+       }\r
+       C = (float)sqrt( w00/w11);\r
+       \r
+       /* first try enhancement without power-constraint */\r
+   \r
+       errs=0.0;\r
+       psseq=sseq+hl*ENH_BLOCKL;\r
+       for (i=0; i<ENH_BLOCKL; i++) {\r
+           odata[i]=C*surround[i];\r
+           err=psseq[i]-odata[i];\r
+           errs+=err*err;\r
+       }\r
+       \r
+       /* if constraint violated by first try, add constraint */ \r
+       \r
+       if (errs > alpha0 * w00) {\r
+           if ( w00 < 1) {\r
+               w00=1;\r
+           }\r
+           denom = (w11*w00-w10*w10)/(w00*w00);\r
+           \r
+           if (denom > 0.0001) { /* eliminates numerical problems \r
+                                    for if smooth */\r
+               A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);\r
+               B = -alpha0/2 - A * w10/w00;\r
+               B = B+1;\r
+           }\r
+           else { /* essentially no difference between cycles; \r
+                     smoothing not needed */\r
+               A= 0.0;\r
+               B= 1.0;\r
+           }\r
+           \r
+           /* create smoothed sequence */\r
+   \r
+           psseq=sseq+hl*ENH_BLOCKL;\r
+           for (i=0; i<ENH_BLOCKL; i++) {\r
+               odata[i]=A*surround[i]+B*psseq[i];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * get the pitch-synchronous sample sequence\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void getsseq(\r
+       float *sseq,    /* (o) the pitch-synchronous sequence */\r
+       float *idata,       /* (i) original data */\r
+       int idatal,         /* (i) dimension of data */\r
+       int centerStartPos, /* (i) where current block starts */\r
+       float *period,      /* (i) rough-pitch-period array */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    107\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float *plocs,       /* (i) where periods of period array \r
+                                  are taken */\r
+       int periodl,    /* (i) dimension period array */\r
+       int hl              /* (i) 2*hl+1 is the number of sequences */\r
+   ){\r
+       int i,centerEndPos,q;\r
+       float blockStartPos[2*ENH_HL+1];\r
+       int lagBlock[2*ENH_HL+1];\r
+       float plocs2[ENH_PLOCSL]; \r
+       float *psseq;\r
+   \r
+       centerEndPos=centerStartPos+ENH_BLOCKL-1;\r
+       \r
+       /* present */\r
+   \r
+       NearestNeighbor(lagBlock+hl,plocs,\r
+           (float)0.5*(centerStartPos+centerEndPos),periodl);\r
+       \r
+       blockStartPos[hl]=(float)centerStartPos;\r
+       psseq=sseq+ENH_BLOCKL*hl;\r
+       memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));\r
+       \r
+       /* past */\r
+   \r
+       for (q=hl-1; q>=0; q--) {\r
+           blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];\r
+           NearestNeighbor(lagBlock+q,plocs,\r
+               blockStartPos[q]+\r
+               ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);\r
+                               \r
+           \r
+           if (blockStartPos[q]-ENH_OVERHANG>=0) {\r
+               refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,\r
+                   idatal, centerStartPos, blockStartPos[q],\r
+                   period[lagBlock[q+1]]);\r
+           } else {\r
+               psseq=sseq+q*ENH_BLOCKL;\r
+               memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
+           }\r
+       }\r
+       \r
+       /* future */\r
+   \r
+       for (i=0; i<periodl; i++) {\r
+           plocs2[i]=plocs[i]-period[i];\r
+       }\r
+       for (q=hl+1; q<=2*hl; q++) { \r
+           NearestNeighbor(lagBlock+q,plocs2,\r
+               blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);\r
+   \r
+           blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];\r
+           if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {\r
+               refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,\r
+                   idatal, centerStartPos, blockStartPos[q],\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    108\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                   period[lagBlock[q]]);\r
+           }\r
+           else {\r
+               psseq=sseq+q*ENH_BLOCKL;\r
+               memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * perform enhancement on idata+centerStartPos through \r
+    * idata+centerStartPos+ENH_BLOCKL-1\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void enhancer(\r
+       float *odata,       /* (o) smoothed block, dimension blockl */\r
+       float *idata,       /* (i) data buffer used for enhancing */\r
+       int idatal,         /* (i) dimension idata */\r
+       int centerStartPos, /* (i) first sample current block \r
+                                  within idata */\r
+       float alpha0,       /* (i) max correction-energy-fraction \r
+                                 (in [0,1]) */\r
+       float *period,      /* (i) pitch period array */\r
+       float *plocs,       /* (i) locations where period array \r
+                                  values valid */\r
+       int periodl         /* (i) dimension of period and plocs */\r
+   ){\r
+       float sseq[(2*ENH_HL+1)*ENH_BLOCKL];\r
+   \r
+       /* get said second sequence of segments */\r
+   \r
+       getsseq(sseq,idata,idatal,centerStartPos,period,\r
+           plocs,periodl,ENH_HL);\r
+   \r
+       /* compute the smoothed output from said second sequence */\r
+   \r
+       smath(odata,sseq,ENH_HL,alpha0);\r
+   \r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * cross correlation\r
+    *---------------------------------------------------------------*/\r
+   \r
+   float xCorrCoef( \r
+       float *target,      /* (i) first array */\r
+       float *regressor,   /* (i) second array */\r
+       int subl        /* (i) dimension arrays */\r
+   ){\r
+       int i;\r
+       float ftmp1, ftmp2;\r
+           \r
+       ftmp1 = 0.0;\r
+       ftmp2 = 0.0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    109\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       for (i=0; i<subl; i++) {\r
+           ftmp1 += target[i]*regressor[i];\r
+           ftmp2 += regressor[i]*regressor[i]; \r
+       }\r
+       \r
+       if (ftmp1 > 0.0) {\r
+           return (float)(ftmp1*ftmp1/ftmp2);\r
+       }\r
+       else {\r
+           return (float)0.0;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * interface for enhancer\r
+    *---------------------------------------------------------------*/\r
+   \r
+   int enhancerInterface(\r
+       float *out,                     /* (o) enhanced signal */\r
+       float *in,                      /* (i) unenhanced signal */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst   /* (i) buffers etc */\r
+   ){\r
+       float *enh_buf, *enh_period;\r
+       int iblock, isample;\r
+       int lag=0, ilag, i, ioffset;\r
+       float cc, maxcc;\r
+       float ftmp1, ftmp2;\r
+       float *inPtr, *enh_bufPtr1, *enh_bufPtr2;\r
+       float plc_pred[ENH_BLOCKL];\r
+   \r
+       float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];\r
+       int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;\r
+       int start, plc_blockl, inlag;\r
+   \r
+       enh_buf=iLBCdec_inst->enh_buf;\r
+       enh_period=iLBCdec_inst->enh_period;\r
+       \r
+       memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], \r
+           (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));\r
+                                                               \r
+       memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, \r
+           iLBCdec_inst->blockl*sizeof(float));\r
+   \r
+       if (iLBCdec_inst->mode==30)\r
+           plc_blockl=ENH_BLOCKL;\r
+       else\r
+           plc_blockl=40;\r
+   \r
+       /* when 20 ms frame, move processing one block */\r
+       ioffset=0;\r
+       if (iLBCdec_inst->mode==20) ioffset=1;\r
+   \r
+       i=3-ioffset;\r
+       memmove(enh_period, &enh_period[i], \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    110\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           (ENH_NBLOCKS_TOT-i)*sizeof(float));\r
+   \r
+       /* Set state information to the 6 samples right before \r
+          the samples to be downsampled. */\r
+   \r
+       memcpy(lpState, \r
+           enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126, \r
+           6*sizeof(float));\r
+   \r
+       /* Down sample a factor 2 to save computations */\r
+   \r
+       DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,\r
+                   lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,\r
+                   lpState, downsampled);\r
+   \r
+       /* Estimate the pitch in the down sampled domain. */\r
+       for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {\r
+           \r
+           lag = 10;\r
+           maxcc = xCorrCoef(downsampled+60+iblock*\r
+               ENH_BLOCKL_HALF, downsampled+60+iblock*\r
+               ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);\r
+           for (ilag=11; ilag<60; ilag++) {\r
+               cc = xCorrCoef(downsampled+60+iblock*\r
+                   ENH_BLOCKL_HALF, downsampled+60+iblock*\r
+                   ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);\r
+               \r
+               if (cc > maxcc) {\r
+                   maxcc = cc;\r
+                   lag = ilag;\r
+               }\r
+           }\r
+   \r
+           /* Store the estimated lag in the non-downsampled domain */\r
+           enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;\r
+\r
+\r
+       }   \r
+   \r
+   \r
+       /* PLC was performed on the previous packet */\r
+       if (iLBCdec_inst->prev_enh_pl==1) {\r
+   \r
+           inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];\r
+   \r
+           lag = inlag-1;\r
+           maxcc = xCorrCoef(in, in+lag, plc_blockl);\r
+           for (ilag=inlag; ilag<=inlag+1; ilag++) {\r
+               cc = xCorrCoef(in, in+ilag, plc_blockl);\r
+               \r
+               if (cc > maxcc) {\r
+                   maxcc = cc;\r
+                   lag = ilag;\r
+               }\r
+           }\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    111\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;\r
+   \r
+           /* compute new concealed residual for the old lookahead,\r
+              mix the forward PLC with a backward PLC from \r
+              the new frame */\r
+           \r
+           inPtr=&in[lag-1];\r
+           \r
+           enh_bufPtr1=&plc_pred[plc_blockl-1];\r
+           \r
+           if (lag>plc_blockl) {\r
+               start=plc_blockl;\r
+           } else {\r
+               start=lag;\r
+           }\r
+   \r
+           for (isample = start; isample>0; isample--) {\r
+               *enh_bufPtr1-- = *inPtr--;\r
+           }\r
+           \r
+           enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
+           for (isample = (plc_blockl-1-lag); isample>=0; isample--) \r
+{\r
+               *enh_bufPtr1-- = *enh_bufPtr2--;\r
+           }\r
+   \r
+           /* limit energy change */\r
+           ftmp2=0.0;\r
+           ftmp1=0.0;\r
+           for (i=0;i<plc_blockl;i++) {\r
+               ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*\r
+                   enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];\r
+               ftmp1+=plc_pred[i]*plc_pred[i];\r
+           }\r
+           ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);\r
+           ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);\r
+           if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {\r
+               for (i=0;i<plc_blockl-10;i++) {\r
+                   plc_pred[i]*=(float)2.0*ftmp2/ftmp1;\r
+               }\r
+               for (i=plc_blockl-10;i<plc_blockl;i++) {\r
+                   plc_pred[i]*=(float)(i-plc_blockl+10)*\r
+                       ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+\r
+                       (float)2.0*ftmp2/ftmp1;\r
+               }\r
+           }\r
+       \r
+           enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
+           for (i=0; i<plc_blockl; i++) {\r
+               ftmp1 = (float) (i+1) / (float) (plc_blockl+1);\r
+               *enh_bufPtr1 *= ftmp1;\r
+               *enh_bufPtr1 += ((float)1.0-ftmp1)*\r
+                                   plc_pred[plc_blockl-1-i];\r
+               enh_bufPtr1--;\r
+           }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    112\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       }\r
+   \r
+       if (iLBCdec_inst->mode==20) {\r
+           /* Enhancer with 40 samples delay */\r
+           for (iblock = 0; iblock<2; iblock++) {\r
+               enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
+                   ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,\r
+                   ENH_ALPHA0, enh_period, enh_plocsTbl, \r
+                       ENH_NBLOCKS_TOT);\r
+           }\r
+       } else if (iLBCdec_inst->mode==30) {\r
+           /* Enhancer with 80 samples delay */\r
+           for (iblock = 0; iblock<3; iblock++) {\r
+               enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
+                   ENH_BUFL, (4+iblock)*ENH_BLOCKL,\r
+                   ENH_ALPHA0, enh_period, enh_plocsTbl, \r
+                       ENH_NBLOCKS_TOT);\r
+           }\r
+       }\r
+   \r
+       return (lag*2);\r
+   }\r
+   \r
+   \r
+A.17 filter.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       filter.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_FILTER_H\r
+   #define __iLBC_FILTER_H\r
+   \r
+   void AllPoleFilter(\r
+       float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
+                              InOut[-1] contain the state of the \r
+                              filter (delayed samples). InOut[0] to \r
+                              InOut[lengthInOut-1] contain the filter \r
+                              input, on en exit InOut[-orderCoef] to \r
+                              InOut[-1] is unchanged and InOut[0] to \r
+                              InOut[lengthInOut-1] contain filtered \r
+                              samples */\r
+       float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
+                              to be 1.0 */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef   /* (i) number of filter coefficients */\r
+   );\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    113\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   void AllZeroFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                              filter input samples */\r
+       float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
+                              to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain the filter state, on exit Out[0] \r
+                              to Out[lengthInOut-1] contain filtered \r
+                              samples */\r
+   );\r
+   \r
+   void ZeroPoleFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain filter\r
+                              input samples In[-orderCoef] to In[-1] \r
+                              contain state of all-zero section */\r
+       float *ZeroCoef,/* (i) filter coefficients for all-zero \r
+                              section (ZeroCoef[0] is assumed to \r
+                              be 1.0) */\r
+       float *PoleCoef,/* (i) filter coefficients for all-pole section\r
+                              (ZeroCoef[0] is assumed to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain state of all-pole section. On\r
+                              exit Out[0] to Out[lengthInOut-1] \r
+                              contain filtered samples */\r
+   );\r
+   \r
+   void DownSample (\r
+       float  *In,     /* (i) input samples */\r
+       float  *Coef,   /* (i) filter coefficients */\r
+       int lengthIn,   /* (i) number of input samples */ \r
+       float  *state,  /* (i) filter state */\r
+       float  *Out     /* (o) downsampled output */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.18 filter.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       filter.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    114\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  all-pole filter\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void AllPoleFilter(\r
+       float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
+                              InOut[-1] contain the state of the \r
+                              filter (delayed samples). InOut[0] to \r
+                              InOut[lengthInOut-1] contain the filter\r
+                              input, on en exit InOut[-orderCoef] to\r
+                              InOut[-1] is unchanged and InOut[0] to\r
+                              InOut[lengthInOut-1] contain filtered \r
+                              samples */\r
+       float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
+                              to be 1.0 */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef   /* (i) number of filter coefficients */\r
+   ){  \r
+       int n,k;\r
+       \r
+       for(n=0;n<lengthInOut;n++){\r
+           for(k=1;k<=orderCoef;k++){\r
+               *InOut -= Coef[k]*InOut[-k];\r
+           }\r
+           InOut++;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  all-zero filter                         \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void AllZeroFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                              filter input samples */\r
+       float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
+                              to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain the filter state, on exit Out[0]\r
+                              to Out[lengthInOut-1] contain filtered\r
+                              samples */\r
+   ){  \r
+       int n,k;\r
+       \r
+       for(n=0;n<lengthInOut;n++){\r
+           *Out = Coef[0]*In[0];\r
+           for(k=1;k<=orderCoef;k++){\r
+               *Out += Coef[k]*In[-k];\r
+           }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    115\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           Out++;\r
+           In++;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  pole-zero filter\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void ZeroPoleFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                              filter input samples In[-orderCoef] to \r
+                              In[-1] contain state of all-zero \r
+                              section */\r
+       float *ZeroCoef,/* (i) filter coefficients for all-zero \r
+                              section (ZeroCoef[0] is assumed to \r
+                              be 1.0) */\r
+       float *PoleCoef,/* (i) filter coefficients for all-pole section\r
+                              (ZeroCoef[0] is assumed to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain state of all-pole section. On \r
+                              exit Out[0] to Out[lengthInOut-1] \r
+                              contain filtered samples */\r
+   ){\r
+       AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);\r
+       AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * downsample (LP filter and decimation)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void DownSample (\r
+       float  *In,     /* (i) input samples */\r
+       float  *Coef,   /* (i) filter coefficients */\r
+       int lengthIn,   /* (i) number of input samples */ \r
+       float  *state,  /* (i) filter state */\r
+       float  *Out     /* (o) downsampled output */\r
+   ){\r
+       float   o;\r
+       float *Out_ptr = Out;\r
+       float *Coef_ptr, *In_ptr;\r
+       float *state_ptr;\r
+       int i, j, stop;\r
+   \r
+       /* LP filter and decimate at the same time */\r
+   \r
+       for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)\r
+       {\r
+           Coef_ptr = &Coef[0];\r
+           In_ptr = &In[i];\r
+           state_ptr = &state[FILTERORDER_DS-2];\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    116\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+           o = (float)0.0;\r
+           \r
+           stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;\r
+   \r
+           for (j = 0; j < stop; j++) \r
+           {\r
+               o += *Coef_ptr++ * (*In_ptr--);\r
+           }\r
+           for (j = i + 1; j < FILTERORDER_DS; j++) \r
+           {\r
+               o += *Coef_ptr++ * (*state_ptr--);\r
+           }\r
+   \r
+           *Out_ptr++ = o;\r
+       }\r
+   \r
+       /* Get the last part (use zeros as input for the future) */\r
+   \r
+       for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS); \r
+               i+=FACTOR_DS) {\r
+   \r
+           o=(float)0.0;\r
+           \r
+           if (i<lengthIn) {\r
+               Coef_ptr = &Coef[0];\r
+               In_ptr = &In[i];\r
+               for (j=0; j<FILTERORDER_DS; j++) {\r
+                       o += *Coef_ptr++ * (*Out_ptr--);\r
+               }\r
+           } else {\r
+               Coef_ptr = &Coef[i-lengthIn];\r
+               In_ptr = &In[lengthIn-1];\r
+               for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {\r
+                       o += *Coef_ptr++ * (*In_ptr--);\r
+               }\r
+           }\r
+           *Out_ptr++ = o;\r
+       }\r
+   }\r
+   \r
+   \r
+A.19 FrameClassify.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       FrameClassify.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    117\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   #ifndef __iLBC_FRAMECLASSIFY_H\r
+   #define __iLBC_FRAMECLASSIFY_H\r
+   \r
+   int FrameClassify(      /* index to the max-energy sub-frame */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i/o) the encoder state structure */\r
+       float *residual     /* (i) lpc residual signal */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.20 FrameClassify.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       FrameClassify.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  Classification of subframes to localize start state\r
+    *--------------------------------------------------------------*/\r
+   \r
+   int FrameClassify(      /* index to the max-energy sub-frame */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i/o) the encoder state structure */\r
+       float *residual     /* (i) lpc residual signal */\r
+   ) {\r
+       float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;\r
+       int n, l, max_ssqEn_n;\r
+       const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,\r
+           (float)1.0,(float)0.9,(float)0.8};\r
+       const float sampEn_win[5]={(float)1.0/(float)6.0, \r
+           (float)2.0/(float)6.0, (float)3.0/(float)6.0,\r
+           (float)4.0/(float)6.0, (float)5.0/(float)6.0};\r
+       \r
+       /* init the front and back energies to zero */\r
+   \r
+       memset(fssqEn, 0, NSUB_MAX*sizeof(float));\r
+       memset(bssqEn, 0, NSUB_MAX*sizeof(float));\r
+   \r
+       /* Calculate front of first seqence */\r
+   \r
+       n=0;\r
+       pp=residual;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    118\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       for (l=0; l<5; l++) {\r
+           fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+       for (l=5; l<SUBL; l++) {\r
+           fssqEn[n] += (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+   \r
+       /* Calculate front and back of all middle sequences */\r
+   \r
+       for (n=1; n<iLBCenc_inst->nsub-1; n++) {\r
+           pp=residual+n*SUBL;\r
+           for (l=0; l<5; l++) {\r
+               fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);\r
+               bssqEn[n] += (*pp) * (*pp);\r
+               pp++;\r
+           }\r
+           for (l=5; l<SUBL-5; l++) {\r
+               fssqEn[n] += (*pp) * (*pp);\r
+               bssqEn[n] += (*pp) * (*pp);\r
+               pp++;\r
+           }\r
+           for (l=SUBL-5; l<SUBL; l++) {\r
+               fssqEn[n] += (*pp) * (*pp);\r
+               bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
+               pp++;\r
+           }\r
+       }\r
+   \r
+       /* Calculate back of last seqence */\r
+   \r
+       n=iLBCenc_inst->nsub-1;\r
+       pp=residual+n*SUBL;\r
+       for (l=0; l<SUBL-5; l++) {\r
+           bssqEn[n] += (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+       for (l=SUBL-5; l<SUBL; l++) {\r
+           bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);\r
+           pp++;\r
+       }\r
+   \r
+       /* find the index to the weighted 80 sample with \r
+          most energy */\r
+   \r
+       if (iLBCenc_inst->mode==20) l=1;\r
+       else                        l=0;\r
+   \r
+       max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];\r
+       max_ssqEn_n=1;\r
+       for (n=2; n<iLBCenc_inst->nsub; n++) {\r
+   \r
+           l++;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    119\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {\r
+               max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *\r
+                               ssqEn_win[l];\r
+               max_ssqEn_n=n;\r
+           }\r
+       }\r
+   \r
+       return max_ssqEn_n;\r
+   }\r
+   \r
+   \r
+A.21 gainquant.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       gainquant.h                                         \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_GAINQUANT_H\r
+   #define __iLBC_GAINQUANT_H\r
+   \r
+   float gainquant(/* (o) quantized gain value */\r
+       float in,       /* (i) gain value */\r
+       float maxIn,/* (i) maximum of gain value */\r
+       int cblen,      /* (i) number of quantization indices */\r
+       int *index      /* (o) quantization index */\r
+   );\r
+   \r
+   float gaindequant(  /* (o) quantized gain value */\r
+       int index,      /* (i) quantization index */\r
+       float maxIn,/* (i) maximum of unquantized gain */\r
+       int cblen       /* (i) number of quantization indices */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.22 gainquant.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       gainquant.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    120\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   #include <math.h>\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  quantizer for the gain in the gain-shape coding of residual\r
+    *---------------------------------------------------------------*/\r
+   \r
+   float gainquant(/* (o) quantized gain value */\r
+       float in,       /* (i) gain value */\r
+       float maxIn,/* (i) maximum of gain value */\r
+       int cblen,      /* (i) number of quantization indices */\r
+       int *index      /* (o) quantization index */\r
+   ){\r
+       int i, tindex;\r
+       float minmeasure,measure, *cb, scale;\r
+   \r
+       /* ensure a lower bound on the scaling factor */\r
+   \r
+       scale=maxIn;\r
+       \r
+       if (scale<0.1) {\r
+           scale=(float)0.1;\r
+       }\r
+   \r
+       /* select the quantization table */\r
+       \r
+       if (cblen == 8) {\r
+           cb = gain_sq3Tbl;\r
+       } else if (cblen == 16) {\r
+           cb = gain_sq4Tbl;\r
+       } else  {\r
+           cb = gain_sq5Tbl;\r
+       }\r
+   \r
+       /* select the best index in the quantization table */\r
+       \r
+       minmeasure=10000000.0;\r
+       tindex=0;\r
+       for (i=0; i<cblen; i++) {\r
+           measure=(in-scale*cb[i])*(in-scale*cb[i]);\r
+           \r
+           if (measure<minmeasure) {\r
+               tindex=i;\r
+               minmeasure=measure;\r
+           }\r
+       }\r
+       *index=tindex;\r
+          \r
+       /* return the quantized value */\r
+       \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    121\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       return scale*cb[tindex];\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  decoder for quantized gains in the gain-shape coding of \r
+    *  residual                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   float gaindequant(  /* (o) quantized gain value */\r
+       int index,      /* (i) quantization index */\r
+       float maxIn,/* (i) maximum of unquantized gain */\r
+       int cblen       /* (i) number of quantization indices */\r
+   ){\r
+       float scale;\r
+   \r
+       /* obtain correct scale factor */\r
+   \r
+       scale=(float)fabs(maxIn);\r
+       \r
+       if (scale<0.1) {\r
+           scale=(float)0.1;\r
+       }\r
+   \r
+       /* select the quantization table and return the decoded value */\r
+   \r
+       if (cblen==8) {\r
+           return scale*gain_sq3Tbl[index];\r
+       } else if (cblen==16) {\r
+           return scale*gain_sq4Tbl[index];\r
+       }\r
+       else if (cblen==32) {\r
+           return scale*gain_sq5Tbl[index];\r
+       }\r
+   \r
+       return 0.0;\r
+   }\r
+   \r
+   \r
+A.23 getCBvec.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       getCBvec.h                 \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_GETCBVEC_H\r
+   #define __iLBC_GETCBVEC_H\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    122\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   void getCBvec(\r
+       float *cbvec,   /* (o) Constructed codebook vector */\r
+       float *mem,     /* (i) Codebook buffer */\r
+       int index,      /* (i) Codebook index */\r
+       int lMem,       /* (i) Length of codebook buffer */\r
+       int cbveclen/* (i) Codebook vector length */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.24 getCBvec.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       getCBvec.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include <string.h>\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Construct codebook vector for given index.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void getCBvec(\r
+       float *cbvec,   /* (o) Constructed codebook vector */\r
+       float *mem,     /* (i) Codebook buffer */\r
+       int index,      /* (i) Codebook index */\r
+       int lMem,       /* (i) Length of codebook buffer */\r
+       int cbveclen/* (i) Codebook vector length */\r
+   ){\r
+       int j, k, n, memInd, sFilt;\r
+       float tmpbuf[CB_MEML];\r
+       int base_size;\r
+       int ilow, ihigh;\r
+       float alfa, alfa1;\r
+   \r
+       /* Determine size of codebook sections */\r
+   \r
+       base_size=lMem-cbveclen+1;\r
+       \r
+       if (cbveclen==SUBL) {\r
+           base_size+=cbveclen/2;\r
+       }\r
+   \r
+       /* No filter -> First codebook section */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    123\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       \r
+       if (index<lMem-cbveclen+1) {\r
+   \r
+           /* first non-interpolated vectors */\r
+   \r
+           k=index+cbveclen;\r
+           /* get vector */\r
+           memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));\r
+   \r
+       } else if (index < base_size) {\r
+   \r
+           k=2*(index-(lMem-cbveclen+1))+cbveclen;\r
+       \r
+           ihigh=k/2;\r
+           ilow=ihigh-5;\r
+   \r
+           /* Copy first noninterpolated part */\r
+   \r
+           memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));\r
+   \r
+           /* interpolation */\r
+   \r
+           alfa1=(float)0.2;\r
+           alfa=0.0;\r
+           for (j=ilow; j<ihigh; j++) {\r
+               cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+\r
+                   alfa*mem[lMem-k+j];\r
+               alfa+=alfa1;\r
+           }\r
+   \r
+           /* Copy second noninterpolated part */\r
+   \r
+           memcpy(cbvec+ihigh, mem+lMem-k+ihigh, \r
+               (cbveclen-ihigh)*sizeof(float));\r
+   \r
+       }\r
+   \r
+       /* Higher codebbok section based on filtering */\r
+   \r
+       else {\r
+   \r
+           /* first non-interpolated vectors */\r
+   \r
+           if (index-base_size<lMem-cbveclen+1) {\r
+               float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
+               float *pos;\r
+               float *pp, *pp1;\r
+   \r
+               memset(tempbuff2, 0,\r
+                   CB_HALFFILTERLEN*sizeof(float));\r
+               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
+                   lMem*sizeof(float));\r
+               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
+                   (CB_HALFFILTERLEN+1)*sizeof(float));\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    124\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+               k=index-base_size+cbveclen;\r
+               sFilt=lMem-k;\r
+               memInd=sFilt+1-CB_HALFFILTERLEN;\r
+   \r
+               /* do filtering */\r
+               pos=cbvec;\r
+               memset(pos, 0, cbveclen*sizeof(float));\r
+               for (n=0; n<cbveclen; n++) {\r
+                   pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];\r
+                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+                   for (j=0; j<CB_FILTERLEN; j++) {\r
+                       (*pos)+=(*pp++)*(*pp1--);\r
+                   }\r
+                   pos++;\r
+               }\r
+           }\r
+   \r
+           /* interpolated vectors */\r
+   \r
+           else {\r
+               float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
+   \r
+               float *pos;\r
+               float *pp, *pp1;\r
+               int i;\r
+   \r
+               memset(tempbuff2, 0,\r
+                   CB_HALFFILTERLEN*sizeof(float));\r
+               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
+                   lMem*sizeof(float));\r
+               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
+                   (CB_HALFFILTERLEN+1)*sizeof(float));\r
+   \r
+               k=2*(index-base_size-\r
+                   (lMem-cbveclen+1))+cbveclen;\r
+               sFilt=lMem-k;\r
+               memInd=sFilt+1-CB_HALFFILTERLEN;\r
+   \r
+               /* do filtering */\r
+               pos=&tmpbuf[sFilt];\r
+               memset(pos, 0, k*sizeof(float));\r
+               for (i=0; i<k; i++) {\r
+                   pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];\r
+                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+                   for (j=0; j<CB_FILTERLEN; j++) {\r
+                       (*pos)+=(*pp++)*(*pp1--);\r
+                   }\r
+                   pos++;\r
+               }\r
+   \r
+               ihigh=k/2;\r
+               ilow=ihigh-5;\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    125\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               /* Copy first noninterpolated part */\r
+   \r
+               memcpy(cbvec, tmpbuf+lMem-k/2, \r
+                   ilow*sizeof(float));\r
+   \r
+               /* interpolation */\r
+   \r
+               alfa1=(float)0.2;\r
+               alfa=0.0;\r
+               for (j=ilow; j<ihigh; j++) {\r
+                   cbvec[j]=((float)1.0-alfa)*\r
+                       tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];\r
+                   alfa+=alfa1;\r
+               }\r
+   \r
+               /* Copy second noninterpolated part */\r
+   \r
+               memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh, \r
+                   (cbveclen-ihigh)*sizeof(float));\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+A.25 helpfun.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       helpfun.h         \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_HELPFUN_H\r
+   #define __iLBC_HELPFUN_H\r
+   \r
+   void autocorr( \r
+       float *r,       /* (o) autocorrelation vector */\r
+       const float *x, /* (i) data vector */\r
+       int N,          /* (i) length of data vector */\r
+       int order       /* largest lag for calculated \r
+                          autocorrelations */\r
+   );\r
+   \r
+   void window( \r
+       float *z,       /* (o) the windowed data */\r
+       const float *x, /* (i) the original data vector */\r
+       const float *y, /* (i) the window */\r
+       int N           /* (i) length of all vectors */\r
+   );\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    126\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   void levdurb( \r
+       float *a,       /* (o) lpc coefficient vector starting \r
+                              with 1.0 */\r
+       float *k,       /* (o) reflection coefficients */\r
+       float *r,       /* (i) autocorrelation vector */\r
+       int order       /* (i) order of lpc filter */\r
+   );\r
+   \r
+   void interpolate( \r
+       float *out,     /* (o) the interpolated vector */\r
+       float *in1,     /* (i) the first vector for the \r
+                              interpolation */\r
+       float *in2,     /* (i) the second vector for the \r
+                              interpolation */\r
+       float coef,     /* (i) interpolation weights */\r
+       int length      /* (i) length of all vectors */\r
+   );\r
+              \r
+   void bwexpand( \r
+       float *out,     /* (o) the bandwidth expanded lpc \r
+                              coefficients */\r
+       float *in,      /* (i) the lpc coefficients before bandwidth\r
+                              expansion */\r
+       float coef,     /* (i) the bandwidth expansion factor */\r
+       int length      /* (i) the length of lpc coefficient vectors */\r
+   );\r
+   \r
+   void vq( \r
+       float *Xq,      /* (o) the quantized vector */\r
+       int *index,     /* (o) the quantization index */\r
+       const float *CB,/* (i) the vector quantization codebook */\r
+       float *X,       /* (i) the vector to quantize */\r
+       int n_cb,       /* (i) the number of vectors in the codebook */\r
+       int dim         /* (i) the dimension of all vectors */\r
+   );  \r
+   \r
+   void SplitVQ( \r
+       float *qX,      /* (o) the quantized vector */\r
+       int *index,     /* (o) a vector of indexes for all vector\r
+                              codebooks in the split */\r
+       float *X,       /* (i) the vector to quantize */\r
+       const float *CB,/* (i) the quantizer codebook */\r
+       int nsplit,     /* the number of vector splits */\r
+       const int *dim, /* the dimension of X and qX */\r
+       const int *cbsize /* the number of vectors in the codebook */\r
+   );\r
+   \r
+   \r
+   void sort_sq( \r
+       float *xq,      /* (o) the quantized value */\r
+       int *index,     /* (o) the quantization index */\r
+       float x,    /* (i) the value to quantize */\r
+       const float *cb,/* (i) the quantization codebook */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    127\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       int cb_size     /* (i) the size of the quantization codebook */\r
+   );\r
+   \r
+   int LSF_check(      /* (o) 1 for stable lsf vectors and 0 for \r
+                              nonstable ones */\r
+       float *lsf,     /* (i) a table of lsf vectors */\r
+       int dim,    /* (i) the dimension of each lsf vector */\r
+       int NoAn    /* (i) the number of lsf vectors in the \r
+                              table */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.26 helpfun.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       helpfun.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  calculation of auto correlation \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void autocorr( \r
+       float *r,       /* (o) autocorrelation vector */\r
+       const float *x, /* (i) data vector */\r
+       int N,          /* (i) length of data vector */\r
+       int order       /* largest lag for calculated \r
+                          autocorrelations */\r
+   ){\r
+       int     lag, n;\r
+       float   sum;\r
+       \r
+       for (lag = 0; lag <= order; lag++) {\r
+           sum = 0;\r
+           for (n = 0; n < N - lag; n++) {\r
+               sum += x[n] * x[n+lag];\r
+           }\r
+           r[lag] = sum;\r
+       }\r
+   }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    128\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  window multiplication  \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void window( \r
+       float *z,       /* (o) the windowed data */\r
+       const float *x, /* (i) the original data vector */\r
+       const float *y, /* (i) the window */\r
+       int N           /* (i) length of all vectors */\r
+   ){\r
+       int     i;\r
+       \r
+       for (i = 0; i < N; i++) {\r
+           z[i] = x[i] * y[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  levinson-durbin solution for lpc coefficients\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void levdurb( \r
+       float *a,       /* (o) lpc coefficient vector starting \r
+                              with 1.0 */\r
+       float *k,       /* (o) reflection coefficients */\r
+       float *r,       /* (i) autocorrelation vector */\r
+       int order       /* (i) order of lpc filter */\r
+   ){\r
+       float  sum, alpha;\r
+       int     m, m_h, i;\r
+   \r
+       a[0] = 1.0;\r
+       \r
+       if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */\r
+           for (i = 0; i < order; i++) {\r
+               k[i] = 0;\r
+               a[i+1] = 0;\r
+           }   \r
+       } else {\r
+           a[1] = k[0] = -r[1]/r[0];\r
+           alpha = r[0] + r[1] * k[0];\r
+           for (m = 1; m < order; m++){\r
+               sum = r[m + 1];\r
+               for (i = 0; i < m; i++){\r
+                   sum += a[i+1] * r[m - i];\r
+               }\r
+               k[m] = -sum / alpha;\r
+               alpha += k[m] * sum;\r
+               m_h = (m + 1) >> 1;\r
+               for (i = 0; i < m_h; i++){\r
+                   sum = a[i+1] + k[m] * a[m - i];\r
+                   a[m - i] += k[m] * a[i+1];\r
+                   a[i+1] = sum;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    129\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               }\r
+               a[m+1] = k[m];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  interpolation between vectors \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void interpolate( \r
+       float *out,      /* (o) the interpolated vector */\r
+       float *in1,     /* (i) the first vector for the \r
+                              interpolation */\r
+       float *in2,     /* (i) the second vector for the \r
+                              interpolation */\r
+       float coef,      /* (i) interpolation weights */\r
+       int length      /* (i) length of all vectors */\r
+   ){\r
+       int i;\r
+       float invcoef;\r
+   \r
+       invcoef = (float)1.0 - coef;\r
+       for (i = 0; i < length; i++) {\r
+           out[i] = coef * in1[i] + invcoef * in2[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lpc bandwidth expansion                   \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void bwexpand( \r
+       float *out,      /* (o) the bandwidth expanded lpc \r
+                              coefficients */\r
+       float *in,      /* (i) the lpc coefficients before bandwidth \r
+                              expansion */\r
+       float coef,     /* (i) the bandwidth expansion factor */\r
+       int length      /* (i) the length of lpc coefficient vectors */\r
+   ){\r
+       int i;\r
+       float  chirp;\r
+       \r
+       chirp = coef;\r
+       \r
+       out[0] = in[0];\r
+       for (i = 1; i < length; i++) {\r
+           out[i] = chirp * in[i];\r
+           chirp *= coef;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  vector quantization \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    130\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void vq( \r
+       float *Xq,      /* (o) the quantized vector */\r
+       int *index,     /* (o) the quantization index */\r
+       const float *CB,/* (i) the vector quantization codebook */\r
+       float *X,       /* (i) the vector to quantize */\r
+       int n_cb,       /* (i) the number of vectors in the codebook */\r
+       int dim         /* (i) the dimension of all vectors */\r
+   ){\r
+       int     i, j;\r
+       int     pos, minindex;\r
+       float   dist, tmp, mindist;\r
+   \r
+       pos = 0;\r
+       mindist = FLOAT_MAX;\r
+       minindex = 0;\r
+       for (j = 0; j < n_cb; j++) {\r
+           dist = X[0] - CB[pos];\r
+           dist *= dist;\r
+           for (i = 1; i < dim; i++) {\r
+               tmp = X[i] - CB[pos + i];\r
+               dist += tmp*tmp;\r
+           }\r
+           \r
+           if (dist < mindist) {\r
+               mindist = dist;\r
+               minindex = j;\r
+           }\r
+           pos += dim;\r
+       }\r
+       for (i = 0; i < dim; i++) {\r
+           Xq[i] = CB[minindex*dim + i];\r
+       }\r
+       *index = minindex;\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  split vector quantization \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SplitVQ( \r
+       float *qX,      /* (o) the quantized vector */\r
+       int *index,     /* (o) a vector of indexes for all vector\r
+                              codebooks in the split */\r
+       float *X,       /* (i) the vector to quantize */\r
+       const float *CB,/* (i) the quantizer codebook */\r
+       int nsplit,     /* the number of vector splits */\r
+       const int *dim, /* the dimension of X and qX */\r
+       const int *cbsize /* the number of vectors in the codebook */\r
+   ){\r
+       int    cb_pos, X_pos, i;\r
+       \r
+       cb_pos = 0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    131\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       X_pos= 0;\r
+       for (i = 0; i < nsplit; i++) {\r
+           vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, \r
+               cbsize[i], dim[i]);\r
+           X_pos += dim[i];\r
+           cb_pos += dim[i] * cbsize[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  scalar quantization \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void sort_sq( \r
+       float *xq,      /* (o) the quantized value */\r
+       int *index,     /* (o) the quantization index */\r
+       float x,    /* (i) the value to quantize */\r
+       const float *cb,/* (i) the quantization codebook */\r
+       int cb_size      /* (i) the size of the quantization codebook */\r
+   ){\r
+       int i;\r
+       \r
+       if (x <= cb[0]) {\r
+           *index = 0;\r
+           *xq = cb[0];\r
+       } else {\r
+           i = 0;\r
+           while ((x > cb[i]) && i < cb_size - 1) {\r
+               i++;\r
+           }\r
+           \r
+           if (x > ((cb[i] + cb[i - 1])/2)) {\r
+               *index = i;\r
+               *xq = cb[i];\r
+           } else {\r
+               *index = i - 1;\r
+               *xq = cb[i - 1];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  check for stability of lsf coefficients\r
+    *---------------------------------------------------------------*/\r
+   \r
+   int LSF_check(    /* (o) 1 for stable lsf vectors and 0 for\r
+                              nonstable ones */\r
+       float *lsf,     /* (i) a table of lsf vectors */\r
+       int dim,    /* (i) the dimension of each lsf vector */\r
+       int NoAn    /* (i) the number of lsf vectors in the \r
+                              table */\r
+   ){\r
+       int k,n,m, Nit=2, change=0,pos;\r
+       float tmp;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    132\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       static float eps=(float)0.039; /* 50 Hz */\r
+       static float eps2=(float)0.0195;\r
+       static float maxlsf=(float)3.14; /* 4000 Hz */\r
+       static float minlsf=(float)0.01; /* 0 Hz */\r
+       \r
+       /* LSF separation check*/\r
+   \r
+       for (n=0; n<Nit; n++) { /* Run through a couple of times */\r
+           for (m=0; m<NoAn; m++) { /* Number of analyses per frame */\r
+               for (k=0; k<(dim-1); k++) {\r
+                   pos=m*dim+k;\r
+                   \r
+                   if ((lsf[pos+1]-lsf[pos])<eps) {\r
+                       \r
+                       if (lsf[pos+1]<lsf[pos]) {\r
+                           tmp=lsf[pos+1];\r
+                           lsf[pos+1]= lsf[pos]+eps2;\r
+                           lsf[pos]= lsf[pos+1]-eps2;\r
+                       } else {\r
+                           lsf[pos]-=eps2;\r
+                           lsf[pos+1]+=eps2;\r
+                       }\r
+                       change=1;\r
+                   }\r
+                   \r
+                   if (lsf[pos]<minlsf) { \r
+                       lsf[pos]=minlsf;\r
+                       change=1;\r
+                   }\r
+                   \r
+                   if (lsf[pos]>maxlsf) { \r
+                       lsf[pos]=maxlsf;\r
+                       change=1;\r
+                   }               \r
+               }\r
+           }\r
+       }\r
+       \r
+       return change;  \r
+   }\r
+   \r
+   \r
+A.27 hpInput.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpInput.h        \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    133\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   #ifndef __iLBC_HPINPUT_H\r
+   #define __iLBC_HPINPUT_H\r
+   \r
+   void hpInput( \r
+       float *In,  /* (i) vector to filter */\r
+       int len,    /* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.28 hpInput.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpInput.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Input high-pass filter                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void hpInput( \r
+       float *In,  /* (i) vector to filter */\r
+       int len,    /* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   ){\r
+       int i;\r
+       float *pi, *po;\r
+   \r
+       /* all-zero section*/\r
+   \r
+       pi = &In[0];\r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po = hpi_zero_coefsTbl[0] * (*pi);\r
+           *po += hpi_zero_coefsTbl[1] * mem[0];\r
+           *po += hpi_zero_coefsTbl[2] * mem[1];\r
+   \r
+           mem[1] = mem[0];\r
+           mem[0] = *pi;\r
+           po++;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    134\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           pi++;\r
+   \r
+       }\r
+   \r
+       /* all-pole section*/\r
+   \r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po -= hpi_pole_coefsTbl[1] * mem[2];\r
+           *po -= hpi_pole_coefsTbl[2] * mem[3];\r
+   \r
+           mem[3] = mem[2];\r
+           mem[2] = *po;\r
+           po++;\r
+       }\r
+   }\r
+   \r
+   \r
+A.29 hpOutput.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpOutput.h       \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_HPOUTPUT_H\r
+   #define __iLBC_HPOUTPUT_H\r
+   \r
+   void hpOutput(\r
+       float *In,  /* (i) vector to filter */\r
+       int len,/* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.30 hpOutput.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpOutput.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    135\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Output high-pass filter                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void hpOutput(\r
+       float *In,  /* (i) vector to filter */\r
+       int len,/* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   ){\r
+       int i;\r
+       float *pi, *po;\r
+   \r
+       /* all-zero section*/\r
+   \r
+       pi = &In[0];\r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po = hpo_zero_coefsTbl[0] * (*pi);\r
+           *po += hpo_zero_coefsTbl[1] * mem[0];\r
+           *po += hpo_zero_coefsTbl[2] * mem[1];\r
+   \r
+           mem[1] = mem[0];\r
+           mem[0] = *pi;\r
+           po++;\r
+           pi++;\r
+   \r
+       }\r
+   \r
+       /* all-pole section*/\r
+   \r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po -= hpo_pole_coefsTbl[1] * mem[2];\r
+           *po -= hpo_pole_coefsTbl[2] * mem[3];\r
+   \r
+           mem[3] = mem[2];\r
+           mem[2] = *po;\r
+           po++;\r
+       }\r
+   }\r
+   \r
+   \r
+A.31 iCBConstruct.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    136\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       iCBConstruct.h   \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ICBCONSTRUCT_H\r
+   #define __iLBC_ICBCONSTRUCT_H\r
+   \r
+   void index_conv_enc(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   );\r
+   \r
+   void index_conv_dec(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   );\r
+   \r
+   void iCBConstruct(\r
+       float *decvector,   /* (o) Decoded vector */\r
+       int *index,         /* (i) Codebook indices */\r
+       int *gain_index,/* (i) Gain quantization indices */\r
+       float *mem,         /* (i) Buffer for codevector construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int veclen,         /* (i) Length of vector */\r
+       int nStages         /* (i) Number of codebook stages */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.32 iCBConstruct.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iCBConstruct.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "gainquant.h"\r
+   #include "getCBvec.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Convert the codebook indexes to make the search easier\r
+    *---------------------------------------------------------------*/\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    137\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   void index_conv_enc(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   ){\r
+       int k;\r
+   \r
+       for (k=1; k<CB_NSTAGES; k++) {\r
+           \r
+           if ((index[k]>=108)&&(index[k]<172)) {\r
+               index[k]-=64;\r
+           } else if (index[k]>=236) {\r
+               index[k]-=128;\r
+           } else {\r
+               /* ERROR */\r
+           }\r
+       }\r
+   }\r
+   \r
+   void index_conv_dec(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   ){\r
+       int k;\r
+   \r
+       for (k=1; k<CB_NSTAGES; k++) {\r
+           \r
+           if ((index[k]>=44)&&(index[k]<108)) {\r
+               index[k]+=64;\r
+           } else if ((index[k]>=108)&&(index[k]<128)) {\r
+               index[k]+=128;\r
+           } else {\r
+               /* ERROR */\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Construct decoded vector from codebook and gains.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iCBConstruct(\r
+       float *decvector,   /* (o) Decoded vector */\r
+       int *index,         /* (i) Codebook indices */\r
+       int *gain_index,/* (i) Gain quantization indices */\r
+       float *mem,         /* (i) Buffer for codevector construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int veclen,         /* (i) Length of vector */\r
+       int nStages         /* (i) Number of codebook stages */\r
+   ){\r
+       int j,k;\r
+       float gain[CB_NSTAGES];\r
+       float cbvec[SUBL];\r
+   \r
+       /* gain de-quantization */\r
+   \r
+       gain[0] = gaindequant(gain_index[0], 1.0, 32);\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    138\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       if (nStages > 1) {\r
+           gain[1] = gaindequant(gain_index[1], \r
+               (float)fabs(gain[0]), 16);  \r
+       }\r
+       if (nStages > 2) {\r
+           gain[2] = gaindequant(gain_index[2], \r
+               (float)fabs(gain[1]), 8);\r
+       }\r
+   \r
+       /* codebook vector construction and construction of \r
+       total vector */\r
+   \r
+       getCBvec(cbvec, mem, index[0], lMem, veclen);\r
+       for (j=0;j<veclen;j++){\r
+           decvector[j] = gain[0]*cbvec[j];\r
+       }\r
+       if (nStages > 1) {\r
+           for (k=1; k<nStages; k++) {\r
+               getCBvec(cbvec, mem, index[k], lMem, veclen);\r
+               for (j=0;j<veclen;j++) {\r
+                   decvector[j] += gain[k]*cbvec[j];\r
+               }\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+A.33 iCBSearch.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iCBSearch.h        \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ICBSEARCH_H\r
+   #define __iLBC_ICBSEARCH_H\r
+   \r
+   void iCBSearch(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i) the encoder state structure */\r
+       int *index,         /* (o) Codebook indices */\r
+       int *gain_index,/* (o) Gain quantization indices */\r
+       float *intarget,/* (i) Target vector for encoding */    \r
+       float *mem,         /* (i) Buffer for codebook construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int lTarget,    /* (i) Length of vector */\r
+       int nStages,    /* (i) Number of codebook stages */\r
+       float *weightDenum, /* (i) weighting filter coefficients */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    139\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float *weightState, /* (i) weighting filter state */\r
+       int block           /* (i) the sub-block number */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.34 iCBSearch.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iCBSearch.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "gainquant.h"\r
+   #include "createCB.h"\r
+   #include "filter.h"\r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Search routine for codebook encoding and gain quantization.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iCBSearch(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i) the encoder state structure */\r
+       int *index,         /* (o) Codebook indices */\r
+       int *gain_index,/* (o) Gain quantization indices */\r
+       float *intarget,/* (i) Target vector for encoding */    \r
+       float *mem,         /* (i) Buffer for codebook construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int lTarget,    /* (i) Length of vector */\r
+       int nStages,    /* (i) Number of codebook stages */\r
+       float *weightDenum, /* (i) weighting filter coefficients */\r
+       float *weightState, /* (i) weighting filter state */\r
+       int block           /* (i) the sub-block number */\r
+   ){\r
+       int i, j, icount, stage, best_index, range, counter;\r
+       float max_measure, gain, measure, crossDot, ftmp;\r
+       float gains[CB_NSTAGES];\r
+       float target[SUBL];\r
+       int base_index, sInd, eInd, base_size;\r
+       int sIndAug=0, eIndAug=0;\r
+       float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    140\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];\r
+       float *pp, *ppi=0, *ppo=0, *ppe=0;\r
+       float cbvectors[CB_MEML];\r
+       float tene, cene, cvec[SUBL];\r
+       float aug_vec[SUBL];\r
+   \r
+       memset(cvec,0,SUBL*sizeof(float));  \r
+   \r
+       /* Determine size of codebook sections */\r
+   \r
+       base_size=lMem-lTarget+1;\r
+       \r
+       if (lTarget==SUBL) {\r
+           base_size=lMem-lTarget+1+lTarget/2;\r
+       }\r
+   \r
+       /* setup buffer for weighting */\r
+   \r
+       memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);\r
+       memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));\r
+       memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));\r
+   \r
+       /* weighting */\r
+   \r
+       AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, \r
+           lMem+lTarget, LPC_FILTERORDER);\r
+       \r
+       /* Construct the codebook and target needed */\r
+   \r
+       memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));\r
+   \r
+       tene=0.0;\r
+       for (i=0; i<lTarget; i++) {\r
+           tene+=target[i]*target[i];\r
+       }\r
+   \r
+       /* Prepare search over one more codebook section. This section \r
+          is created by filtering the original buffer with a filter. */\r
+           \r
+       filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);\r
+   \r
+       /* The Main Loop over stages */\r
+   \r
+       for (stage=0; stage<nStages; stage++) {\r
+   \r
+           range = search_rangeTbl[block][stage];\r
+   \r
+           /* initialize search measure */\r
+   \r
+           max_measure = (float)-10000000.0;\r
+           gain = (float)0.0;\r
+           best_index = 0;\r
+   \r
+           /* Compute cross dot product between the target \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    141\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+              and the CB memory */\r
+   \r
+           crossDot=0.0;\r
+           pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
+           for (j=0; j<lTarget; j++) {\r
+               crossDot += target[j]*(*pp++);\r
+           }       \r
+           \r
+           if (stage==0) {\r
+   \r
+               /* Calculate energy in the first block of \r
+                 'lTarget' sampels. */\r
+               ppe = energy;\r
+               ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;\r
+               ppo = buf+LPC_FILTERORDER+lMem-1;\r
+   \r
+               *ppe=0.0;\r
+               pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
+               for (j=0; j<lTarget; j++) {\r
+                   *ppe+=(*pp)*(*pp++);\r
+               }\r
+               \r
+               if (*ppe>0.0) {\r
+                   invenergy[0] = (float) 1.0 / (*ppe + EPS);\r
+               } else {\r
+                   invenergy[0] = (float) 0.0; \r
+               }\r
+               ppe++;\r
+   \r
+               measure=(float)-10000000.0; \r
+               \r
+               if (crossDot > 0.0) {\r
+                      measure = crossDot*crossDot*invenergy[0];\r
+               }\r
+           }\r
+           else {\r
+               measure = crossDot*crossDot*invenergy[0];\r
+           }\r
+   \r
+           /* check if measure is better */\r
+           ftmp = crossDot*invenergy[0];\r
+           \r
+           if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+               best_index = 0;\r
+               max_measure = measure;\r
+               gain = ftmp;\r
+           }\r
+   \r
+           /* loop over the main first codebook section, \r
+              full search */\r
+   \r
+           for (icount=1; icount<range; icount++) {\r
+   \r
+               /* calculate measure */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    142\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+               crossDot=0.0;\r
+               pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;\r
+   \r
+               for (j=0; j<lTarget; j++) {\r
+                   crossDot += target[j]*(*pp++);\r
+               }\r
+               \r
+               if (stage==0) {\r
+                   *ppe++ = energy[icount-1] + (*ppi)*(*ppi) - \r
+                       (*ppo)*(*ppo);\r
+                   ppo--;\r
+                   ppi--;\r
+                   \r
+                   if (energy[icount]>0.0) {\r
+                       invenergy[icount] = \r
+                           (float)1.0/(energy[icount]+EPS);\r
+                   } else {\r
+                       invenergy[icount] = (float) 0.0;\r
+                   }\r
+   \r
+                   measure=(float)-10000000.0;\r
+                   \r
+                   if (crossDot > 0.0) {\r
+                       measure = crossDot*crossDot*invenergy[icount];\r
+                   }\r
+               }\r
+               else {\r
+                   measure = crossDot*crossDot*invenergy[icount];\r
+               }\r
+   \r
+               /* check if measure is better */\r
+               ftmp = crossDot*invenergy[icount];\r
+   \r
+               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+                   best_index = icount;\r
+                   max_measure = measure;\r
+                   gain = ftmp;\r
+               }\r
+           }\r
+   \r
+           /* Loop over augmented part in the first codebook \r
+            * section, full search.\r
+            * The vectors are interpolated.\r
+            */\r
+           \r
+           if (lTarget==SUBL) {        \r
+               \r
+               /* Search for best possible cb vector and \r
+                  compute the CB-vectors' energy. */\r
+               searchAugmentedCB(20, 39, stage, base_size-lTarget/2, \r
+                   target, buf+LPC_FILTERORDER+lMem,\r
+                   &max_measure, &best_index, &gain, energy, \r
+                   invenergy);\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    143\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           }\r
+   \r
+           /* set search range for following codebook sections */\r
+   \r
+           base_index=best_index;\r
+   \r
+           /* unrestricted search */\r
+   \r
+           if (CB_RESRANGE == -1) {\r
+               sInd=0;\r
+               eInd=range-1;\r
+               sIndAug=20;\r
+               eIndAug=39;\r
+           }\r
+   \r
+           /* restriced search around best index from first \r
+           codebook section */\r
+   \r
+           else {\r
+               /* Initialize search indices */\r
+               sIndAug=0;\r
+               eIndAug=0;\r
+               sInd=base_index-CB_RESRANGE/2;\r
+               eInd=sInd+CB_RESRANGE;\r
+               \r
+               if (lTarget==SUBL) {\r
+   \r
+                   if (sInd<0) {\r
+                       \r
+                       sIndAug = 40 + sInd;\r
+                       eIndAug = 39;\r
+                       sInd=0;\r
+   \r
+                   } else if ( base_index < (base_size-20) ) {\r
+                       \r
+                       if (eInd > range) {\r
+                           sInd -= (eInd-range);\r
+                           eInd = range;\r
+                       }\r
+                   } else { /* base_index >= (base_size-20) */\r
+                       \r
+                       if (sInd < (base_size-20)) {\r
+                           sIndAug = 20;\r
+                           sInd = 0;\r
+                           eInd = 0;\r
+                           eIndAug = 19 + CB_RESRANGE;\r
+                           \r
+                           if(eIndAug > 39) {\r
+                               eInd = eIndAug-39;\r
+                               eIndAug = 39;\r
+                           }\r
+                       } else {\r
+                           sIndAug = 20 + sInd - (base_size-20);\r
+                           eIndAug = 39;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    144\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                           sInd = 0;\r
+                           eInd = CB_RESRANGE - (eIndAug-sIndAug+1);\r
+                       }\r
+                   }\r
+   \r
+               } else { /* lTarget = 22 or 23 */\r
+                   \r
+                   if (sInd < 0) {\r
+                       eInd -= sInd;\r
+                       sInd = 0;\r
+                   }\r
+                   \r
+                   if(eInd > range) {\r
+                       sInd -= (eInd - range);\r
+                       eInd = range;\r
+                   }\r
+               }\r
+           }\r
+   \r
+           /* search of higher codebook section */\r
+   \r
+           /* index search range */\r
+           counter = sInd;\r
+           sInd += base_size;\r
+           eInd += base_size;\r
+           \r
+           \r
+           if (stage==0) {\r
+               ppe = energy+base_size;\r
+               *ppe=0.0;\r
+   \r
+               pp=cbvectors+lMem-lTarget;\r
+               for (j=0; j<lTarget; j++) {\r
+                   *ppe+=(*pp)*(*pp++);\r
+               }\r
+   \r
+               ppi = cbvectors + lMem - 1 - lTarget;\r
+               ppo = cbvectors + lMem - 1;\r
+               \r
+               for (j=0; j<(range-1); j++) {\r
+                   *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);\r
+                   ppo--;\r
+                   ppi--;\r
+                   ppe++;\r
+               }\r
+           }\r
+   \r
+           /* loop over search range */\r
+   \r
+           for (icount=sInd; icount<eInd; icount++) {\r
+   \r
+               /* calculate measure */\r
+   \r
+               crossDot=0.0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    145\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               pp=cbvectors + lMem - (counter++) - lTarget;\r
+   \r
+               for (j=0;j<lTarget;j++) {\r
+                   crossDot += target[j]*(*pp++);\r
+               }\r
+               \r
+               if (energy[icount]>0.0) {\r
+                   invenergy[icount] =(float)1.0/(energy[icount]+EPS);\r
+               } else {\r
+                   invenergy[icount] =(float)0.0;\r
+               }\r
+               \r
+               if (stage==0) {\r
+   \r
+                   measure=(float)-10000000.0;\r
+                   \r
+                   if (crossDot > 0.0) {\r
+                       measure = crossDot*crossDot*\r
+                           invenergy[icount];\r
+                   }\r
+               }\r
+               else {\r
+                   measure = crossDot*crossDot*invenergy[icount];\r
+               }\r
+   \r
+               /* check if measure is better */\r
+               ftmp = crossDot*invenergy[icount];\r
+   \r
+               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+                   best_index = icount;\r
+                   max_measure = measure;\r
+                   gain = ftmp;\r
+               }\r
+           }\r
+   \r
+           /* Search the augmented CB inside the limited range. */\r
+           \r
+           if ((lTarget==SUBL)&&(sIndAug!=0)) {\r
+               searchAugmentedCB(sIndAug, eIndAug, stage, \r
+                   2*base_size-20, target, cbvectors+lMem,\r
+                   &max_measure, &best_index, &gain, energy, \r
+                   invenergy);\r
+           }\r
+   \r
+           /* record best index */\r
+   \r
+           index[stage] = best_index;\r
+   \r
+           /* gain quantization */\r
+   \r
+           if (stage==0){\r
+               \r
+               if (gain<0.0){\r
+                   gain = 0.0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    146\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               }\r
+               \r
+               if (gain>CB_MAXGAIN) {\r
+                   gain = (float)CB_MAXGAIN;\r
+               }\r
+               gain = gainquant(gain, 1.0, 32, &gain_index[stage]);\r
+           }\r
+           else {\r
+               if (stage==1) {\r
+                   gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
+                       16, &gain_index[stage]);\r
+               } else {\r
+                   gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
+                       8, &gain_index[stage]);\r
+               }\r
+           }\r
+   \r
+           /* Extract the best (according to measure) \r
+              codebook vector */\r
+           \r
+           if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {\r
+               \r
+               if (index[stage]<base_size) {\r
+                   pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];\r
+               } else {\r
+                   pp=cbvectors+lMem-lTarget-\r
+                       index[stage]+base_size;\r
+               }\r
+           } else {\r
+               \r
+               if (index[stage]<base_size) {\r
+                   if (index[stage]<(base_size-20)) {\r
+                       pp=buf+LPC_FILTERORDER+lMem-\r
+                           lTarget-index[stage];\r
+                   } else {\r
+                       createAugmentedVec(index[stage]-base_size+40,\r
+                               buf+LPC_FILTERORDER+lMem,aug_vec);\r
+                       pp=aug_vec;\r
+                   }\r
+               } else {\r
+                   int filterno, position;\r
+   \r
+                   filterno=index[stage]/base_size;\r
+                   position=index[stage]-filterno*base_size;\r
+   \r
+                   \r
+                   if (position<(base_size-20)) {\r
+                       pp=cbvectors+filterno*lMem-lTarget-\r
+                           index[stage]+filterno*base_size;\r
+                   } else {\r
+                       createAugmentedVec(\r
+                           index[stage]-(filterno+1)*base_size+40,\r
+                           cbvectors+filterno*lMem,aug_vec);\r
+                       pp=aug_vec;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    147\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                   }\r
+               }\r
+           }\r
+   \r
+           /* Subtract the best codebook vector, according \r
+              to measure, from the target vector */\r
+   \r
+           for (j=0;j<lTarget;j++) {\r
+               cvec[j] += gain*(*pp);\r
+               target[j] -= gain*(*pp++);\r
+           }\r
+   \r
+           /* record quantized gain */\r
+   \r
+           gains[stage]=gain;\r
+   \r
+       }/* end of Main Loop. for (stage=0;... */\r
+   \r
+       /* Gain adjustment for energy matching */\r
+       cene=0.0;\r
+       for (i=0; i<lTarget; i++) {\r
+           cene+=cvec[i]*cvec[i];\r
+       }\r
+       j=gain_index[0];\r
+   \r
+       for (i=gain_index[0]; i<32; i++) {\r
+           ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];\r
+           \r
+           if ((ftmp<(tene*gains[0]*gains[0])) && \r
+               (gain_sq5Tbl[j]<(2.0*gains[0]))) {\r
+               j=i;\r
+           }\r
+       }\r
+       gain_index[0]=j;\r
+   }\r
+   \r
+   \r
+A.35 LPCdecode.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPC_decode.h     \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_LPC_DECODE_H\r
+   #define __iLBC_LPC_DECODE_H\r
+   \r
+   void LSFinterpolate2a_dec( \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    148\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float *a,           /* (o) lpc coefficients for a sub-frame */\r
+       float *lsf1,    /* (i) first lsf coefficient vector */\r
+       float *lsf2,    /* (i) second lsf coefficient vector */\r
+       float coef,         /* (i) interpolation weight */\r
+       int length          /* (i) length of lsf vectors */\r
+   );\r
+         \r
+   void SimplelsfDEQ( \r
+       float *lsfdeq,      /* (o) dequantized lsf coefficients */\r
+       int *index,         /* (i) quantization index */\r
+       int lpc_n           /* (i) number of LPCs */\r
+   );\r
+   \r
+   void DecoderInterpolateLSF( \r
+       float *syntdenum,   /* (o) synthesis filter coefficients */\r
+       float *weightdenum, /* (o) weighting denumerator \r
+                                  coefficients */\r
+       float *lsfdeq,      /* (i) dequantized lsf coefficients */\r
+       int length,         /* (i) length of lsf coefficient vector */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i) the decoder state structure */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.36 LPCdecode.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPC_decode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   \r
+   #include "helpfun.h"\r
+   #include "lsf.h"\r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  interpolation of lsf coefficients for the decoder\r
+    *--------------------------------------------------------------*/\r
+   \r
+   void LSFinterpolate2a_dec( \r
+       float *a,           /* (o) lpc coefficients for a sub-frame */\r
+       float *lsf1,    /* (i) first lsf coefficient vector */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    149\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float *lsf2,    /* (i) second lsf coefficient vector */\r
+       float coef,         /* (i) interpolation weight */\r
+       int length          /* (i) length of lsf vectors */\r
+   ){\r
+       float  lsftmp[LPC_FILTERORDER];\r
+       \r
+       interpolate(lsftmp, lsf1, lsf2, coef, length);\r
+       lsf2a(a, lsftmp);\r
+   }\r
+   \r
+   /*---------------------------------------------------------------*\r
+    *  obtain dequantized lsf coefficients from quantization index \r
+    *--------------------------------------------------------------*/\r
+   \r
+   void SimplelsfDEQ(\r
+       float *lsfdeq,    /* (o) dequantized lsf coefficients */\r
+       int *index,         /* (i) quantization index */\r
+       int lpc_n           /* (i) number of LPCs */\r
+   ){  \r
+       int i, j, pos, cb_pos;\r
+   \r
+       /* decode first LSF */\r
+       \r
+       pos = 0;\r
+       cb_pos = 0;\r
+       for (i = 0; i < LSF_NSPLIT; i++) {\r
+           for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
+               lsfdeq[pos + j] = lsfCbTbl[cb_pos + \r
+                   (long)(index[i])*dim_lsfCbTbl[i] + j];\r
+           }       \r
+           pos += dim_lsfCbTbl[i];\r
+           cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
+       }\r
+   \r
+       if (lpc_n>1) {\r
+   \r
+           /* decode last LSF */\r
+   \r
+           pos = 0;\r
+           cb_pos = 0;\r
+           for (i = 0; i < LSF_NSPLIT; i++) {\r
+               for (j = 0; j < dim_lsfCbTbl[i]; j++) {\r
+                   lsfdeq[LPC_FILTERORDER + pos + j] = \r
+                       lsfCbTbl[cb_pos + \r
+                       (long)(index[LSF_NSPLIT + i])*\r
+                       dim_lsfCbTbl[i] + j];\r
+               }       \r
+               pos += dim_lsfCbTbl[i];\r
+               cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    150\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+    *  obtain synthesis and weighting filters form lsf coefficients \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void DecoderInterpolateLSF( \r
+       float *syntdenum, /* (o) synthesis filter coefficients */\r
+       float *weightdenum, /* (o) weighting denumerator \r
+                                  coefficients */\r
+       float *lsfdeq,       /* (i) dequantized lsf coefficients */\r
+       int length,         /* (i) length of lsf coefficient vector */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i) the decoder state structure */\r
+   ){\r
+       int    i, pos, lp_length;\r
+       float  lp[LPC_FILTERORDER + 1], *lsfdeq2;\r
+           \r
+       lsfdeq2 = lsfdeq + length;\r
+       lp_length = length + 1;\r
+       \r
+       if (iLBCdec_inst->mode==30) {\r
+           /* sub-frame 1: Interpolation between old and first */\r
+   \r
+           LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, \r
+               lsf_weightTbl_30ms[0], length);\r
+           memcpy(syntdenum,lp,lp_length*sizeof(float));\r
+           bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, \r
+               lp_length);\r
+   \r
+           /* sub-frames 2 to 6: interpolation between first \r
+              and last LSF */\r
+       \r
+           pos = lp_length;\r
+           for (i = 1; i < 6; i++) {\r
+               LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, \r
+                   lsf_weightTbl_30ms[i], length);\r
+               memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
+               bwexpand(weightdenum + pos, lp, \r
+                   LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       else {\r
+           pos = 0;\r
+           for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
+               LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, \r
+                   lsfdeq, lsf_weightTbl_20ms[i], length);\r
+               memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
+               bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, \r
+                   lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       \r
+       /* update memory */\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    151\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       if (iLBCdec_inst->mode==30)\r
+           memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, \r
+                       length*sizeof(float));\r
+       else\r
+           memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, \r
+                       length*sizeof(float));\r
+   \r
+   }\r
+   \r
+   \r
+A.37 LPCencode.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPCencode.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_LPCENCOD_H\r
+   #define __iLBC_LPCENCOD_H\r
+   \r
+   void LPCencode( \r
+       float *syntdenum,   /* (i/o) synthesis filter coefficients \r
+                                  before/after encoding */\r
+       float *weightdenum, /* (i/o) weighting denumerator coefficients\r
+                                  before/after encoding */\r
+       int *lsf_index,     /* (o) lsf quantization index */\r
+       float *data,    /* (i) lsf coefficients to quantize */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.38 LPCencode.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       LPCencode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    152\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   #include "iLBC_define.h"\r
+   #include "helpfun.h"\r
+   #include "lsf.h"\r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lpc analysis (subrutine to LPCencode)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SimpleAnalysis(\r
+       float *lsf,         /* (o) lsf coefficients */\r
+       float *data,    /* (i) new data vector */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   ){\r
+       int k, is;\r
+       float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];\r
+       float lp2[LPC_FILTERORDER + 1];\r
+       float r[LPC_FILTERORDER + 1];\r
+   \r
+       is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
+       memcpy(iLBCenc_inst->lpc_buffer+is,data,\r
+           iLBCenc_inst->blockl*sizeof(float));\r
+       \r
+       /* No lookahead, last window is asymmetric */\r
+       \r
+       for (k = 0; k < iLBCenc_inst->lpc_n; k++) {\r
+           \r
+           is = LPC_LOOKBACK;\r
+   \r
+           if (k < (iLBCenc_inst->lpc_n - 1)) {\r
+               window(temp, lpc_winTbl, \r
+                   iLBCenc_inst->lpc_buffer, BLOCKL_MAX);\r
+           } else {\r
+               window(temp, lpc_asymwinTbl, \r
+                   iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);\r
+           }\r
+           \r
+           autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);\r
+           window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);\r
+           \r
+           levdurb(lp, temp, r, LPC_FILTERORDER);\r
+           bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);\r
+   \r
+           a2lsf(lsf + k*LPC_FILTERORDER, lp2);\r
+       }\r
+       is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;\r
+       memmove(iLBCenc_inst->lpc_buffer, \r
+           iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, \r
+           is*sizeof(float));\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    153\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+    *  lsf interpolator and conversion from lsf to a coefficients\r
+    *  (subrutine to SimpleInterpolateLSF)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void LSFinterpolate2a_enc(\r
+       float *a,       /* (o) lpc coefficients */ \r
+       float *lsf1,/* (i) first set of lsf coefficients */\r
+       float *lsf2,/* (i) second set of lsf coefficients */\r
+       float coef,     /* (i) weighting coefficient to use between \r
+                              lsf1 and lsf2 */\r
+       long length      /* (i) length of coefficient vectors */\r
+   ){  \r
+       float  lsftmp[LPC_FILTERORDER];\r
+       \r
+       interpolate(lsftmp, lsf1, lsf2, coef, length);\r
+       lsf2a(a, lsftmp);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lsf interpolator (subrutine to LPCencode)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SimpleInterpolateLSF(\r
+       float *syntdenum,   /* (o) the synthesis filter denominator \r
+                                  resulting from the quantized \r
+                                  interpolated lsf */\r
+       float *weightdenum, /* (o) the weighting filter denominator \r
+                                  resulting from the unquantized \r
+                                  interpolated lsf */\r
+       float *lsf,         /* (i) the unquantized lsf coefficients */\r
+       float *lsfdeq,      /* (i) the dequantized lsf coefficients */\r
+       float *lsfold,      /* (i) the unquantized lsf coefficients of \r
+                                  the previous signal frame */\r
+       float *lsfdeqold, /* (i) the dequantized lsf coefficients of \r
+                                  the previous signal frame */\r
+       int length,         /* (i) should equate LPC_FILTERORDER */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   ){\r
+       int    i, pos, lp_length;\r
+       float  lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;\r
+       \r
+       lsf2 = lsf + length;\r
+       lsfdeq2 = lsfdeq + length;\r
+       lp_length = length + 1; \r
+    \r
+       if (iLBCenc_inst->mode==30) {\r
+           /* sub-frame 1: Interpolation between old and first \r
+              set of lsf coefficients */\r
+   \r
+           LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
+               lsf_weightTbl_30ms[0], length);\r
+           memcpy(syntdenum,lp,lp_length*sizeof(float));\r
+           LSFinterpolate2a_enc(lp, lsfold, lsf, \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    154\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               lsf_weightTbl_30ms[0], length);\r
+           bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+   \r
+           /* sub-frame 2 to 6: Interpolation between first \r
+              and second set of lsf coefficients */\r
+       \r
+           pos = lp_length;\r
+           for (i = 1; i < iLBCenc_inst->nsub; i++) {\r
+               LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, \r
+                   lsf_weightTbl_30ms[i], length);\r
+               memcpy(syntdenum + pos,lp,lp_length*sizeof(float));\r
+           \r
+               LSFinterpolate2a_enc(lp, lsf, lsf2, \r
+                   lsf_weightTbl_30ms[i], length);\r
+               bwexpand(weightdenum + pos, lp, \r
+                   LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       else {\r
+           pos = 0;\r
+           for (i = 0; i < iLBCenc_inst->nsub; i++) {\r
+               LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, \r
+                   lsf_weightTbl_20ms[i], length);\r
+               memcpy(syntdenum+pos,lp,lp_length*sizeof(float));\r
+               LSFinterpolate2a_enc(lp, lsfold, lsf, \r
+                   lsf_weightTbl_20ms[i], length);\r
+               bwexpand(weightdenum+pos, lp, \r
+                   LPC_CHIRP_WEIGHTDENUM, lp_length);\r
+               pos += lp_length;\r
+           }\r
+       }\r
+       \r
+       /* update memory */\r
+   \r
+       if (iLBCenc_inst->mode==30) {\r
+           memcpy(lsfold, lsf2, length*sizeof(float));\r
+           memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));\r
+       }\r
+       else {\r
+           memcpy(lsfold, lsf, length*sizeof(float));\r
+           memcpy(lsfdeqold, lsfdeq, length*sizeof(float));\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lsf quantizer (subrutine to LPCencode)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SimplelsfQ(\r
+       float *lsfdeq,    /* (o) dequantized lsf coefficients\r
+                              (dimension FILTERORDER) */\r
+       int *index,     /* (o) quantization index */\r
+       float *lsf,      /* (i) the lsf coefficient vector to be \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    155\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                              quantized (dimension FILTERORDER ) */\r
+       int lpc_n     /* (i) number of lsf sets to quantize */\r
+   ){    \r
+       /* Quantize first LSF with memoryless split VQ */\r
+       SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, \r
+           dim_lsfCbTbl, size_lsfCbTbl);\r
+   \r
+       if (lpc_n==2) {\r
+           /* Quantize second LSF with memoryless split VQ */\r
+           SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, \r
+               lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, \r
+               dim_lsfCbTbl, size_lsfCbTbl);\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lpc encoder\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void LPCencode( \r
+       float *syntdenum, /* (i/o) synthesis filter coefficients \r
+                                  before/after encoding */\r
+       float *weightdenum, /* (i/o) weighting denumerator \r
+                                  coefficients before/after \r
+                                  encoding */\r
+       int *lsf_index,     /* (o) lsf quantization index */\r
+       float *data,    /* (i) lsf coefficients to quantize */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst \r
+                           /* (i/o) the encoder state structure */\r
+   ){\r
+       float lsf[LPC_FILTERORDER * LPC_N_MAX];\r
+       float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];\r
+       int change=0;\r
+       \r
+       SimpleAnalysis(lsf, data, iLBCenc_inst);\r
+       SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);\r
+       change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);\r
+       SimpleInterpolateLSF(syntdenum, weightdenum, \r
+           lsf, lsfdeq, iLBCenc_inst->lsfold, \r
+           iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);\r
+   }\r
+   \r
+   \r
+   \r
+A.39 lsf.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       lsf.h             \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    156\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_LSF_H\r
+   #define __iLBC_LSF_H\r
+   \r
+   void a2lsf( \r
+       float *freq,/* (o) lsf coefficients */\r
+       float *a    /* (i) lpc coefficients */\r
+   );\r
+   \r
+   void lsf2a( \r
+       float *a_coef,  /* (o) lpc coefficients */\r
+       float *freq     /* (i) lsf coefficients */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.40 lsf.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       lsf.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   #include <math.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  conversion from lpc coefficients to lsf coefficients \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void a2lsf( \r
+       float *freq,/* (o) lsf coefficients */\r
+       float *a    /* (i) lpc coefficients */\r
+   ){\r
+       float steps[LSF_NUMBER_OF_STEPS] = \r
+           {(float)0.00635, (float)0.003175, (float)0.0015875, \r
+           (float)0.00079375};\r
+       float step;\r
+       int step_idx;\r
+       int lsp_index;  \r
+       float p[LPC_HALFORDER];\r
+       float q[LPC_HALFORDER];\r
+       float p_pre[LPC_HALFORDER];\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    157\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       float q_pre[LPC_HALFORDER];\r
+       float old_p, old_q, *old;\r
+       float *pq_coef; \r
+       float omega, old_omega;\r
+       int i;\r
+       float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;\r
+   \r
+       for (i=0; i<LPC_HALFORDER; i++) {\r
+           p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);\r
+           q[i] = a[LPC_FILTERORDER - i] - a[i + 1];\r
+       }\r
+       \r
+       p_pre[0] = (float)-1.0 - p[0];\r
+       p_pre[1] = - p_pre[0] - p[1];\r
+       p_pre[2] = - p_pre[1] - p[2];\r
+       p_pre[3] = - p_pre[2] - p[3];\r
+       p_pre[4] = - p_pre[3] - p[4];\r
+       p_pre[4] = p_pre[4] / 2;\r
+       \r
+       q_pre[0] = (float)1.0 - q[0];\r
+       q_pre[1] = q_pre[0] - q[1];\r
+       q_pre[2] = q_pre[1] - q[2];\r
+       q_pre[3] = q_pre[2] - q[3];\r
+       q_pre[4] = q_pre[3] - q[4];\r
+       q_pre[4] = q_pre[4] / 2;\r
+       \r
+       omega = 0.0;\r
+       old_omega = 0.0;\r
+   \r
+       old_p = FLOAT_MAX;\r
+       old_q = FLOAT_MAX;\r
+       \r
+       /* Here we loop through lsp_index to find all the \r
+          LPC_FILTERORDER roots for omega. */  \r
+   \r
+       for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {\r
+           \r
+           /* Depending on lsp_index being even or odd, we \r
+           alternatively solve the roots for the two LSP equations. */\r
+   \r
+           \r
+           if ((lsp_index & 0x1) == 0) {\r
+               pq_coef = p_pre;\r
+               old = &old_p;\r
+           } else {\r
+               pq_coef = q_pre;\r
+               old = &old_q;\r
+           }\r
+           \r
+           /* Start with low resolution grid */\r
+   \r
+           for (step_idx = 0, step = steps[step_idx]; \r
+               step_idx < LSF_NUMBER_OF_STEPS;){\r
+               \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    158\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+               /*  cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) + \r
+               pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */\r
+   \r
+               hlp = (float)cos(omega * TWO_PI);\r
+               hlp1 = (float)2.0 * hlp + pq_coef[0];\r
+               hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 + \r
+                   pq_coef[1];\r
+               hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];\r
+               hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];\r
+               hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];\r
+               \r
+               \r
+               if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){\r
+                   \r
+                   if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){\r
+                       \r
+                       if (fabs(hlp5) >= fabs(*old)) {\r
+                           freq[lsp_index] = omega - step;\r
+                       } else {\r
+                           freq[lsp_index] = omega;\r
+                       }   \r
+                       \r
+                       \r
+                       if ((*old) >= 0.0){\r
+                           *old = (float)-1.0 * FLOAT_MAX;\r
+                       } else {\r
+                           *old = FLOAT_MAX;\r
+                       }\r
+   \r
+                       omega = old_omega;\r
+                       step_idx = 0;\r
+                       \r
+                       step_idx = LSF_NUMBER_OF_STEPS;\r
+                   } else {\r
+                       \r
+                       if (step_idx == 0) {\r
+                           old_omega = omega;\r
+                       }\r
+   \r
+                       step_idx++;\r
+                       omega -= steps[step_idx];\r
+   \r
+                       /* Go back one grid step */\r
+   \r
+                       step = steps[step_idx];\r
+                   }\r
+               } else {\r
+                   \r
+               /* increment omega until they are of different sign, \r
+               and we know there is at least one root between omega \r
+               and old_omega */\r
+                   *old = hlp5;\r
+                   omega += step;\r
+               }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    159\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           }\r
+       }\r
+   \r
+       for (i = 0; i<LPC_FILTERORDER; i++) {\r
+           freq[i] = freq[i] * TWO_PI;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  conversion from lsf coefficients to lpc coefficients \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void lsf2a( \r
+       float *a_coef,  /* (o) lpc coefficients */\r
+       float *freq     /* (i) lsf coefficients */\r
+   ){\r
+       int i, j;\r
+       float hlp;\r
+       float p[LPC_HALFORDER], q[LPC_HALFORDER];\r
+       float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],\r
+           a2[LPC_HALFORDER];\r
+       float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER], \r
+           b2[LPC_HALFORDER];\r
+   \r
+       for (i=0; i<LPC_FILTERORDER; i++) {\r
+           freq[i] = freq[i] * PI2;\r
+       }\r
+   \r
+       /* Check input for ill-conditioned cases.  This part is not \r
+       found in the TIA standard.  It involves the following 2 IF \r
+       blocks. If "freq" is judged ill-conditioned, then we first \r
+       modify freq[0] and freq[LPC_HALFORDER-1] (normally \r
+       LPC_HALFORDER = 10 for LPC applications), then we adjust \r
+       the other "freq" values slightly */\r
+   \r
+       \r
+       if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){\r
+   \r
+           \r
+           if (freq[0] <= 0.0) {\r
+               freq[0] = (float)0.022;\r
+           }\r
+   \r
+           \r
+           if (freq[LPC_FILTERORDER - 1] >= 0.5) {\r
+               freq[LPC_FILTERORDER - 1] = (float)0.499;\r
+           }\r
+   \r
+           hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / \r
+               (float) (LPC_FILTERORDER - 1);\r
+   \r
+           for (i=1; i<LPC_FILTERORDER; i++) {\r
+               freq[i] = freq[i - 1] + hlp;\r
+           }\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    160\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       }\r
+       \r
+       memset(a1, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(a2, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(b1, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(b2, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));\r
+       memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));\r
+           \r
+       /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and \r
+       cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.  \r
+       Note that for this code p[i] specifies the coefficients \r
+       used in .Q_A(z) while q[i] specifies the coefficients used \r
+       in .P_A(z) */\r
+   \r
+       for (i=0; i<LPC_HALFORDER; i++) {\r
+           p[i] = (float)cos(TWO_PI * freq[2 * i]);\r
+           q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);\r
+       }\r
+       \r
+       a[0] = 0.25;\r
+       b[0] = 0.25;\r
+       \r
+       for (i= 0; i<LPC_HALFORDER; i++) {\r
+           a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
+           b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
+           a2[i] = a1[i];\r
+           a1[i] = a[i];\r
+           b2[i] = b1[i];\r
+           b1[i] = b[i];\r
+       }\r
+       \r
+       for (j=0; j<LPC_FILTERORDER; j++) {\r
+           \r
+           if (j == 0) {\r
+               a[0] = 0.25;\r
+               b[0] = -0.25;\r
+           } else {\r
+               a[0] = b[0] = 0.0;\r
+           }\r
+           \r
+           for (i=0; i<LPC_HALFORDER; i++) {\r
+               a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
+               b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
+               a2[i] = a1[i];\r
+               a1[i] = a[i];\r
+               b2[i] = b1[i];\r
+               b1[i] = b[i];\r
+           }\r
+   \r
+           a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);\r
+       }\r
+   \r
+       a_coef[0] = 1.0;\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    161\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   }\r
+   \r
+   \r
+A.41 packing.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       packing.h              \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __PACKING_H\r
+   #define __PACKING_H\r
+   \r
+   void packsplit(\r
+       int *index,                 /* (i) the value to split */\r
+       int *firstpart,             /* (o) the value specified by most \r
+                                          significant bits */\r
+       int *rest,                  /* (o) the value specified by least \r
+                                          significant bits */\r
+       int bitno_firstpart,    /* (i) number of bits in most \r
+                                          significant part */\r
+       int bitno_total             /* (i) number of bits in full range \r
+                                          of value */\r
+   );\r
+   \r
+   void packcombine( \r
+       int *index,                 /* (i/o) the msb value in the \r
+                                          combined value out */\r
+       int rest,                   /* (i) the lsb value */\r
+       int bitno_rest              /* (i) the number of bits in the \r
+                                          lsb part */\r
+   );\r
+   \r
+   void dopack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                          place in bitstream to pack \r
+                                          new data, on exit pointer \r
+                                          to place in bitstream to \r
+                                          pack future data */\r
+       int index,                  /* (i) the value to pack */\r
+       int bitno,                  /* (i) the number of bits that the \r
+                                          value will fit within */\r
+       int *pos                /* (i/o) write position in the \r
+                                          current byte */\r
+   );\r
+   \r
+   void unpack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    162\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                                          place in bitstream to \r
+                                          unpack new data from, on \r
+                                          exit pointer to place in \r
+                                          bitstream to unpack future \r
+                                          data from */\r
+       int *index,                 /* (o) resulting value */\r
+       int bitno,                  /* (i) number of bits used to \r
+                                          represent the value */\r
+       int *pos                /* (i/o) read position in the \r
+                                          current byte */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.42 packing.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       packing.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "helpfun.h"\r
+   #include "string.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  splitting an integer into first most significant bits and \r
+    *  remaining least significant bits\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void packsplit(\r
+       int *index,                 /* (i) the value to split */\r
+       int *firstpart,             /* (o) the value specified by most \r
+                                          significant bits */\r
+       int *rest,                  /* (o) the value specified by least\r
+                                          significant bits */\r
+       int bitno_firstpart,    /* (i) number of bits in most \r
+                                          significant part */\r
+       int bitno_total             /* (i) number of bits in full range\r
+                                          of value */\r
+   ){\r
+       int bitno_rest = bitno_total-bitno_firstpart;\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    163\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       *firstpart = *index>>(bitno_rest);\r
+       *rest = *index-(*firstpart<<(bitno_rest));\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  combining a value corresponding to msb's with a value \r
+    *  corresponding to lsb's\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void packcombine( \r
+       int *index,                 /* (i/o) the msb value in the \r
+                                          combined value out */\r
+       int rest,                   /* (i) the lsb value */\r
+       int bitno_rest              /* (i) the number of bits in the \r
+                                          lsb part */\r
+   ){\r
+       *index = *index<<bitno_rest;\r
+       *index += rest;\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  packing of bits into bitstream, i.e., vector of bytes\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void dopack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                          place in bitstream to pack \r
+                                          new data, on exit pointer \r
+                                          to place in bitstream to \r
+                                          pack future data */\r
+       int index,                  /* (i) the value to pack */\r
+       int bitno,                  /* (i) the number of bits that the \r
+                                          value will fit within */\r
+       int *pos                /* (i/o) write position in the \r
+                                          current byte */\r
+   ){\r
+       int posLeft;\r
+       \r
+       /* Clear the bits before starting in a new byte */\r
+       \r
+       if ((*pos)==0) {\r
+           **bitstream=0;\r
+       }\r
+   \r
+       while (bitno>0) {\r
+           \r
+           /* Jump to the next byte if end of this byte is reached*/\r
+           \r
+           if (*pos==8) {\r
+               *pos=0;\r
+               (*bitstream)++;\r
+               **bitstream=0;\r
+           }\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    164\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           posLeft=8-(*pos);\r
+   \r
+           /* Insert index into the bitstream */\r
+           \r
+           if (bitno <= posLeft) {\r
+               **bitstream |= (unsigned char)(index<<(posLeft-bitno));\r
+               *pos+=bitno;\r
+               bitno=0;\r
+           } else {\r
+               **bitstream |= (unsigned char)(index>>(bitno-posLeft));\r
+               \r
+               *pos=8;\r
+               index-=((index>>(bitno-posLeft))<<(bitno-posLeft));\r
+               \r
+               bitno-=posLeft;\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  unpacking of bits from bitstream, i.e., vector of bytes\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void unpack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                          place in bitstream to \r
+                                          unpack new data from, on \r
+                                          exit pointer to place in \r
+                                          bitstream to unpack future \r
+                                          data from */\r
+       int *index,                 /* (o) resulting value */\r
+       int bitno,                  /* (i) number of bits used to \r
+                                          represent the value */\r
+       int *pos                /* (i/o) read position in the \r
+                                          current byte */\r
+   ){\r
+       int BitsLeft;\r
+   \r
+       *index=0;\r
+   \r
+       while (bitno>0) {\r
+           \r
+           /* move forward in bitstream when the end of the \r
+              byte is reached */\r
+           \r
+           if (*pos==8) {\r
+               *pos=0;\r
+               (*bitstream)++;\r
+           }\r
+   \r
+           BitsLeft=8-(*pos);\r
+   \r
+           /* Extract bits to index */\r
+           \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    165\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           if (BitsLeft>=bitno) {\r
+               *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));\r
+               \r
+               *pos+=bitno;\r
+               bitno=0;\r
+           } else {\r
+               \r
+               if ((8-bitno)>0) {\r
+                   *index+=((((**bitstream)<<(*pos)) & 0xFF)>>\r
+                       (8-bitno));\r
+                   *pos=8;\r
+               } else {\r
+                   *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<\r
+                       (bitno-8));\r
+                   *pos=8;\r
+               }\r
+               bitno-=BitsLeft;\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+A.43 StateConstructW.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateConstructW.h  \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_STATECONSTRUCTW_H\r
+   #define __iLBC_STATECONSTRUCTW_H\r
+   \r
+   void StateConstructW( \r
+       int idxForMax,      /* (i) 6-bit index for the quantization of \r
+                                  max amplitude */\r
+       int *idxVec,    /* (i) vector of quantization indexes */\r
+       float *syntDenum,   /* (i) synthesis filter denumerator */\r
+       float *out,         /* (o) the decoded state vector */\r
+       int len             /* (i) length of a state vector */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.44 StateConstructW.c\r
+   \r
+   /******************************************************************\r
+   \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    166\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateConstructW.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h> \r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  decoding of the start state\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void StateConstructW( \r
+       int idxForMax,      /* (i) 6-bit index for the quantization of \r
+                                  max amplitude */\r
+       int *idxVec,    /* (i) vector of quantization indexes */\r
+       float *syntDenum,   /* (i) synthesis filter denumerator */\r
+       float *out,         /* (o) the decoded state vector */\r
+       int len             /* (i) length of a state vector */\r
+   ){\r
+       float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, \r
+           numerator[LPC_FILTERORDER+1];\r
+       float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;\r
+       int k,tmpi;\r
+       \r
+       /* decoding of the maximum value */\r
+   \r
+       maxVal = state_frgqTbl[idxForMax];\r
+       maxVal = (float)pow(10,maxVal)/(float)4.5;\r
+           \r
+       /* initialization of buffers and coefficients */\r
+       \r
+       memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       for (k=0; k<LPC_FILTERORDER; k++) {\r
+           numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
+       }\r
+       numerator[LPC_FILTERORDER]=syntDenum[0];\r
+       tmp = &tmpbuf[LPC_FILTERORDER];\r
+       fout = &foutbuf[LPC_FILTERORDER];\r
+   \r
+       /* decoding of the sample values */\r
+       \r
+       for (k=0; k<len; k++) {\r
+           tmpi = len-1-k;\r
+           /* maxVal = 1/scal */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    167\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];\r
+       }\r
+   \r
+       /* circular convolution with all-pass filter */\r
+   \r
+       memset(tmp+len, 0, len*sizeof(float));\r
+       ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
+           LPC_FILTERORDER, fout);\r
+       for (k=0;k<len;k++) {\r
+           out[k] = fout[len-1-k]+fout[2*len-1-k];\r
+       }\r
+   }\r
+   \r
+   \r
+A.45 StateSearchW.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateSearchW.h     \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_STATESEARCHW_H\r
+   #define __iLBC_STATESEARCHW_H\r
+   \r
+   void AbsQuantW(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *in,          /* (i) vector to encode */\r
+       float *syntDenum,   /* (i) denominator of synthesis filter */\r
+       float *weightDenum, /* (i) denominator of weighting filter */\r
+       int *out,           /* (o) vector of quantizer indexes */\r
+       int len,        /* (i) length of vector to encode and \r
+                                  vector of quantizer indexes */\r
+       int state_first     /* (i) position of start state in the \r
+                                  80 vec */\r
+   );\r
+   \r
+   void StateSearchW( \r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *residual,/* (i) target residual vector */\r
+       float *syntDenum,   /* (i) lpc synthesis filter */\r
+       float *weightDenum, /* (i) weighting filter denuminator */\r
+       int *idxForMax,     /* (o) quantizer index for maximum \r
+                                  amplitude */\r
+       int *idxVec,    /* (o) vector of quantization indexes */\r
+       int len,        /* (i) length of all vectors */\r
+       int state_first     /* (i) position of start state in the \r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    168\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+                                  80 vec */\r
+   );\r
+   \r
+   \r
+   #endif\r
+   \r
+   \r
+A.46 StateSearchW.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       StateSearchW.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h> \r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   #include "helpfun.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  predictive noise shaping encoding of scaled start state \r
+    *  (subrutine for StateSearchW) \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void AbsQuantW(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *in,          /* (i) vector to encode */\r
+       float *syntDenum,   /* (i) denominator of synthesis filter */\r
+       float *weightDenum, /* (i) denominator of weighting filter */\r
+       int *out,           /* (o) vector of quantizer indexes */\r
+       int len,        /* (i) length of vector to encode and \r
+                                  vector of quantizer indexes */\r
+       int state_first     /* (i) position of start state in the \r
+                                  80 vec */\r
+   ){\r
+       float *syntOut;\r
+       float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];\r
+       float toQ, xq;\r
+       int n;\r
+       int index;\r
+   \r
+       /* initialization of buffer for filtering */\r
+               \r
+       memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    169\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+       /* initialization of pointer for filtering */\r
+   \r
+       syntOut = &syntOutBuf[LPC_FILTERORDER];\r
+       \r
+       /* synthesis and weighting filters on input */\r
+       \r
+       if (state_first) {\r
+           AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);\r
+       } else {\r
+           AllPoleFilter (in, weightDenum, \r
+               iLBCenc_inst->state_short_len-SUBL, \r
+               LPC_FILTERORDER);\r
+       }\r
+   \r
+       /* encoding loop */\r
+   \r
+       for (n=0; n<len; n++) {\r
+           \r
+           /* time update of filter coefficients */  \r
+           \r
+           if ((state_first)&&(n==SUBL)){\r
+               syntDenum += (LPC_FILTERORDER+1);\r
+               weightDenum += (LPC_FILTERORDER+1);\r
+   \r
+               /* synthesis and weighting filters on input */\r
+               AllPoleFilter (&in[n], weightDenum, len-n, \r
+                   LPC_FILTERORDER);\r
+   \r
+           } else if ((state_first==0)&&\r
+               (n==(iLBCenc_inst->state_short_len-SUBL))) {\r
+               syntDenum += (LPC_FILTERORDER+1);\r
+               weightDenum += (LPC_FILTERORDER+1);\r
+   \r
+               /* synthesis and weighting filters on input */\r
+               AllPoleFilter (&in[n], weightDenum, len-n, \r
+                   LPC_FILTERORDER);\r
+               \r
+           }\r
+           \r
+           /* prediction of synthesized and weighted input */\r
+   \r
+           syntOut[n] = 0.0;\r
+           AllPoleFilter (&syntOut[n], weightDenum, 1, \r
+               LPC_FILTERORDER);\r
+           \r
+           /* quantization */      \r
+   \r
+           toQ = in[n]-syntOut[n];\r
+           sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);\r
+           out[n]=index;\r
+           syntOut[n] = state_sq3Tbl[out[n]];\r
+   \r
+           /* update of the prediction filter */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    170\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   \r
+           AllPoleFilter(&syntOut[n], weightDenum, 1, \r
+               LPC_FILTERORDER);\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  encoding of start state                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void StateSearchW( \r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  \r
+                           /* (i) Encoder instance */\r
+       float *residual,/* (i) target residual vector */\r
+       float *syntDenum,   /* (i) lpc synthesis filter */\r
+       float *weightDenum, /* (i) weighting filter denuminator */\r
+       int *idxForMax,     /* (o) quantizer index for maximum \r
+                                  amplitude */\r
+       int *idxVec,    /* (o) vector of quantization indexes */\r
+       int len,        /* (i) length of all vectors */\r
+       int state_first     /* (i) position of start state in the \r
+                                  80 vec */\r
+   ){  \r
+       float dtmp, maxVal;\r
+       float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];\r
+       float *tmp, numerator[1+LPC_FILTERORDER]; \r
+       float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;\r
+       int k;\r
+       float qmax, scal;\r
+       \r
+       /* initialization of buffers and filter coefficients */\r
+   \r
+       memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));\r
+       for (k=0; k<LPC_FILTERORDER; k++) {\r
+           numerator[k]=syntDenum[LPC_FILTERORDER-k];\r
+       }\r
+       numerator[LPC_FILTERORDER]=syntDenum[0];\r
+       tmp = &tmpbuf[LPC_FILTERORDER];\r
+       fout = &foutbuf[LPC_FILTERORDER];\r
+   \r
+       /* circular convolution with the all-pass filter */\r
+       \r
+       memcpy(tmp, residual, len*sizeof(float));\r
+       memset(tmp+len, 0, len*sizeof(float));\r
+       ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, \r
+           LPC_FILTERORDER, fout);\r
+       for (k=0; k<len; k++) {\r
+           fout[k] += fout[k+len];\r
+       }   \r
+           \r
+       /* identification of the maximum amplitude value */\r
+       \r
+       maxVal = fout[0];\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    171\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+       for (k=1; k<len; k++) {\r
+           \r
+           if (fout[k]*fout[k] > maxVal*maxVal){\r
+               maxVal = fout[k];\r
+           }\r
+       }\r
+       maxVal=(float)fabs(maxVal);\r
+           \r
+       /* encoding of the maximum amplitude value */\r
+       \r
+       if (maxVal < 10.0) {\r
+           maxVal = 10.0;\r
+       }\r
+       maxVal = (float)log10(maxVal);\r
+       sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);\r
+   \r
+       /* decoding of the maximum amplitude representation value,\r
+          and corresponding scaling of start state */\r
+   \r
+       maxVal=state_frgqTbl[*idxForMax];\r
+       qmax = (float)pow(10,maxVal);\r
+       scal = (float)(4.5)/qmax;\r
+       for (k=0; k<len; k++){\r
+           fout[k] *= scal;\r
+       }\r
+   \r
+       /* predictive noise shaping encoding of scaled start state */\r
+   \r
+       AbsQuantW(iLBCenc_inst, fout,syntDenum, \r
+           weightDenum,idxVec, len, state_first);\r
+   }\r
+   \r
+   \r
+A.47 syntFilter.h\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       syntFilter.h               \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_SYNTFILTER_H\r
+   #define __iLBC_SYNTFILTER_H\r
+   \r
+   void syntFilter(\r
+       float *Out,     /* (i/o) Signal to be filtered */\r
+       float *a,       /* (i) LP parameters */\r
+       int len,    /* (i) Length of signal */\r
+       float *mem      /* (i/o) Filter state */\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    172\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
+A.48 syntFilter.c\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       syntFilter.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  LP synthesis filter.\r
+    *---------------------------------------------------------------*/\r
+       \r
+   void syntFilter(\r
+       float *Out,     /* (i/o) Signal to be filtered */\r
+       float *a,       /* (i) LP parameters */\r
+       int len,    /* (i) Length of signal */\r
+       float *mem      /* (i/o) Filter state */\r
+   ){\r
+       int i, j;\r
+       float *po, *pi, *pa, *pm;\r
+   \r
+       po=Out;\r
+   \r
+       /* Filter first part using memory from past */\r
+   \r
+       for (i=0; i<LPC_FILTERORDER; i++) {\r
+           pi=&Out[i-1];\r
+           pa=&a[1];\r
+           pm=&mem[LPC_FILTERORDER-1];\r
+           for (j=1; j<=i; j++) {\r
+               *po-=(*pa++)*(*pi--);\r
+           }\r
+           for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
+               *po-=(*pa++)*(*pm--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Filter last part where the state is entierly in \r
+          the output vector */\r
+       \r
+       for (i=LPC_FILTERORDER; i<len; i++) {\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    173\r
+                     Internet Low Bit Rate Codec               May 04\r
+   \r
+           pi=&Out[i-1];\r
+           pa=&a[1];\r
+           for (j=1; j<LPC_FILTERORDER+1; j++) {\r
+               *po-=(*pa++)*(*pi--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Update state vector */\r
+   \r
+       memcpy(mem, &Out[len-LPC_FILTERORDER], \r
+           LPC_FILTERORDER*sizeof(float));\r
+   }\r
+   \r
+   \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+   \r
+   Andersen et. al.  Experimental - Expires November 29th, 2004    174\r
+\r
index 435811330e5aa9667a6c1e6fb32cabce699f43d1..4d5c87eeda6fad4b8d1a3debb039237c9d918e98 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    enhancer.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <string.h>\r
-#include "iLBC_define.h"\r
-#include "enhancer.h"\r
-#include "constants.h"\r
-#include "filter.h"\r
-\r
-/*----------------------------------------------------------------*\r
-\r
-\r
- * Find index in array such that the array element with said\r
- * index is the element of said array closest to "value" \r
- * according to the squared-error criterion\r
- *---------------------------------------------------------------*/\r
-\r
-static void NearestNeighbor(\r
-    int   *index,   /* (o) index of array element closest \r
-                           to value */\r
-    float *array,   /* (i) data array */\r
-    float value,/* (i) value */\r
-    int arlength/* (i) dimension of data array */\r
-){\r
-    int i;\r
-    float bestcrit,crit;\r
-\r
-    crit=array[0]-value;\r
-    bestcrit=crit*crit;\r
-    *index=0;\r
-    for (i=1; i<arlength; i++) {\r
-        crit=array[i]-value;\r
-        crit=crit*crit;\r
-        \r
-        if (crit<bestcrit) {\r
-            bestcrit=crit;\r
-            *index=i;\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * compute cross correlation between sequences\r
- *---------------------------------------------------------------*/\r
-\r
-static void mycorr1( \r
-    float* corr,    /* (o) correlation of seq1 and seq2 */\r
-    float* seq1,    /* (i) first sequence */\r
-    int dim1,           /* (i) dimension first seq1 */\r
-    const float *seq2,  /* (i) second sequence */\r
-    int dim2        /* (i) dimension seq2 */\r
-){\r
-    int i,j;\r
-\r
-    for (i=0; i<=dim1-dim2; i++) {\r
-        corr[i]=0.0;\r
-        for (j=0; j<dim2; j++) {\r
-            corr[i] += seq1[i+j] * seq2[j];\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * upsample finite array assuming zeros outside bounds\r
- *---------------------------------------------------------------*/\r
-\r
-\r
-\r
-static void enh_upsample( \r
-    float* useq1,   /* (o) upsampled output sequence */\r
-    float* seq1,/* (i) unupsampled sequence */\r
-    int dim1,       /* (i) dimension seq1 */\r
-    int hfl         /* (i) polyphase filter length=2*hfl+1 */\r
-){\r
-    float *pu,*ps;\r
-    int i,j,k,q,filterlength,hfl2;\r
-    const float *polyp[ENH_UPS0]; /* pointers to \r
-                                     polyphase columns */\r
-    const float *pp;\r
-\r
-    /* define pointers for filter */\r
-\r
-    filterlength=2*hfl+1;\r
-    \r
-    if ( filterlength > dim1 ) {\r
-        hfl2=(int) (dim1/2);\r
-        for (j=0; j<ENH_UPS0; j++) {\r
-            polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;\r
-        }\r
-        hfl=hfl2;\r
-        filterlength=2*hfl+1;\r
-    }\r
-    else {\r
-        for (j=0; j<ENH_UPS0; j++) {\r
-            polyp[j]=polyphaserTbl+j*filterlength;\r
-        }\r
-    }\r
-\r
-    /* filtering: filter overhangs left side of sequence */\r
-\r
-    pu=useq1;\r
-    for (i=hfl; i<filterlength; i++) { \r
-        for (j=0; j<ENH_UPS0; j++) {\r
-            *pu=0.0;\r
-            pp = polyp[j];\r
-            ps = seq1+i;\r
-            for (k=0; k<=i; k++) {\r
-                *pu += *ps-- * *pp++;\r
-            }\r
-            pu++;\r
-        }\r
-    }\r
-\r
-    /* filtering: simple convolution=inner products */\r
-\r
-    for (i=filterlength; i<dim1; i++) {\r
-        for (j=0;j<ENH_UPS0; j++){\r
-            *pu=0.0;\r
-            pp = polyp[j];\r
-            ps = seq1+i;\r
-            for (k=0; k<filterlength; k++) {\r
-                *pu += *ps-- * *pp++;\r
-\r
-\r
-            }\r
-            pu++;\r
-        }\r
-    }\r
-\r
-    /* filtering: filter overhangs right side of sequence */\r
-\r
-    for (q=1; q<=hfl; q++) { \r
-        for (j=0; j<ENH_UPS0; j++) {\r
-            *pu=0.0;\r
-            pp = polyp[j]+q;\r
-            ps = seq1+dim1-1;\r
-            for (k=0; k<filterlength-q; k++) {\r
-                *pu += *ps-- * *pp++;\r
-            }\r
-            pu++;\r
-        }\r
-    }\r
-}\r
-\r
-\r
-/*----------------------------------------------------------------*\r
- * find segment starting near idata+estSegPos that has highest \r
- * correlation with idata+centerStartPos through \r
- * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a \r
- * resolution of ENH_UPSO times the original of the original \r
- * sampling rate\r
- *---------------------------------------------------------------*/\r
-\r
-static void refiner(\r
-    float *seg,         /* (o) segment array */\r
-    float *updStartPos, /* (o) updated start point */\r
-    float* idata,       /* (i) original data buffer */\r
-    int idatal,         /* (i) dimension of idata */\r
-    int centerStartPos, /* (i) beginning center segment */\r
-    float estSegPos,/* (i) estimated beginning other segment */\r
-    float period    /* (i) estimated pitch period */\r
-){\r
-    int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;\r
-    int tloc,tloc2,i,st,en,fraction;\r
-    float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;\r
-    float corrVecUps[ENH_CORRDIM*ENH_UPS0];\r
-\r
-    /* defining array bounds */\r
-    \r
-    estSegPosRounded=(int)(estSegPos - 0.5);\r
-\r
-    searchSegStartPos=estSegPosRounded-ENH_SLOP;\r
-    \r
-    if (searchSegStartPos<0) { \r
-        searchSegStartPos=0;\r
-    }\r
-    searchSegEndPos=estSegPosRounded+ENH_SLOP;\r
-    \r
-\r
-\r
-    if (searchSegEndPos+ENH_BLOCKL >= idatal) { \r
-        searchSegEndPos=idatal-ENH_BLOCKL-1;\r
-    }\r
-    corrdim=searchSegEndPos-searchSegStartPos+1;\r
-    \r
-    /* compute upsampled correlation (corr33) and find \r
-       location of max */\r
-\r
-    mycorr1(corrVec,idata+searchSegStartPos,\r
-        corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);\r
-    enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);\r
-    tloc=0; maxv=corrVecUps[0];\r
-    for (i=1; i<ENH_UPS0*corrdim; i++) {\r
-        \r
-        if (corrVecUps[i]>maxv) {\r
-            tloc=i;\r
-            maxv=corrVecUps[i];\r
-        }\r
-    }\r
-    \r
-    /* make vector can be upsampled without ever running outside \r
-       bounds */\r
-    \r
-    *updStartPos= (float)searchSegStartPos + \r
-        (float)tloc/(float)ENH_UPS0+(float)1.0;\r
-    tloc2=(int)(tloc/ENH_UPS0);\r
-    \r
-    if (tloc>tloc2*ENH_UPS0) {\r
-        tloc2++;\r
-    }\r
-    st=searchSegStartPos+tloc2-ENH_FL0;\r
-    \r
-    if (st<0) {\r
-        memset(vect,0,-st*sizeof(float));\r
-        memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));\r
-    }\r
-    else {\r
-        en=st+ENH_VECTL;\r
-        \r
-        if (en>idatal) {\r
-            memcpy(vect, &idata[st], \r
-                (ENH_VECTL-(en-idatal))*sizeof(float));\r
-            memset(&vect[ENH_VECTL-(en-idatal)], 0, \r
-                (en-idatal)*sizeof(float));\r
-        }\r
-        else {\r
-            memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));\r
-        }\r
-    }\r
-    fraction=tloc2*ENH_UPS0-tloc;\r
-    \r
-    /* compute the segment (this is actually a convolution) */\r
-\r
-    mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,\r
-\r
-\r
-        2*ENH_FL0+1);\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * find the smoothed output data\r
- *---------------------------------------------------------------*/\r
-\r
-static void smath(\r
-    float *odata,   /* (o) smoothed output */\r
-    float *sseq,/* (i) said second sequence of waveforms */\r
-    int hl,         /* (i) 2*hl+1 is sseq dimension */\r
-    float alpha0/* (i) max smoothing energy fraction */\r
-){\r
-    int i,k;\r
-    float w00,w10,w11,A,B,C,*psseq,err,errs;\r
-    float surround[BLOCKL_MAX]; /* shape contributed by other than \r
-                                   current */\r
-    float wt[2*ENH_HL+1];       /* waveform weighting to get \r
-                                   surround shape */\r
-    float denom;\r
-    \r
-    /* create shape of contribution from all waveforms except the\r
-       current one */\r
-\r
-    for (i=1; i<=2*hl+1; i++) {\r
-        wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); \r
-    }\r
-    wt[hl]=0.0; /* for clarity, not used */\r
-    for (i=0; i<ENH_BLOCKL; i++) {\r
-        surround[i]=sseq[i]*wt[0];\r
-    }\r
-    for (k=1; k<hl; k++) {\r
-        psseq=sseq+k*ENH_BLOCKL;\r
-        for(i=0;i<ENH_BLOCKL; i++) {\r
-            surround[i]+=psseq[i]*wt[k];\r
-        }\r
-    }\r
-    for (k=hl+1; k<=2*hl; k++) {\r
-        psseq=sseq+k*ENH_BLOCKL;\r
-        for(i=0;i<ENH_BLOCKL; i++) {\r
-            surround[i]+=psseq[i]*wt[k];\r
-        }\r
-    }\r
-    \r
-    /* compute some inner products */\r
-\r
-    w00 = w10 = w11 = 0.0;\r
-    psseq=sseq+hl*ENH_BLOCKL; /* current block  */\r
-    for (i=0; i<ENH_BLOCKL;i++) {\r
-        w00+=psseq[i]*psseq[i];\r
-        w11+=surround[i]*surround[i];\r
-        w10+=surround[i]*psseq[i];\r
-    }\r
-    \r
-\r
-\r
-    if (fabs(w11) < 1.0) {\r
-        w11=1.0;\r
-    }\r
-    C = (float)sqrt( w00/w11);\r
-    \r
-    /* first try enhancement without power-constraint */\r
-\r
-    errs=0.0;\r
-    psseq=sseq+hl*ENH_BLOCKL;\r
-    for (i=0; i<ENH_BLOCKL; i++) {\r
-        odata[i]=C*surround[i];\r
-        err=psseq[i]-odata[i];\r
-        errs+=err*err;\r
-    }\r
-    \r
-    /* if constraint violated by first try, add constraint */ \r
-    \r
-    if (errs > alpha0 * w00) {\r
-        if ( w00 < 1) {\r
-            w00=1;\r
-        }\r
-        denom = (w11*w00-w10*w10)/(w00*w00);\r
-        \r
-        if (denom > 0.0001) { /* eliminates numerical problems \r
-                                 for if smooth */\r
-            A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);\r
-            B = -alpha0/2 - A * w10/w00;\r
-            B = B+1;\r
-        }\r
-        else { /* essentially no difference between cycles; \r
-                  smoothing not needed */\r
-            A= 0.0;\r
-            B= 1.0;\r
-        }\r
-        \r
-        /* create smoothed sequence */\r
-\r
-        psseq=sseq+hl*ENH_BLOCKL;\r
-        for (i=0; i<ENH_BLOCKL; i++) {\r
-            odata[i]=A*surround[i]+B*psseq[i];\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * get the pitch-synchronous sample sequence\r
- *---------------------------------------------------------------*/\r
-\r
-static void getsseq(\r
-    float *sseq,    /* (o) the pitch-synchronous sequence */\r
-    float *idata,       /* (i) original data */\r
-    int idatal,         /* (i) dimension of data */\r
-    int centerStartPos, /* (i) where current block starts */\r
-    float *period,      /* (i) rough-pitch-period array */\r
-\r
-\r
-    float *plocs,       /* (i) where periods of period array \r
-                               are taken */\r
-    int periodl,    /* (i) dimension period array */\r
-    int hl              /* (i) 2*hl+1 is the number of sequences */\r
-){\r
-    int i,centerEndPos,q;\r
-    float blockStartPos[2*ENH_HL+1];\r
-    int lagBlock[2*ENH_HL+1];\r
-    float plocs2[ENH_PLOCSL]; \r
-    float *psseq;\r
-\r
-    centerEndPos=centerStartPos+ENH_BLOCKL-1;\r
-    \r
-    /* present */\r
-\r
-    NearestNeighbor(lagBlock+hl,plocs,\r
-        (float)0.5*(centerStartPos+centerEndPos),periodl);\r
-    \r
-    blockStartPos[hl]=(float)centerStartPos;\r
-    psseq=sseq+ENH_BLOCKL*hl;\r
-    memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));\r
-    \r
-    /* past */\r
-\r
-    for (q=hl-1; q>=0; q--) {\r
-        blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];\r
-        NearestNeighbor(lagBlock+q,plocs,\r
-            blockStartPos[q]+\r
-            ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);\r
-                            \r
-        \r
-        if (blockStartPos[q]-ENH_OVERHANG>=0) {\r
-            refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,\r
-                idatal, centerStartPos, blockStartPos[q],\r
-                period[lagBlock[q+1]]);\r
-        } else {\r
-            psseq=sseq+q*ENH_BLOCKL;\r
-            memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
-        }\r
-    }\r
-    \r
-    /* future */\r
-\r
-    for (i=0; i<periodl; i++) {\r
-        plocs2[i]=plocs[i]-period[i];\r
-    }\r
-    for (q=hl+1; q<=2*hl; q++) { \r
-        NearestNeighbor(lagBlock+q,plocs2,\r
-            blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);\r
-\r
-        blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];\r
-        if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {\r
-            refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,\r
-                idatal, centerStartPos, blockStartPos[q],\r
-\r
-\r
-                period[lagBlock[q]]);\r
-        }\r
-        else {\r
-            psseq=sseq+q*ENH_BLOCKL;\r
-            memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * perform enhancement on idata+centerStartPos through \r
- * idata+centerStartPos+ENH_BLOCKL-1\r
- *---------------------------------------------------------------*/\r
-\r
-static void enhancer(\r
-    float *odata,       /* (o) smoothed block, dimension blockl */\r
-    float *idata,       /* (i) data buffer used for enhancing */\r
-    int idatal,         /* (i) dimension idata */\r
-    int centerStartPos, /* (i) first sample current block \r
-                               within idata */\r
-    float alpha0,       /* (i) max correction-energy-fraction \r
-                              (in [0,1]) */\r
-    float *period,      /* (i) pitch period array */\r
-    float *plocs,       /* (i) locations where period array \r
-                               values valid */\r
-    int periodl         /* (i) dimension of period and plocs */\r
-){\r
-    float sseq[(2*ENH_HL+1)*ENH_BLOCKL];\r
-\r
-    /* get said second sequence of segments */\r
-\r
-    getsseq(sseq,idata,idatal,centerStartPos,period,\r
-        plocs,periodl,ENH_HL);\r
-\r
-    /* compute the smoothed output from said second sequence */\r
-\r
-    smath(odata,sseq,ENH_HL,alpha0);\r
-\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * cross correlation\r
- *---------------------------------------------------------------*/\r
-\r
-float xCorrCoef( \r
-    float *target,      /* (i) first array */\r
-    float *regressor,   /* (i) second array */\r
-    int subl        /* (i) dimension arrays */\r
-){\r
-    int i;\r
-    float ftmp1, ftmp2;\r
-        \r
-    ftmp1 = 0.0;\r
-    ftmp2 = 0.0;\r
-\r
-\r
-    for (i=0; i<subl; i++) {\r
-        ftmp1 += target[i]*regressor[i];\r
-        ftmp2 += regressor[i]*regressor[i]; \r
-    }\r
-    \r
-    if (ftmp1 > 0.0) {\r
-        return (float)(ftmp1*ftmp1/ftmp2);\r
-    }\r
-    else {\r
-        return (float)0.0;\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * interface for enhancer\r
- *---------------------------------------------------------------*/\r
-\r
-int enhancerInterface(\r
-    float *out,                     /* (o) enhanced signal */\r
-    float *in,                      /* (i) unenhanced signal */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst   /* (i) buffers etc */\r
-){\r
-    float *enh_buf, *enh_period;\r
-    int iblock, isample;\r
-    int lag=0, ilag, i, ioffset;\r
-    float cc, maxcc;\r
-    float ftmp1, ftmp2;\r
-    float *inPtr, *enh_bufPtr1, *enh_bufPtr2;\r
-    float plc_pred[ENH_BLOCKL];\r
-\r
-    float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];\r
-    int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;\r
-    int start, plc_blockl, inlag;\r
-\r
-    enh_buf=iLBCdec_inst->enh_buf;\r
-    enh_period=iLBCdec_inst->enh_period;\r
-    \r
-    memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], \r
-        (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));\r
-                                                            \r
-    memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, \r
-        iLBCdec_inst->blockl*sizeof(float));\r
-\r
-    if (iLBCdec_inst->mode==30)\r
-        plc_blockl=ENH_BLOCKL;\r
-    else\r
-        plc_blockl=40;\r
-\r
-    /* when 20 ms frame, move processing one block */\r
-    ioffset=0;\r
-    if (iLBCdec_inst->mode==20) ioffset=1;\r
-\r
-    i=3-ioffset;\r
-    memmove(enh_period, &enh_period[i], \r
-\r
-\r
-        (ENH_NBLOCKS_TOT-i)*sizeof(float));\r
-\r
-    /* Set state information to the 6 samples right before \r
-       the samples to be downsampled. */\r
-\r
-    memcpy(lpState, \r
-        enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126, \r
-        6*sizeof(float));\r
-\r
-    /* Down sample a factor 2 to save computations */\r
-\r
-    DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,\r
-                lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,\r
-                lpState, downsampled);\r
-\r
-    /* Estimate the pitch in the down sampled domain. */\r
-    for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {\r
-        \r
-        lag = 10;\r
-        maxcc = xCorrCoef(downsampled+60+iblock*\r
-            ENH_BLOCKL_HALF, downsampled+60+iblock*\r
-            ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);\r
-        for (ilag=11; ilag<60; ilag++) {\r
-            cc = xCorrCoef(downsampled+60+iblock*\r
-                ENH_BLOCKL_HALF, downsampled+60+iblock*\r
-                ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);\r
-            \r
-            if (cc > maxcc) {\r
-                maxcc = cc;\r
-                lag = ilag;\r
-            }\r
-        }\r
-\r
-        /* Store the estimated lag in the non-downsampled domain */\r
-        enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;\r
-\r
-\r
-    }   \r
-\r
-\r
-    /* PLC was performed on the previous packet */\r
-    if (iLBCdec_inst->prev_enh_pl==1) {\r
-\r
-        inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];\r
-\r
-        lag = inlag-1;\r
-        maxcc = xCorrCoef(in, in+lag, plc_blockl);\r
-        for (ilag=inlag; ilag<=inlag+1; ilag++) {\r
-            cc = xCorrCoef(in, in+ilag, plc_blockl);\r
-            \r
-            if (cc > maxcc) {\r
-                maxcc = cc;\r
-                lag = ilag;\r
-            }\r
-        }\r
-\r
-\r
-\r
-        enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;\r
-\r
-        /* compute new concealed residual for the old lookahead,\r
-           mix the forward PLC with a backward PLC from \r
-           the new frame */\r
-        \r
-        inPtr=&in[lag-1];\r
-        \r
-        enh_bufPtr1=&plc_pred[plc_blockl-1];\r
-        \r
-        if (lag>plc_blockl) {\r
-            start=plc_blockl;\r
-        } else {\r
-            start=lag;\r
-        }\r
-\r
-        for (isample = start; isample>0; isample--) {\r
-            *enh_bufPtr1-- = *inPtr--;\r
-        }\r
-        \r
-        enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
-        for (isample = (plc_blockl-1-lag); isample>=0; isample--) \r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       enhancer.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+   \r
+   \r
+    * Find index in array such that the array element with said\r
+    * index is the element of said array closest to "value" \r
+    * according to the squared-error criterion\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void NearestNeighbor(\r
+       int   *index,   /* (o) index of array element closest \r
+                              to value */\r
+       float *array,   /* (i) data array */\r
+       float value,/* (i) value */\r
+       int arlength/* (i) dimension of data array */\r
+   ){\r
+       int i;\r
+       float bestcrit,crit;\r
+   \r
+       crit=array[0]-value;\r
+       bestcrit=crit*crit;\r
+       *index=0;\r
+       for (i=1; i<arlength; i++) {\r
+           crit=array[i]-value;\r
+           crit=crit*crit;\r
+           \r
+           if (crit<bestcrit) {\r
+               bestcrit=crit;\r
+               *index=i;\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * compute cross correlation between sequences\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void mycorr1( \r
+       float* corr,    /* (o) correlation of seq1 and seq2 */\r
+       float* seq1,    /* (i) first sequence */\r
+       int dim1,           /* (i) dimension first seq1 */\r
+       const float *seq2,  /* (i) second sequence */\r
+       int dim2        /* (i) dimension seq2 */\r
+   ){\r
+       int i,j;\r
+   \r
+       for (i=0; i<=dim1-dim2; i++) {\r
+           corr[i]=0.0;\r
+           for (j=0; j<dim2; j++) {\r
+               corr[i] += seq1[i+j] * seq2[j];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * upsample finite array assuming zeros outside bounds\r
+    *---------------------------------------------------------------*/\r
+   \r
+   \r
+   \r
+   void enh_upsample( \r
+       float* useq1,   /* (o) upsampled output sequence */\r
+       float* seq1,/* (i) unupsampled sequence */\r
+       int dim1,       /* (i) dimension seq1 */\r
+       int hfl         /* (i) polyphase filter length=2*hfl+1 */\r
+   ){\r
+       float *pu,*ps;\r
+       int i,j,k,q,filterlength,hfl2;\r
+       const float *polyp[ENH_UPS0]; /* pointers to \r
+                                        polyphase columns */\r
+       const float *pp;\r
+   \r
+       /* define pointers for filter */\r
+   \r
+       filterlength=2*hfl+1;\r
+       \r
+       if ( filterlength > dim1 ) {\r
+           hfl2=(int) (dim1/2);\r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;\r
+           }\r
+           hfl=hfl2;\r
+           filterlength=2*hfl+1;\r
+       }\r
+       else {\r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               polyp[j]=polyphaserTbl+j*filterlength;\r
+           }\r
+       }\r
+   \r
+       /* filtering: filter overhangs left side of sequence */\r
+   \r
+       pu=useq1;\r
+       for (i=hfl; i<filterlength; i++) { \r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               *pu=0.0;\r
+               pp = polyp[j];\r
+               ps = seq1+i;\r
+               for (k=0; k<=i; k++) {\r
+                   *pu += *ps-- * *pp++;\r
+               }\r
+               pu++;\r
+           }\r
+       }\r
+   \r
+       /* filtering: simple convolution=inner products */\r
+   \r
+       for (i=filterlength; i<dim1; i++) {\r
+           for (j=0;j<ENH_UPS0; j++){\r
+               *pu=0.0;\r
+               pp = polyp[j];\r
+               ps = seq1+i;\r
+               for (k=0; k<filterlength; k++) {\r
+                   *pu += *ps-- * *pp++;\r
+   \r
+   \r
+               }\r
+               pu++;\r
+           }\r
+       }\r
+   \r
+       /* filtering: filter overhangs right side of sequence */\r
+   \r
+       for (q=1; q<=hfl; q++) { \r
+           for (j=0; j<ENH_UPS0; j++) {\r
+               *pu=0.0;\r
+               pp = polyp[j]+q;\r
+               ps = seq1+dim1-1;\r
+               for (k=0; k<filterlength-q; k++) {\r
+                   *pu += *ps-- * *pp++;\r
+               }\r
+               pu++;\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    * find segment starting near idata+estSegPos that has highest \r
+    * correlation with idata+centerStartPos through \r
+    * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a \r
+    * resolution of ENH_UPSO times the original of the original \r
+    * sampling rate\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void refiner(\r
+       float *seg,         /* (o) segment array */\r
+       float *updStartPos, /* (o) updated start point */\r
+       float* idata,       /* (i) original data buffer */\r
+       int idatal,         /* (i) dimension of idata */\r
+       int centerStartPos, /* (i) beginning center segment */\r
+       float estSegPos,/* (i) estimated beginning other segment */\r
+       float period    /* (i) estimated pitch period */\r
+   ){\r
+       int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;\r
+       int tloc,tloc2,i,st,en,fraction;\r
+       float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;\r
+       float corrVecUps[ENH_CORRDIM*ENH_UPS0];\r
+   \r
+       /* defining array bounds */\r
+       \r
+       estSegPosRounded=(int)(estSegPos - 0.5);\r
+   \r
+       searchSegStartPos=estSegPosRounded-ENH_SLOP;\r
+       \r
+       if (searchSegStartPos<0) { \r
+           searchSegStartPos=0;\r
+       }\r
+       searchSegEndPos=estSegPosRounded+ENH_SLOP;\r
+       \r
+   \r
+   \r
+       if (searchSegEndPos+ENH_BLOCKL >= idatal) { \r
+           searchSegEndPos=idatal-ENH_BLOCKL-1;\r
+       }\r
+       corrdim=searchSegEndPos-searchSegStartPos+1;\r
+       \r
+       /* compute upsampled correlation (corr33) and find \r
+          location of max */\r
+   \r
+       mycorr1(corrVec,idata+searchSegStartPos,\r
+           corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);\r
+       enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);\r
+       tloc=0; maxv=corrVecUps[0];\r
+       for (i=1; i<ENH_UPS0*corrdim; i++) {\r
+           \r
+           if (corrVecUps[i]>maxv) {\r
+               tloc=i;\r
+               maxv=corrVecUps[i];\r
+           }\r
+       }\r
+       \r
+       /* make vector can be upsampled without ever running outside \r
+          bounds */\r
+       \r
+       *updStartPos= (float)searchSegStartPos + \r
+           (float)tloc/(float)ENH_UPS0+(float)1.0;\r
+       tloc2=(int)(tloc/ENH_UPS0);\r
+       \r
+       if (tloc>tloc2*ENH_UPS0) {\r
+           tloc2++;\r
+       }\r
+       st=searchSegStartPos+tloc2-ENH_FL0;\r
+       \r
+       if (st<0) {\r
+           memset(vect,0,-st*sizeof(float));\r
+           memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));\r
+       }\r
+       else {\r
+           en=st+ENH_VECTL;\r
+           \r
+           if (en>idatal) {\r
+               memcpy(vect, &idata[st], \r
+                   (ENH_VECTL-(en-idatal))*sizeof(float));\r
+               memset(&vect[ENH_VECTL-(en-idatal)], 0, \r
+                   (en-idatal)*sizeof(float));\r
+           }\r
+           else {\r
+               memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));\r
+           }\r
+       }\r
+       fraction=tloc2*ENH_UPS0-tloc;\r
+       \r
+       /* compute the segment (this is actually a convolution) */\r
+   \r
+       mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,\r
+   \r
+   \r
+           2*ENH_FL0+1);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * find the smoothed output data\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void smath(\r
+       float *odata,   /* (o) smoothed output */\r
+       float *sseq,/* (i) said second sequence of waveforms */\r
+       int hl,         /* (i) 2*hl+1 is sseq dimension */\r
+       float alpha0/* (i) max smoothing energy fraction */\r
+   ){\r
+       int i,k;\r
+       float w00,w10,w11,A,B,C,*psseq,err,errs;\r
+       float surround[BLOCKL_MAX]; /* shape contributed by other than \r
+                                      current */\r
+       float wt[2*ENH_HL+1];       /* waveform weighting to get \r
+                                      surround shape */\r
+       float denom;\r
+       \r
+       /* create shape of contribution from all waveforms except the\r
+          current one */\r
+   \r
+       for (i=1; i<=2*hl+1; i++) {\r
+           wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); \r
+       }\r
+       wt[hl]=0.0; /* for clarity, not used */\r
+       for (i=0; i<ENH_BLOCKL; i++) {\r
+           surround[i]=sseq[i]*wt[0];\r
+       }\r
+       for (k=1; k<hl; k++) {\r
+           psseq=sseq+k*ENH_BLOCKL;\r
+           for(i=0;i<ENH_BLOCKL; i++) {\r
+               surround[i]+=psseq[i]*wt[k];\r
+           }\r
+       }\r
+       for (k=hl+1; k<=2*hl; k++) {\r
+           psseq=sseq+k*ENH_BLOCKL;\r
+           for(i=0;i<ENH_BLOCKL; i++) {\r
+               surround[i]+=psseq[i]*wt[k];\r
+           }\r
+       }\r
+       \r
+       /* compute some inner products */\r
+   \r
+       w00 = w10 = w11 = 0.0;\r
+       psseq=sseq+hl*ENH_BLOCKL; /* current block  */\r
+       for (i=0; i<ENH_BLOCKL;i++) {\r
+           w00+=psseq[i]*psseq[i];\r
+           w11+=surround[i]*surround[i];\r
+           w10+=surround[i]*psseq[i];\r
+       }\r
+       \r
+   \r
+   \r
+       if (fabs(w11) < 1.0) {\r
+           w11=1.0;\r
+       }\r
+       C = (float)sqrt( w00/w11);\r
+       \r
+       /* first try enhancement without power-constraint */\r
+   \r
+       errs=0.0;\r
+       psseq=sseq+hl*ENH_BLOCKL;\r
+       for (i=0; i<ENH_BLOCKL; i++) {\r
+           odata[i]=C*surround[i];\r
+           err=psseq[i]-odata[i];\r
+           errs+=err*err;\r
+       }\r
+       \r
+       /* if constraint violated by first try, add constraint */ \r
+       \r
+       if (errs > alpha0 * w00) {\r
+           if ( w00 < 1) {\r
+               w00=1;\r
+           }\r
+           denom = (w11*w00-w10*w10)/(w00*w00);\r
+           \r
+           if (denom > 0.0001) { /* eliminates numerical problems \r
+                                    for if smooth */\r
+               A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);\r
+               B = -alpha0/2 - A * w10/w00;\r
+               B = B+1;\r
+           }\r
+           else { /* essentially no difference between cycles; \r
+                     smoothing not needed */\r
+               A= 0.0;\r
+               B= 1.0;\r
+           }\r
+           \r
+           /* create smoothed sequence */\r
+   \r
+           psseq=sseq+hl*ENH_BLOCKL;\r
+           for (i=0; i<ENH_BLOCKL; i++) {\r
+               odata[i]=A*surround[i]+B*psseq[i];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * get the pitch-synchronous sample sequence\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void getsseq(\r
+       float *sseq,    /* (o) the pitch-synchronous sequence */\r
+       float *idata,       /* (i) original data */\r
+       int idatal,         /* (i) dimension of data */\r
+       int centerStartPos, /* (i) where current block starts */\r
+       float *period,      /* (i) rough-pitch-period array */\r
+   \r
+   \r
+       float *plocs,       /* (i) where periods of period array \r
+                                  are taken */\r
+       int periodl,    /* (i) dimension period array */\r
+       int hl              /* (i) 2*hl+1 is the number of sequences */\r
+   ){\r
+       int i,centerEndPos,q;\r
+       float blockStartPos[2*ENH_HL+1];\r
+       int lagBlock[2*ENH_HL+1];\r
+       float plocs2[ENH_PLOCSL]; \r
+       float *psseq;\r
+   \r
+       centerEndPos=centerStartPos+ENH_BLOCKL-1;\r
+       \r
+       /* present */\r
+   \r
+       NearestNeighbor(lagBlock+hl,plocs,\r
+           (float)0.5*(centerStartPos+centerEndPos),periodl);\r
+       \r
+       blockStartPos[hl]=(float)centerStartPos;\r
+       psseq=sseq+ENH_BLOCKL*hl;\r
+       memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));\r
+       \r
+       /* past */\r
+   \r
+       for (q=hl-1; q>=0; q--) {\r
+           blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];\r
+           NearestNeighbor(lagBlock+q,plocs,\r
+               blockStartPos[q]+\r
+               ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);\r
+                               \r
+           \r
+           if (blockStartPos[q]-ENH_OVERHANG>=0) {\r
+               refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,\r
+                   idatal, centerStartPos, blockStartPos[q],\r
+                   period[lagBlock[q+1]]);\r
+           } else {\r
+               psseq=sseq+q*ENH_BLOCKL;\r
+               memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
+           }\r
+       }\r
+       \r
+       /* future */\r
+   \r
+       for (i=0; i<periodl; i++) {\r
+           plocs2[i]=plocs[i]-period[i];\r
+       }\r
+       for (q=hl+1; q<=2*hl; q++) { \r
+           NearestNeighbor(lagBlock+q,plocs2,\r
+               blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);\r
+   \r
+           blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];\r
+           if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {\r
+               refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,\r
+                   idatal, centerStartPos, blockStartPos[q],\r
+   \r
+   \r
+                   period[lagBlock[q]]);\r
+           }\r
+           else {\r
+               psseq=sseq+q*ENH_BLOCKL;\r
+               memset(psseq, 0, ENH_BLOCKL*sizeof(float));\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * perform enhancement on idata+centerStartPos through \r
+    * idata+centerStartPos+ENH_BLOCKL-1\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void enhancer(\r
+       float *odata,       /* (o) smoothed block, dimension blockl */\r
+       float *idata,       /* (i) data buffer used for enhancing */\r
+       int idatal,         /* (i) dimension idata */\r
+       int centerStartPos, /* (i) first sample current block \r
+                                  within idata */\r
+       float alpha0,       /* (i) max correction-energy-fraction \r
+                                 (in [0,1]) */\r
+       float *period,      /* (i) pitch period array */\r
+       float *plocs,       /* (i) locations where period array \r
+                                  values valid */\r
+       int periodl         /* (i) dimension of period and plocs */\r
+   ){\r
+       float sseq[(2*ENH_HL+1)*ENH_BLOCKL];\r
+   \r
+       /* get said second sequence of segments */\r
+   \r
+       getsseq(sseq,idata,idatal,centerStartPos,period,\r
+           plocs,periodl,ENH_HL);\r
+   \r
+       /* compute the smoothed output from said second sequence */\r
+   \r
+       smath(odata,sseq,ENH_HL,alpha0);\r
+   \r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * cross correlation\r
+    *---------------------------------------------------------------*/\r
+   \r
+   float xCorrCoef( \r
+       float *target,      /* (i) first array */\r
+       float *regressor,   /* (i) second array */\r
+       int subl        /* (i) dimension arrays */\r
+   ){\r
+       int i;\r
+       float ftmp1, ftmp2;\r
+           \r
+       ftmp1 = 0.0;\r
+       ftmp2 = 0.0;\r
+   \r
+   \r
+       for (i=0; i<subl; i++) {\r
+           ftmp1 += target[i]*regressor[i];\r
+           ftmp2 += regressor[i]*regressor[i]; \r
+       }\r
+       \r
+       if (ftmp1 > 0.0) {\r
+           return (float)(ftmp1*ftmp1/ftmp2);\r
+       }\r
+       else {\r
+           return (float)0.0;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * interface for enhancer\r
+    *---------------------------------------------------------------*/\r
+   \r
+   int enhancerInterface(\r
+       float *out,                     /* (o) enhanced signal */\r
+       float *in,                      /* (i) unenhanced signal */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst   /* (i) buffers etc */\r
+   ){\r
+       float *enh_buf, *enh_period;\r
+       int iblock, isample;\r
+       int lag=0, ilag, i, ioffset;\r
+       float cc, maxcc;\r
+       float ftmp1, ftmp2;\r
+       float *inPtr, *enh_bufPtr1, *enh_bufPtr2;\r
+       float plc_pred[ENH_BLOCKL];\r
+   \r
+       float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];\r
+       int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;\r
+       int start, plc_blockl, inlag;\r
+   \r
+       enh_buf=iLBCdec_inst->enh_buf;\r
+       enh_period=iLBCdec_inst->enh_period;\r
+       \r
+       memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], \r
+           (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));\r
+                                                               \r
+       memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, \r
+           iLBCdec_inst->blockl*sizeof(float));\r
+   \r
+       if (iLBCdec_inst->mode==30)\r
+           plc_blockl=ENH_BLOCKL;\r
+       else\r
+           plc_blockl=40;\r
+   \r
+       /* when 20 ms frame, move processing one block */\r
+       ioffset=0;\r
+       if (iLBCdec_inst->mode==20) ioffset=1;\r
+   \r
+       i=3-ioffset;\r
+       memmove(enh_period, &enh_period[i], \r
+   \r
+   \r
+           (ENH_NBLOCKS_TOT-i)*sizeof(float));\r
+   \r
+       /* Set state information to the 6 samples right before \r
+          the samples to be downsampled. */\r
+   \r
+       memcpy(lpState, \r
+           enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126, \r
+           6*sizeof(float));\r
+   \r
+       /* Down sample a factor 2 to save computations */\r
+   \r
+       DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,\r
+                   lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,\r
+                   lpState, downsampled);\r
+   \r
+       /* Estimate the pitch in the down sampled domain. */\r
+       for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {\r
+           \r
+           lag = 10;\r
+           maxcc = xCorrCoef(downsampled+60+iblock*\r
+               ENH_BLOCKL_HALF, downsampled+60+iblock*\r
+               ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);\r
+           for (ilag=11; ilag<60; ilag++) {\r
+               cc = xCorrCoef(downsampled+60+iblock*\r
+                   ENH_BLOCKL_HALF, downsampled+60+iblock*\r
+                   ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);\r
+               \r
+               if (cc > maxcc) {\r
+                   maxcc = cc;\r
+                   lag = ilag;\r
+               }\r
+           }\r
+   \r
+           /* Store the estimated lag in the non-downsampled domain */\r
+           enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;\r
+\r
+\r
+       }   \r
+   \r
+   \r
+       /* PLC was performed on the previous packet */\r
+       if (iLBCdec_inst->prev_enh_pl==1) {\r
+   \r
+           inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];\r
+   \r
+           lag = inlag-1;\r
+           maxcc = xCorrCoef(in, in+lag, plc_blockl);\r
+           for (ilag=inlag; ilag<=inlag+1; ilag++) {\r
+               cc = xCorrCoef(in, in+ilag, plc_blockl);\r
+               \r
+               if (cc > maxcc) {\r
+                   maxcc = cc;\r
+                   lag = ilag;\r
+               }\r
+           }\r
+   \r
+   \r
+   \r
+           enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;\r
+   \r
+           /* compute new concealed residual for the old lookahead,\r
+              mix the forward PLC with a backward PLC from \r
+              the new frame */\r
+           \r
+           inPtr=&in[lag-1];\r
+           \r
+           enh_bufPtr1=&plc_pred[plc_blockl-1];\r
+           \r
+           if (lag>plc_blockl) {\r
+               start=plc_blockl;\r
+           } else {\r
+               start=lag;\r
+           }\r
+   \r
+           for (isample = start; isample>0; isample--) {\r
+               *enh_bufPtr1-- = *inPtr--;\r
+           }\r
+           \r
+           enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
+           for (isample = (plc_blockl-1-lag); isample>=0; isample--) \r
 {\r
-            *enh_bufPtr1-- = *enh_bufPtr2--;\r
-        }\r
-\r
-        /* limit energy change */\r
-        ftmp2=0.0;\r
-        ftmp1=0.0;\r
-        for (i=0;i<plc_blockl;i++) {\r
-            ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*\r
-                enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];\r
-            ftmp1+=plc_pred[i]*plc_pred[i];\r
-        }\r
-        ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);\r
-        ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);\r
-        if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {\r
-            for (i=0;i<plc_blockl-10;i++) {\r
-                plc_pred[i]*=(float)2.0*ftmp2/ftmp1;\r
-            }\r
-            for (i=plc_blockl-10;i<plc_blockl;i++) {\r
-                plc_pred[i]*=(float)(i-plc_blockl+10)*\r
-                    ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+\r
-                    (float)2.0*ftmp2/ftmp1;\r
-            }\r
-        }\r
-    \r
-        enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
-        for (i=0; i<plc_blockl; i++) {\r
-            ftmp1 = (float) (i+1) / (float) (plc_blockl+1);\r
-            *enh_bufPtr1 *= ftmp1;\r
-            *enh_bufPtr1 += ((float)1.0-ftmp1)*\r
-                                plc_pred[plc_blockl-1-i];\r
-            enh_bufPtr1--;\r
-        }\r
-\r
-\r
-    }\r
-\r
-    if (iLBCdec_inst->mode==20) {\r
-        /* Enhancer with 40 samples delay */\r
-        for (iblock = 0; iblock<2; iblock++) {\r
-            enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
-                ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,\r
-                ENH_ALPHA0, enh_period, enh_plocsTbl, \r
-                    ENH_NBLOCKS_TOT);\r
-        }\r
-    } else if (iLBCdec_inst->mode==30) {\r
-        /* Enhancer with 80 samples delay */\r
-        for (iblock = 0; iblock<3; iblock++) {\r
-            enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
-                ENH_BUFL, (4+iblock)*ENH_BLOCKL,\r
-                ENH_ALPHA0, enh_period, enh_plocsTbl, \r
-                    ENH_NBLOCKS_TOT);\r
-        }\r
-    }\r
-\r
-    return (lag*2);\r
-}\r
-\r
-\r
+               *enh_bufPtr1-- = *enh_bufPtr2--;\r
+           }\r
+   \r
+           /* limit energy change */\r
+           ftmp2=0.0;\r
+           ftmp1=0.0;\r
+           for (i=0;i<plc_blockl;i++) {\r
+               ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*\r
+                   enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];\r
+               ftmp1+=plc_pred[i]*plc_pred[i];\r
+           }\r
+           ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);\r
+           ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);\r
+           if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {\r
+               for (i=0;i<plc_blockl-10;i++) {\r
+                   plc_pred[i]*=(float)2.0*ftmp2/ftmp1;\r
+               }\r
+               for (i=plc_blockl-10;i<plc_blockl;i++) {\r
+                   plc_pred[i]*=(float)(i-plc_blockl+10)*\r
+                       ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+\r
+                       (float)2.0*ftmp2/ftmp1;\r
+               }\r
+           }\r
+       \r
+           enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];\r
+           for (i=0; i<plc_blockl; i++) {\r
+               ftmp1 = (float) (i+1) / (float) (plc_blockl+1);\r
+               *enh_bufPtr1 *= ftmp1;\r
+               *enh_bufPtr1 += ((float)1.0-ftmp1)*\r
+                                   plc_pred[plc_blockl-1-i];\r
+               enh_bufPtr1--;\r
+           }\r
+   \r
+   \r
+       }\r
+   \r
+       if (iLBCdec_inst->mode==20) {\r
+           /* Enhancer with 40 samples delay */\r
+           for (iblock = 0; iblock<2; iblock++) {\r
+               enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
+                   ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,\r
+                   ENH_ALPHA0, enh_period, enh_plocsTbl, \r
+                       ENH_NBLOCKS_TOT);\r
+           }\r
+       } else if (iLBCdec_inst->mode==30) {\r
+           /* Enhancer with 80 samples delay */\r
+           for (iblock = 0; iblock<3; iblock++) {\r
+               enhancer(out+iblock*ENH_BLOCKL, enh_buf, \r
+                   ENH_BUFL, (4+iblock)*ENH_BLOCKL,\r
+                   ENH_ALPHA0, enh_period, enh_plocsTbl, \r
+                       ENH_NBLOCKS_TOT);\r
+           }\r
+       }\r
+   \r
+       return (lag*2);\r
+   }\r
+   \r
+   \r
index dab29ec53de6a1d7b9933036312508a6d21fb2e7..1a5d27d86f192a25f7bcfb91b967d9c7c02d86bb 100644 (file)
@@ -1,33 +1,33 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    enhancer.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __ENHANCER_H\r
-#define __ENHANCER_H\r
-\r
-#include "iLBC_define.h"\r
-\r
-float xCorrCoef( \r
-    float *target,      /* (i) first array */\r
-    float *regressor,   /* (i) second array */\r
-    int subl        /* (i) dimension arrays */\r
-);\r
-\r
-int enhancerInterface(\r
-    float *out,         /* (o) the enhanced recidual signal */\r
-    float *in,          /* (i) the recidual signal to enhance */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst \r
-                        /* (i/o) the decoder state structure */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       enhancer.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __ENHANCER_H\r
+   #define __ENHANCER_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   float xCorrCoef( \r
+       float *target,      /* (i) first array */\r
+       float *regressor,   /* (i) second array */\r
+       int subl        /* (i) dimension arrays */\r
+   );\r
+   \r
+   int enhancerInterface(\r
+       float *out,         /* (o) the enhanced recidual signal */\r
+       float *in,          /* (i) the recidual signal to enhance */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst \r
+                           /* (i/o) the decoder state structure */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
diff --git a/libs/codec/ilbc/extract-cfile.awk b/libs/codec/ilbc/extract-cfile.awk
new file mode 100644 (file)
index 0000000..abe19ba
--- /dev/null
@@ -0,0 +1,17 @@
+BEGIN { srcname = "nothing"; }\r
+{ if (/^A\.[0-9][0-9]* [a-zA-Z][a-zA-Z_0-9]*\.[ch]/) {\r
+    if (srcname != "nothing")\r
+      close(srcname);\r
+    srcname = $2;\r
+    printf("creating source file %s\n", srcname);\r
+  }else if (srcname != "nothing") {\r
+    if (/Andersen et\. al\./ || /Internet Low Bit Rate Codec *May 04/)\r
+      printf("skipping %s\n", $0);\r
+    else\r
+      print $0 >> srcname;\r
+  }\r
+}\r
+END {\r
+  printf("ending file %s\n", srcname);\r
+  close(srcname);\r
+}\r
index 1215e313ac05acfe89cd2e79b5d9f8a247329b65..e79483c18be11c8a6fbf5bec5bcfe98f7af24dd2 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    filter.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-\r
-\r
-#include "iLBC_define.h"\r
-#include "filter.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  all-pole filter\r
- *---------------------------------------------------------------*/\r
-\r
-void AllPoleFilter(\r
-    float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
-                           InOut[-1] contain the state of the \r
-                           filter (delayed samples). InOut[0] to \r
-                           InOut[lengthInOut-1] contain the filter\r
-                           input, on en exit InOut[-orderCoef] to\r
-                           InOut[-1] is unchanged and InOut[0] to\r
-                           InOut[lengthInOut-1] contain filtered \r
-                           samples */\r
-    float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
-                           to be 1.0 */\r
-    int lengthInOut,/* (i) number of input/output samples */\r
-    int orderCoef   /* (i) number of filter coefficients */\r
-){  \r
-    int n,k;\r
-    \r
-    for(n=0;n<lengthInOut;n++){\r
-        for(k=1;k<=orderCoef;k++){\r
-            *InOut -= Coef[k]*InOut[-k];\r
-        }\r
-        InOut++;\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  all-zero filter                         \r
- *---------------------------------------------------------------*/\r
-\r
-void AllZeroFilter(\r
-    float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
-                           filter input samples */\r
-    float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
-                           to be 1.0) */\r
-    int lengthInOut,/* (i) number of input/output samples */\r
-    int orderCoef,  /* (i) number of filter coefficients */\r
-    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
-                           contain the filter state, on exit Out[0]\r
-                           to Out[lengthInOut-1] contain filtered\r
-                           samples */\r
-){  \r
-    int n,k;\r
-    \r
-    for(n=0;n<lengthInOut;n++){\r
-        *Out = Coef[0]*In[0];\r
-        for(k=1;k<=orderCoef;k++){\r
-            *Out += Coef[k]*In[-k];\r
-        }\r
-\r
-\r
-        Out++;\r
-        In++;\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  pole-zero filter\r
- *---------------------------------------------------------------*/\r
-\r
-void ZeroPoleFilter(\r
-    float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
-                           filter input samples In[-orderCoef] to \r
-                           In[-1] contain state of all-zero \r
-                           section */\r
-    float *ZeroCoef,/* (i) filter coefficients for all-zero \r
-                           section (ZeroCoef[0] is assumed to \r
-                           be 1.0) */\r
-    float *PoleCoef,/* (i) filter coefficients for all-pole section\r
-                           (ZeroCoef[0] is assumed to be 1.0) */\r
-    int lengthInOut,/* (i) number of input/output samples */\r
-    int orderCoef,  /* (i) number of filter coefficients */\r
-    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
-                           contain state of all-pole section. On \r
-                           exit Out[0] to Out[lengthInOut-1] \r
-                           contain filtered samples */\r
-){\r
-    AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);\r
-    AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- * downsample (LP filter and decimation)\r
- *---------------------------------------------------------------*/\r
-\r
-void DownSample (\r
-    float  *In,     /* (i) input samples */\r
-    float  *Coef,   /* (i) filter coefficients */\r
-    int lengthIn,   /* (i) number of input samples */ \r
-    float  *state,  /* (i) filter state */\r
-    float  *Out     /* (o) downsampled output */\r
-){\r
-    float   o;\r
-    float *Out_ptr = Out;\r
-    float *Coef_ptr, *In_ptr;\r
-    float *state_ptr;\r
-    int i, j, stop;\r
-\r
-    /* LP filter and decimate at the same time */\r
-\r
-    for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)\r
-    {\r
-        Coef_ptr = &Coef[0];\r
-        In_ptr = &In[i];\r
-        state_ptr = &state[FILTERORDER_DS-2];\r
-\r
-\r
-\r
-        o = (float)0.0;\r
-        \r
-        stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;\r
-\r
-        for (j = 0; j < stop; j++) \r
-        {\r
-            o += *Coef_ptr++ * (*In_ptr--);\r
-        }\r
-        for (j = i + 1; j < FILTERORDER_DS; j++) \r
-        {\r
-            o += *Coef_ptr++ * (*state_ptr--);\r
-        }\r
-\r
-        *Out_ptr++ = o;\r
-    }\r
-\r
-    /* Get the last part (use zeros as input for the future) */\r
-\r
-    for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS); \r
-            i+=FACTOR_DS) {\r
-\r
-        o=(float)0.0;\r
-        \r
-        if (i<lengthIn) {\r
-            Coef_ptr = &Coef[0];\r
-            In_ptr = &In[i];\r
-            for (j=0; j<FILTERORDER_DS; j++) {\r
-                    o += *Coef_ptr++ * (*Out_ptr--);\r
-            }\r
-        } else {\r
-            Coef_ptr = &Coef[i-lengthIn];\r
-            In_ptr = &In[lengthIn-1];\r
-            for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {\r
-                    o += *Coef_ptr++ * (*In_ptr--);\r
-            }\r
-        }\r
-        *Out_ptr++ = o;\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       filter.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   \r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  all-pole filter\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void AllPoleFilter(\r
+       float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
+                              InOut[-1] contain the state of the \r
+                              filter (delayed samples). InOut[0] to \r
+                              InOut[lengthInOut-1] contain the filter\r
+                              input, on en exit InOut[-orderCoef] to\r
+                              InOut[-1] is unchanged and InOut[0] to\r
+                              InOut[lengthInOut-1] contain filtered \r
+                              samples */\r
+       float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
+                              to be 1.0 */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef   /* (i) number of filter coefficients */\r
+   ){  \r
+       int n,k;\r
+       \r
+       for(n=0;n<lengthInOut;n++){\r
+           for(k=1;k<=orderCoef;k++){\r
+               *InOut -= Coef[k]*InOut[-k];\r
+           }\r
+           InOut++;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  all-zero filter                         \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void AllZeroFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                              filter input samples */\r
+       float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
+                              to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain the filter state, on exit Out[0]\r
+                              to Out[lengthInOut-1] contain filtered\r
+                              samples */\r
+   ){  \r
+       int n,k;\r
+       \r
+       for(n=0;n<lengthInOut;n++){\r
+           *Out = Coef[0]*In[0];\r
+           for(k=1;k<=orderCoef;k++){\r
+               *Out += Coef[k]*In[-k];\r
+           }\r
+   \r
+   \r
+           Out++;\r
+           In++;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  pole-zero filter\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void ZeroPoleFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                              filter input samples In[-orderCoef] to \r
+                              In[-1] contain state of all-zero \r
+                              section */\r
+       float *ZeroCoef,/* (i) filter coefficients for all-zero \r
+                              section (ZeroCoef[0] is assumed to \r
+                              be 1.0) */\r
+       float *PoleCoef,/* (i) filter coefficients for all-pole section\r
+                              (ZeroCoef[0] is assumed to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain state of all-pole section. On \r
+                              exit Out[0] to Out[lengthInOut-1] \r
+                              contain filtered samples */\r
+   ){\r
+       AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);\r
+       AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    * downsample (LP filter and decimation)\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void DownSample (\r
+       float  *In,     /* (i) input samples */\r
+       float  *Coef,   /* (i) filter coefficients */\r
+       int lengthIn,   /* (i) number of input samples */ \r
+       float  *state,  /* (i) filter state */\r
+       float  *Out     /* (o) downsampled output */\r
+   ){\r
+       float   o;\r
+       float *Out_ptr = Out;\r
+       float *Coef_ptr, *In_ptr;\r
+       float *state_ptr;\r
+       int i, j, stop;\r
+   \r
+       /* LP filter and decimate at the same time */\r
+   \r
+       for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)\r
+       {\r
+           Coef_ptr = &Coef[0];\r
+           In_ptr = &In[i];\r
+           state_ptr = &state[FILTERORDER_DS-2];\r
+   \r
+   \r
+   \r
+           o = (float)0.0;\r
+           \r
+           stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;\r
+   \r
+           for (j = 0; j < stop; j++) \r
+           {\r
+               o += *Coef_ptr++ * (*In_ptr--);\r
+           }\r
+           for (j = i + 1; j < FILTERORDER_DS; j++) \r
+           {\r
+               o += *Coef_ptr++ * (*state_ptr--);\r
+           }\r
+   \r
+           *Out_ptr++ = o;\r
+       }\r
+   \r
+       /* Get the last part (use zeros as input for the future) */\r
+   \r
+       for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS); \r
+               i+=FACTOR_DS) {\r
+   \r
+           o=(float)0.0;\r
+           \r
+           if (i<lengthIn) {\r
+               Coef_ptr = &Coef[0];\r
+               In_ptr = &In[i];\r
+               for (j=0; j<FILTERORDER_DS; j++) {\r
+                       o += *Coef_ptr++ * (*Out_ptr--);\r
+               }\r
+           } else {\r
+               Coef_ptr = &Coef[i-lengthIn];\r
+               In_ptr = &In[lengthIn-1];\r
+               for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {\r
+                       o += *Coef_ptr++ * (*In_ptr--);\r
+               }\r
+           }\r
+           *Out_ptr++ = o;\r
+       }\r
+   }\r
+   \r
+   \r
index bdfdff2254cc3edbd6a8b7e363591ee806bd717b..bf9711edb7ea4ee3705db3996986f9902e81fb4b 100644 (file)
@@ -1,73 +1,73 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    filter.h\r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_FILTER_H\r
-#define __iLBC_FILTER_H\r
-\r
-void AllPoleFilter(\r
-    float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
-                           InOut[-1] contain the state of the \r
-                           filter (delayed samples). InOut[0] to \r
-                           InOut[lengthInOut-1] contain the filter \r
-                           input, on en exit InOut[-orderCoef] to \r
-                           InOut[-1] is unchanged and InOut[0] to \r
-                           InOut[lengthInOut-1] contain filtered \r
-                           samples */\r
-    float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
-                           to be 1.0 */\r
-    int lengthInOut,/* (i) number of input/output samples */\r
-    int orderCoef   /* (i) number of filter coefficients */\r
-);\r
-\r
-\r
-\r
-void AllZeroFilter(\r
-    float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
-                           filter input samples */\r
-    float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
-                           to be 1.0) */\r
-    int lengthInOut,/* (i) number of input/output samples */\r
-    int orderCoef,  /* (i) number of filter coefficients */\r
-    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
-                           contain the filter state, on exit Out[0] \r
-                           to Out[lengthInOut-1] contain filtered \r
-                           samples */\r
-);\r
-\r
-void ZeroPoleFilter(\r
-    float *In,      /* (i) In[0] to In[lengthInOut-1] contain filter\r
-                           input samples In[-orderCoef] to In[-1] \r
-                           contain state of all-zero section */\r
-    float *ZeroCoef,/* (i) filter coefficients for all-zero \r
-                           section (ZeroCoef[0] is assumed to \r
-                           be 1.0) */\r
-    float *PoleCoef,/* (i) filter coefficients for all-pole section\r
-                           (ZeroCoef[0] is assumed to be 1.0) */\r
-    int lengthInOut,/* (i) number of input/output samples */\r
-    int orderCoef,  /* (i) number of filter coefficients */\r
-    float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
-                           contain state of all-pole section. On\r
-                           exit Out[0] to Out[lengthInOut-1] \r
-                           contain filtered samples */\r
-);\r
-\r
-void DownSample (\r
-    float  *In,     /* (i) input samples */\r
-    float  *Coef,   /* (i) filter coefficients */\r
-    int lengthIn,   /* (i) number of input samples */ \r
-    float  *state,  /* (i) filter state */\r
-    float  *Out     /* (o) downsampled output */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       filter.h\r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_FILTER_H\r
+   #define __iLBC_FILTER_H\r
+   \r
+   void AllPoleFilter(\r
+       float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to \r
+                              InOut[-1] contain the state of the \r
+                              filter (delayed samples). InOut[0] to \r
+                              InOut[lengthInOut-1] contain the filter \r
+                              input, on en exit InOut[-orderCoef] to \r
+                              InOut[-1] is unchanged and InOut[0] to \r
+                              InOut[lengthInOut-1] contain filtered \r
+                              samples */\r
+       float *Coef,/* (i) filter coefficients, Coef[0] is assumed \r
+                              to be 1.0 */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef   /* (i) number of filter coefficients */\r
+   );\r
+   \r
+   \r
+   \r
+   void AllZeroFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain \r
+                              filter input samples */\r
+       float *Coef,/* (i) filter coefficients (Coef[0] is assumed \r
+                              to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain the filter state, on exit Out[0] \r
+                              to Out[lengthInOut-1] contain filtered \r
+                              samples */\r
+   );\r
+   \r
+   void ZeroPoleFilter(\r
+       float *In,      /* (i) In[0] to In[lengthInOut-1] contain filter\r
+                              input samples In[-orderCoef] to In[-1] \r
+                              contain state of all-zero section */\r
+       float *ZeroCoef,/* (i) filter coefficients for all-zero \r
+                              section (ZeroCoef[0] is assumed to \r
+                              be 1.0) */\r
+       float *PoleCoef,/* (i) filter coefficients for all-pole section\r
+                              (ZeroCoef[0] is assumed to be 1.0) */\r
+       int lengthInOut,/* (i) number of input/output samples */\r
+       int orderCoef,  /* (i) number of filter coefficients */\r
+       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]\r
+                              contain state of all-pole section. On\r
+                              exit Out[0] to Out[lengthInOut-1] \r
+                              contain filtered samples */\r
+   );\r
+   \r
+   void DownSample (\r
+       float  *In,     /* (i) input samples */\r
+       float  *Coef,   /* (i) filter coefficients */\r
+       int lengthIn,   /* (i) number of input samples */ \r
+       float  *state,  /* (i) filter state */\r
+       float  *Out     /* (o) downsampled output */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 9115a80a9bad696e52ca20dab7d50080d7830701..bd43f7a88b73054a1fedf3ae2b39650d9f6bc1ef 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    gainquant.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-\r
-\r
-******************************************************************/\r
-\r
-#include <string.h>\r
-#include <math.h>\r
-#include "constants.h"\r
-#include "gainquant.h"\r
-#include "filter.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  quantizer for the gain in the gain-shape coding of residual\r
- *---------------------------------------------------------------*/\r
-\r
-float gainquant(/* (o) quantized gain value */\r
-    float in,       /* (i) gain value */\r
-    float maxIn,/* (i) maximum of gain value */\r
-    int cblen,      /* (i) number of quantization indices */\r
-    int *index      /* (o) quantization index */\r
-){\r
-    int i, tindex;\r
-    float minmeasure,measure, *cb, scale;\r
-\r
-    /* ensure a lower bound on the scaling factor */\r
-\r
-    scale=maxIn;\r
-    \r
-    if (scale<0.1) {\r
-        scale=(float)0.1;\r
-    }\r
-\r
-    /* select the quantization table */\r
-    \r
-    if (cblen == 8) {\r
-        cb = gain_sq3Tbl;\r
-    } else if (cblen == 16) {\r
-        cb = gain_sq4Tbl;\r
-    } else  {\r
-        cb = gain_sq5Tbl;\r
-    }\r
-\r
-    /* select the best index in the quantization table */\r
-    \r
-    minmeasure=10000000.0;\r
-    tindex=0;\r
-    for (i=0; i<cblen; i++) {\r
-        measure=(in-scale*cb[i])*(in-scale*cb[i]);\r
-        \r
-        if (measure<minmeasure) {\r
-            tindex=i;\r
-            minmeasure=measure;\r
-        }\r
-    }\r
-    *index=tindex;\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       gainquant.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   #include <math.h>\r
+   #include "constants.h"\r
+   #include "filter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  quantizer for the gain in the gain-shape coding of residual\r
+    *---------------------------------------------------------------*/\r
+   \r
+   float gainquant(/* (o) quantized gain value */\r
+       float in,       /* (i) gain value */\r
+       float maxIn,/* (i) maximum of gain value */\r
+       int cblen,      /* (i) number of quantization indices */\r
+       int *index      /* (o) quantization index */\r
+   ){\r
+       int i, tindex;\r
+       float minmeasure,measure, *cb, scale;\r
+   \r
+       /* ensure a lower bound on the scaling factor */\r
+   \r
+       scale=maxIn;\r
        \r
-    /* return the quantized value */\r
-    \r
-\r
-\r
-    return scale*cb[tindex];\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  decoder for quantized gains in the gain-shape coding of \r
- *  residual                          \r
- *---------------------------------------------------------------*/\r
-\r
-float gaindequant(  /* (o) quantized gain value */\r
-    int index,      /* (i) quantization index */\r
-    float maxIn,/* (i) maximum of unquantized gain */\r
-    int cblen       /* (i) number of quantization indices */\r
-){\r
-    float scale;\r
-\r
-    /* obtain correct scale factor */\r
-\r
-    scale=(float)fabs(maxIn);\r
-    \r
-    if (scale<0.1) {\r
-        scale=(float)0.1;\r
-    }\r
-\r
-    /* select the quantization table and return the decoded value */\r
-\r
-    if (cblen==8) {\r
-        return scale*gain_sq3Tbl[index];\r
-    } else if (cblen==16) {\r
-        return scale*gain_sq4Tbl[index];\r
-    }\r
-    else if (cblen==32) {\r
-        return scale*gain_sq5Tbl[index];\r
-    }\r
-\r
-    return 0.0;\r
-}\r
-\r
-\r
+       if (scale<0.1) {\r
+           scale=(float)0.1;\r
+       }\r
+   \r
+       /* select the quantization table */\r
+       \r
+       if (cblen == 8) {\r
+           cb = gain_sq3Tbl;\r
+       } else if (cblen == 16) {\r
+           cb = gain_sq4Tbl;\r
+       } else  {\r
+           cb = gain_sq5Tbl;\r
+       }\r
+   \r
+       /* select the best index in the quantization table */\r
+       \r
+       minmeasure=10000000.0;\r
+       tindex=0;\r
+       for (i=0; i<cblen; i++) {\r
+           measure=(in-scale*cb[i])*(in-scale*cb[i]);\r
+           \r
+           if (measure<minmeasure) {\r
+               tindex=i;\r
+               minmeasure=measure;\r
+           }\r
+       }\r
+       *index=tindex;\r
+          \r
+       /* return the quantized value */\r
+       \r
+   \r
+   \r
+       return scale*cb[tindex];\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  decoder for quantized gains in the gain-shape coding of \r
+    *  residual                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   float gaindequant(  /* (o) quantized gain value */\r
+       int index,      /* (i) quantization index */\r
+       float maxIn,/* (i) maximum of unquantized gain */\r
+       int cblen       /* (i) number of quantization indices */\r
+   ){\r
+       float scale;\r
+   \r
+       /* obtain correct scale factor */\r
+   \r
+       scale=(float)fabs(maxIn);\r
+       \r
+       if (scale<0.1) {\r
+           scale=(float)0.1;\r
+       }\r
+   \r
+       /* select the quantization table and return the decoded value */\r
+   \r
+       if (cblen==8) {\r
+           return scale*gain_sq3Tbl[index];\r
+       } else if (cblen==16) {\r
+           return scale*gain_sq4Tbl[index];\r
+       }\r
+       else if (cblen==32) {\r
+           return scale*gain_sq5Tbl[index];\r
+       }\r
+   \r
+       return 0.0;\r
+   }\r
+   \r
+   \r
index be81799250e44e47016098def899e146d60a25ae..b25f842ffe1a86ddec663a7de5f02716a8d93005 100644 (file)
@@ -1,31 +1,31 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    gainquant.h                                         \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_GAINQUANT_H\r
-#define __iLBC_GAINQUANT_H\r
-\r
-float gainquant(/* (o) quantized gain value */\r
-    float in,       /* (i) gain value */\r
-    float maxIn,/* (i) maximum of gain value */\r
-    int cblen,      /* (i) number of quantization indices */\r
-    int *index      /* (o) quantization index */\r
-);\r
-\r
-float gaindequant(  /* (o) quantized gain value */\r
-    int index,      /* (i) quantization index */\r
-    float maxIn,/* (i) maximum of unquantized gain */\r
-    int cblen       /* (i) number of quantization indices */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       gainquant.h                                         \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_GAINQUANT_H\r
+   #define __iLBC_GAINQUANT_H\r
+   \r
+   float gainquant(/* (o) quantized gain value */\r
+       float in,       /* (i) gain value */\r
+       float maxIn,/* (i) maximum of gain value */\r
+       int cblen,      /* (i) number of quantization indices */\r
+       int *index      /* (o) quantization index */\r
+   );\r
+   \r
+   float gaindequant(  /* (o) quantized gain value */\r
+       int index,      /* (i) quantization index */\r
+       float maxIn,/* (i) maximum of unquantized gain */\r
+       int cblen       /* (i) number of quantization indices */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 311568cc0d3b7816dc4feb5c89756ab893ebf375..e95b7aeaa8a08a523857b1c5b6acf83f9d0662f1 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    getCBvec.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include "iLBC_define.h"\r
-#include "getCBvec.h"\r
-#include "constants.h"\r
-#include <string.h>\r
-\r
-/*----------------------------------------------------------------*\r
- *  Construct codebook vector for given index.\r
- *---------------------------------------------------------------*/\r
-\r
-void getCBvec(\r
-    float *cbvec,   /* (o) Constructed codebook vector */\r
-    float *mem,     /* (i) Codebook buffer */\r
-    int index,      /* (i) Codebook index */\r
-    int lMem,       /* (i) Length of codebook buffer */\r
-    int cbveclen/* (i) Codebook vector length */\r
-){\r
-    int j, k, n, memInd, sFilt;\r
-    float tmpbuf[CB_MEML];\r
-    int base_size;\r
-    int ilow, ihigh;\r
-    float alfa, alfa1;\r
-\r
-    /* Determine size of codebook sections */\r
-\r
-    base_size=lMem-cbveclen+1;\r
-    \r
-    if (cbveclen==SUBL) {\r
-        base_size+=cbveclen/2;\r
-    }\r
-\r
-    /* No filter -> First codebook section */\r
-\r
-\r
-    \r
-    if (index<lMem-cbveclen+1) {\r
-\r
-        /* first non-interpolated vectors */\r
-\r
-        k=index+cbveclen;\r
-        /* get vector */\r
-        memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));\r
-\r
-    } else if (index < base_size) {\r
-\r
-        k=2*(index-(lMem-cbveclen+1))+cbveclen;\r
-    \r
-        ihigh=k/2;\r
-        ilow=ihigh-5;\r
-\r
-        /* Copy first noninterpolated part */\r
-\r
-        memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));\r
-\r
-        /* interpolation */\r
-\r
-        alfa1=(float)0.2;\r
-        alfa=0.0;\r
-        for (j=ilow; j<ihigh; j++) {\r
-            cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+\r
-                alfa*mem[lMem-k+j];\r
-            alfa+=alfa1;\r
-        }\r
-\r
-        /* Copy second noninterpolated part */\r
-\r
-        memcpy(cbvec+ihigh, mem+lMem-k+ihigh, \r
-            (cbveclen-ihigh)*sizeof(float));\r
-\r
-    }\r
-\r
-    /* Higher codebbok section based on filtering */\r
-\r
-    else {\r
-\r
-        /* first non-interpolated vectors */\r
-\r
-        if (index-base_size<lMem-cbveclen+1) {\r
-            float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
-            float *pos;\r
-            float *pp, *pp1;\r
-\r
-            memset(tempbuff2, 0,\r
-                CB_HALFFILTERLEN*sizeof(float));\r
-            memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
-                lMem*sizeof(float));\r
-            memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
-                (CB_HALFFILTERLEN+1)*sizeof(float));\r
-\r
-\r
-\r
-            k=index-base_size+cbveclen;\r
-            sFilt=lMem-k;\r
-            memInd=sFilt+1-CB_HALFFILTERLEN;\r
-\r
-            /* do filtering */\r
-            pos=cbvec;\r
-            memset(pos, 0, cbveclen*sizeof(float));\r
-            for (n=0; n<cbveclen; n++) {\r
-                pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];\r
-                pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
-                for (j=0; j<CB_FILTERLEN; j++) {\r
-                    (*pos)+=(*pp++)*(*pp1--);\r
-                }\r
-                pos++;\r
-            }\r
-        }\r
-\r
-        /* interpolated vectors */\r
-\r
-        else {\r
-            float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
-\r
-            float *pos;\r
-            float *pp, *pp1;\r
-            int i;\r
-\r
-            memset(tempbuff2, 0,\r
-                CB_HALFFILTERLEN*sizeof(float));\r
-            memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
-                lMem*sizeof(float));\r
-            memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
-                (CB_HALFFILTERLEN+1)*sizeof(float));\r
-\r
-            k=2*(index-base_size-\r
-                (lMem-cbveclen+1))+cbveclen;\r
-            sFilt=lMem-k;\r
-            memInd=sFilt+1-CB_HALFFILTERLEN;\r
-\r
-            /* do filtering */\r
-            pos=&tmpbuf[sFilt];\r
-            memset(pos, 0, k*sizeof(float));\r
-            for (i=0; i<k; i++) {\r
-                pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];\r
-                pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
-                for (j=0; j<CB_FILTERLEN; j++) {\r
-                    (*pos)+=(*pp++)*(*pp1--);\r
-                }\r
-                pos++;\r
-            }\r
-\r
-            ihigh=k/2;\r
-            ilow=ihigh-5;\r
-\r
-\r
-\r
-            /* Copy first noninterpolated part */\r
-\r
-            memcpy(cbvec, tmpbuf+lMem-k/2, \r
-                ilow*sizeof(float));\r
-\r
-            /* interpolation */\r
-\r
-            alfa1=(float)0.2;\r
-            alfa=0.0;\r
-            for (j=ilow; j<ihigh; j++) {\r
-                cbvec[j]=((float)1.0-alfa)*\r
-                    tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];\r
-                alfa+=alfa1;\r
-            }\r
-\r
-            /* Copy second noninterpolated part */\r
-\r
-            memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh, \r
-                (cbveclen-ihigh)*sizeof(float));\r
-        }\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       getCBvec.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include <string.h>\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Construct codebook vector for given index.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void getCBvec(\r
+       float *cbvec,   /* (o) Constructed codebook vector */\r
+       float *mem,     /* (i) Codebook buffer */\r
+       int index,      /* (i) Codebook index */\r
+       int lMem,       /* (i) Length of codebook buffer */\r
+       int cbveclen/* (i) Codebook vector length */\r
+   ){\r
+       int j, k, n, memInd, sFilt;\r
+       float tmpbuf[CB_MEML];\r
+       int base_size;\r
+       int ilow, ihigh;\r
+       float alfa, alfa1;\r
+   \r
+       /* Determine size of codebook sections */\r
+   \r
+       base_size=lMem-cbveclen+1;\r
+       \r
+       if (cbveclen==SUBL) {\r
+           base_size+=cbveclen/2;\r
+       }\r
+   \r
+       /* No filter -> First codebook section */\r
+   \r
+   \r
+       \r
+       if (index<lMem-cbveclen+1) {\r
+   \r
+           /* first non-interpolated vectors */\r
+   \r
+           k=index+cbveclen;\r
+           /* get vector */\r
+           memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));\r
+   \r
+       } else if (index < base_size) {\r
+   \r
+           k=2*(index-(lMem-cbveclen+1))+cbveclen;\r
+       \r
+           ihigh=k/2;\r
+           ilow=ihigh-5;\r
+   \r
+           /* Copy first noninterpolated part */\r
+   \r
+           memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));\r
+   \r
+           /* interpolation */\r
+   \r
+           alfa1=(float)0.2;\r
+           alfa=0.0;\r
+           for (j=ilow; j<ihigh; j++) {\r
+               cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+\r
+                   alfa*mem[lMem-k+j];\r
+               alfa+=alfa1;\r
+           }\r
+   \r
+           /* Copy second noninterpolated part */\r
+   \r
+           memcpy(cbvec+ihigh, mem+lMem-k+ihigh, \r
+               (cbveclen-ihigh)*sizeof(float));\r
+   \r
+       }\r
+   \r
+       /* Higher codebbok section based on filtering */\r
+   \r
+       else {\r
+   \r
+           /* first non-interpolated vectors */\r
+   \r
+           if (index-base_size<lMem-cbveclen+1) {\r
+               float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
+               float *pos;\r
+               float *pp, *pp1;\r
+   \r
+               memset(tempbuff2, 0,\r
+                   CB_HALFFILTERLEN*sizeof(float));\r
+               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
+                   lMem*sizeof(float));\r
+               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
+                   (CB_HALFFILTERLEN+1)*sizeof(float));\r
+   \r
+   \r
+   \r
+               k=index-base_size+cbveclen;\r
+               sFilt=lMem-k;\r
+               memInd=sFilt+1-CB_HALFFILTERLEN;\r
+   \r
+               /* do filtering */\r
+               pos=cbvec;\r
+               memset(pos, 0, cbveclen*sizeof(float));\r
+               for (n=0; n<cbveclen; n++) {\r
+                   pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];\r
+                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+                   for (j=0; j<CB_FILTERLEN; j++) {\r
+                       (*pos)+=(*pp++)*(*pp1--);\r
+                   }\r
+                   pos++;\r
+               }\r
+           }\r
+   \r
+           /* interpolated vectors */\r
+   \r
+           else {\r
+               float tempbuff2[CB_MEML+CB_FILTERLEN+1];\r
+   \r
+               float *pos;\r
+               float *pp, *pp1;\r
+               int i;\r
+   \r
+               memset(tempbuff2, 0,\r
+                   CB_HALFFILTERLEN*sizeof(float));\r
+               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,\r
+                   lMem*sizeof(float));\r
+               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,\r
+                   (CB_HALFFILTERLEN+1)*sizeof(float));\r
+   \r
+               k=2*(index-base_size-\r
+                   (lMem-cbveclen+1))+cbveclen;\r
+               sFilt=lMem-k;\r
+               memInd=sFilt+1-CB_HALFFILTERLEN;\r
+   \r
+               /* do filtering */\r
+               pos=&tmpbuf[sFilt];\r
+               memset(pos, 0, k*sizeof(float));\r
+               for (i=0; i<k; i++) {\r
+                   pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];\r
+                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];\r
+                   for (j=0; j<CB_FILTERLEN; j++) {\r
+                       (*pos)+=(*pp++)*(*pp1--);\r
+                   }\r
+                   pos++;\r
+               }\r
+   \r
+               ihigh=k/2;\r
+               ilow=ihigh-5;\r
+   \r
+   \r
+   \r
+               /* Copy first noninterpolated part */\r
+   \r
+               memcpy(cbvec, tmpbuf+lMem-k/2, \r
+                   ilow*sizeof(float));\r
+   \r
+               /* interpolation */\r
+   \r
+               alfa1=(float)0.2;\r
+               alfa=0.0;\r
+               for (j=ilow; j<ihigh; j++) {\r
+                   cbvec[j]=((float)1.0-alfa)*\r
+                       tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];\r
+                   alfa+=alfa1;\r
+               }\r
+   \r
+               /* Copy second noninterpolated part */\r
+   \r
+               memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh, \r
+                   (cbveclen-ihigh)*sizeof(float));\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
index d4e9311606c74ab671fc909baaeabd2b9cfb9e46..883b55d21fdfa23b19311c672be094283886fe79 100644 (file)
@@ -1,28 +1,28 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    getCBvec.h                 \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_GETCBVEC_H\r
-#define __iLBC_GETCBVEC_H\r
-\r
-\r
-\r
-void getCBvec(\r
-    float *cbvec,   /* (o) Constructed codebook vector */\r
-    float *mem,     /* (i) Codebook buffer */\r
-    int index,      /* (i) Codebook index */\r
-    int lMem,       /* (i) Length of codebook buffer */\r
-    int cbveclen/* (i) Codebook vector length */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       getCBvec.h                 \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_GETCBVEC_H\r
+   #define __iLBC_GETCBVEC_H\r
+   \r
+   \r
+   \r
+   void getCBvec(\r
+       float *cbvec,   /* (o) Constructed codebook vector */\r
+       float *mem,     /* (i) Codebook buffer */\r
+       int index,      /* (i) Codebook index */\r
+       int lMem,       /* (i) Length of codebook buffer */\r
+       int cbveclen/* (i) Codebook vector length */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 899291d403e1b87c0685f8f987d47b292aa3a2e5..88cb3d1d84f7dd17886e14fd8888b3bb9bbfb280 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    helpfun.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "helpfun.h"\r
-#include "constants.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  calculation of auto correlation \r
- *---------------------------------------------------------------*/\r
-\r
-void autocorr( \r
-    float *r,       /* (o) autocorrelation vector */\r
-    const float *x, /* (i) data vector */\r
-    int N,          /* (i) length of data vector */\r
-    int order       /* largest lag for calculated \r
-                       autocorrelations */\r
-){\r
-    int     lag, n;\r
-    float   sum;\r
-    \r
-    for (lag = 0; lag <= order; lag++) {\r
-        sum = 0;\r
-        for (n = 0; n < N - lag; n++) {\r
-            sum += x[n] * x[n+lag];\r
-        }\r
-        r[lag] = sum;\r
-    }\r
-}\r
-\r
-\r
-\r
-/*----------------------------------------------------------------*\r
- *  window multiplication  \r
- *---------------------------------------------------------------*/\r
-\r
-void window( \r
-    float *z,       /* (o) the windowed data */\r
-    const float *x, /* (i) the original data vector */\r
-    const float *y, /* (i) the window */\r
-    int N           /* (i) length of all vectors */\r
-){\r
-    int     i;\r
-    \r
-    for (i = 0; i < N; i++) {\r
-        z[i] = x[i] * y[i];\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  levinson-durbin solution for lpc coefficients\r
- *---------------------------------------------------------------*/\r
-\r
-void levdurb( \r
-    float *a,       /* (o) lpc coefficient vector starting \r
-                           with 1.0 */\r
-    float *k,       /* (o) reflection coefficients */\r
-    float *r,       /* (i) autocorrelation vector */\r
-    int order       /* (i) order of lpc filter */\r
-){\r
-    float  sum, alpha;\r
-    int     m, m_h, i;\r
-\r
-    a[0] = 1.0;\r
-    \r
-    if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */\r
-        for (i = 0; i < order; i++) {\r
-            k[i] = 0;\r
-            a[i+1] = 0;\r
-        }   \r
-    } else {\r
-        a[1] = k[0] = -r[1]/r[0];\r
-        alpha = r[0] + r[1] * k[0];\r
-        for (m = 1; m < order; m++){\r
-            sum = r[m + 1];\r
-            for (i = 0; i < m; i++){\r
-                sum += a[i+1] * r[m - i];\r
-            }\r
-            k[m] = -sum / alpha;\r
-            alpha += k[m] * sum;\r
-            m_h = (m + 1) >> 1;\r
-            for (i = 0; i < m_h; i++){\r
-                sum = a[i+1] + k[m] * a[m - i];\r
-                a[m - i] += k[m] * a[i+1];\r
-                a[i+1] = sum;\r
-\r
-\r
-            }\r
-            a[m+1] = k[m];\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  interpolation between vectors \r
- *---------------------------------------------------------------*/\r
-\r
-void interpolate( \r
-    float *out,      /* (o) the interpolated vector */\r
-    float *in1,     /* (i) the first vector for the \r
-                           interpolation */\r
-    float *in2,     /* (i) the second vector for the \r
-                           interpolation */\r
-    float coef,      /* (i) interpolation weights */\r
-    int length      /* (i) length of all vectors */\r
-){\r
-    int i;\r
-    float invcoef;\r
-\r
-    invcoef = (float)1.0 - coef;\r
-    for (i = 0; i < length; i++) {\r
-        out[i] = coef * in1[i] + invcoef * in2[i];\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  lpc bandwidth expansion                   \r
- *---------------------------------------------------------------*/\r
-\r
-void bwexpand( \r
-    float *out,      /* (o) the bandwidth expanded lpc \r
-                           coefficients */\r
-    float *in,      /* (i) the lpc coefficients before bandwidth \r
-                           expansion */\r
-    float coef,     /* (i) the bandwidth expansion factor */\r
-    int length      /* (i) the length of lpc coefficient vectors */\r
-){\r
-    int i;\r
-    float  chirp;\r
-    \r
-    chirp = coef;\r
-    \r
-    out[0] = in[0];\r
-    for (i = 1; i < length; i++) {\r
-        out[i] = chirp * in[i];\r
-        chirp *= coef;\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  vector quantization \r
-\r
-\r
- *---------------------------------------------------------------*/\r
-\r
-void vq( \r
-    float *Xq,      /* (o) the quantized vector */\r
-    int *index,     /* (o) the quantization index */\r
-    const float *CB,/* (i) the vector quantization codebook */\r
-    float *X,       /* (i) the vector to quantize */\r
-    int n_cb,       /* (i) the number of vectors in the codebook */\r
-    int dim         /* (i) the dimension of all vectors */\r
-){\r
-    int     i, j;\r
-    int     pos, minindex;\r
-    float   dist, tmp, mindist;\r
-\r
-    pos = 0;\r
-    mindist = FLOAT_MAX;\r
-    minindex = 0;\r
-    for (j = 0; j < n_cb; j++) {\r
-        dist = X[0] - CB[pos];\r
-        dist *= dist;\r
-        for (i = 1; i < dim; i++) {\r
-            tmp = X[i] - CB[pos + i];\r
-            dist += tmp*tmp;\r
-        }\r
-        \r
-        if (dist < mindist) {\r
-            mindist = dist;\r
-            minindex = j;\r
-        }\r
-        pos += dim;\r
-    }\r
-    for (i = 0; i < dim; i++) {\r
-        Xq[i] = CB[minindex*dim + i];\r
-    }\r
-    *index = minindex;\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  split vector quantization \r
- *---------------------------------------------------------------*/\r
-\r
-void SplitVQ( \r
-    float *qX,      /* (o) the quantized vector */\r
-    int *index,     /* (o) a vector of indexes for all vector\r
-                           codebooks in the split */\r
-    float *X,       /* (i) the vector to quantize */\r
-    const float *CB,/* (i) the quantizer codebook */\r
-    int nsplit,     /* the number of vector splits */\r
-    const int *dim, /* the dimension of X and qX */\r
-    const int *cbsize /* the number of vectors in the codebook */\r
-){\r
-    int    cb_pos, X_pos, i;\r
-    \r
-    cb_pos = 0;\r
-\r
-\r
-    X_pos= 0;\r
-    for (i = 0; i < nsplit; i++) {\r
-        vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, \r
-            cbsize[i], dim[i]);\r
-        X_pos += dim[i];\r
-        cb_pos += dim[i] * cbsize[i];\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  scalar quantization \r
- *---------------------------------------------------------------*/\r
-\r
-void sort_sq( \r
-    float *xq,      /* (o) the quantized value */\r
-    int *index,     /* (o) the quantization index */\r
-    float x,    /* (i) the value to quantize */\r
-    const float *cb,/* (i) the quantization codebook */\r
-    int cb_size      /* (i) the size of the quantization codebook */\r
-){\r
-    int i;\r
-    \r
-    if (x <= cb[0]) {\r
-        *index = 0;\r
-        *xq = cb[0];\r
-    } else {\r
-        i = 0;\r
-        while ((x > cb[i]) && i < cb_size - 1) {\r
-            i++;\r
-        }\r
-        \r
-        if (x > ((cb[i] + cb[i - 1])/2)) {\r
-            *index = i;\r
-            *xq = cb[i];\r
-        } else {\r
-            *index = i - 1;\r
-            *xq = cb[i - 1];\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  check for stability of lsf coefficients\r
- *---------------------------------------------------------------*/\r
-\r
-int LSF_check(    /* (o) 1 for stable lsf vectors and 0 for\r
-                           nonstable ones */\r
-    float *lsf,     /* (i) a table of lsf vectors */\r
-    int dim,    /* (i) the dimension of each lsf vector */\r
-    int NoAn    /* (i) the number of lsf vectors in the \r
-                           table */\r
-){\r
-    int k,n,m, Nit=2, change=0,pos;\r
-    float tmp;\r
-\r
-\r
-    static float eps=(float)0.039; /* 50 Hz */\r
-    static float eps2=(float)0.0195;\r
-    static float maxlsf=(float)3.14; /* 4000 Hz */\r
-    static float minlsf=(float)0.01; /* 0 Hz */\r
-    \r
-    /* LSF separation check*/\r
-\r
-    for (n=0; n<Nit; n++) { /* Run through a couple of times */\r
-        for (m=0; m<NoAn; m++) { /* Number of analyses per frame */\r
-            for (k=0; k<(dim-1); k++) {\r
-                pos=m*dim+k;\r
-                \r
-                if ((lsf[pos+1]-lsf[pos])<eps) {\r
-                    \r
-                    if (lsf[pos+1]<lsf[pos]) {\r
-                        tmp=lsf[pos+1];\r
-                        lsf[pos+1]= lsf[pos]+eps2;\r
-                        lsf[pos]= lsf[pos+1]-eps2;\r
-                    } else {\r
-                        lsf[pos]-=eps2;\r
-                        lsf[pos+1]+=eps2;\r
-                    }\r
-                    change=1;\r
-                }\r
-                \r
-                if (lsf[pos]<minlsf) { \r
-                    lsf[pos]=minlsf;\r
-                    change=1;\r
-                }\r
-                \r
-                if (lsf[pos]>maxlsf) { \r
-                    lsf[pos]=maxlsf;\r
-                    change=1;\r
-                }               \r
-            }\r
-        }\r
-    }\r
-    \r
-    return change;  \r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       helpfun.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  calculation of auto correlation \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void autocorr( \r
+       float *r,       /* (o) autocorrelation vector */\r
+       const float *x, /* (i) data vector */\r
+       int N,          /* (i) length of data vector */\r
+       int order       /* largest lag for calculated \r
+                          autocorrelations */\r
+   ){\r
+       int     lag, n;\r
+       float   sum;\r
+       \r
+       for (lag = 0; lag <= order; lag++) {\r
+           sum = 0;\r
+           for (n = 0; n < N - lag; n++) {\r
+               sum += x[n] * x[n+lag];\r
+           }\r
+           r[lag] = sum;\r
+       }\r
+   }\r
+   \r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  window multiplication  \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void window( \r
+       float *z,       /* (o) the windowed data */\r
+       const float *x, /* (i) the original data vector */\r
+       const float *y, /* (i) the window */\r
+       int N           /* (i) length of all vectors */\r
+   ){\r
+       int     i;\r
+       \r
+       for (i = 0; i < N; i++) {\r
+           z[i] = x[i] * y[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  levinson-durbin solution for lpc coefficients\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void levdurb( \r
+       float *a,       /* (o) lpc coefficient vector starting \r
+                              with 1.0 */\r
+       float *k,       /* (o) reflection coefficients */\r
+       float *r,       /* (i) autocorrelation vector */\r
+       int order       /* (i) order of lpc filter */\r
+   ){\r
+       float  sum, alpha;\r
+       int     m, m_h, i;\r
+   \r
+       a[0] = 1.0;\r
+       \r
+       if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */\r
+           for (i = 0; i < order; i++) {\r
+               k[i] = 0;\r
+               a[i+1] = 0;\r
+           }   \r
+       } else {\r
+           a[1] = k[0] = -r[1]/r[0];\r
+           alpha = r[0] + r[1] * k[0];\r
+           for (m = 1; m < order; m++){\r
+               sum = r[m + 1];\r
+               for (i = 0; i < m; i++){\r
+                   sum += a[i+1] * r[m - i];\r
+               }\r
+               k[m] = -sum / alpha;\r
+               alpha += k[m] * sum;\r
+               m_h = (m + 1) >> 1;\r
+               for (i = 0; i < m_h; i++){\r
+                   sum = a[i+1] + k[m] * a[m - i];\r
+                   a[m - i] += k[m] * a[i+1];\r
+                   a[i+1] = sum;\r
+   \r
+   \r
+               }\r
+               a[m+1] = k[m];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  interpolation between vectors \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void interpolate( \r
+       float *out,      /* (o) the interpolated vector */\r
+       float *in1,     /* (i) the first vector for the \r
+                              interpolation */\r
+       float *in2,     /* (i) the second vector for the \r
+                              interpolation */\r
+       float coef,      /* (i) interpolation weights */\r
+       int length      /* (i) length of all vectors */\r
+   ){\r
+       int i;\r
+       float invcoef;\r
+   \r
+       invcoef = (float)1.0 - coef;\r
+       for (i = 0; i < length; i++) {\r
+           out[i] = coef * in1[i] + invcoef * in2[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  lpc bandwidth expansion                   \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void bwexpand( \r
+       float *out,      /* (o) the bandwidth expanded lpc \r
+                              coefficients */\r
+       float *in,      /* (i) the lpc coefficients before bandwidth \r
+                              expansion */\r
+       float coef,     /* (i) the bandwidth expansion factor */\r
+       int length      /* (i) the length of lpc coefficient vectors */\r
+   ){\r
+       int i;\r
+       float  chirp;\r
+       \r
+       chirp = coef;\r
+       \r
+       out[0] = in[0];\r
+       for (i = 1; i < length; i++) {\r
+           out[i] = chirp * in[i];\r
+           chirp *= coef;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  vector quantization \r
+   \r
+   \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void vq( \r
+       float *Xq,      /* (o) the quantized vector */\r
+       int *index,     /* (o) the quantization index */\r
+       const float *CB,/* (i) the vector quantization codebook */\r
+       float *X,       /* (i) the vector to quantize */\r
+       int n_cb,       /* (i) the number of vectors in the codebook */\r
+       int dim         /* (i) the dimension of all vectors */\r
+   ){\r
+       int     i, j;\r
+       int     pos, minindex;\r
+       float   dist, tmp, mindist;\r
+   \r
+       pos = 0;\r
+       mindist = FLOAT_MAX;\r
+       minindex = 0;\r
+       for (j = 0; j < n_cb; j++) {\r
+           dist = X[0] - CB[pos];\r
+           dist *= dist;\r
+           for (i = 1; i < dim; i++) {\r
+               tmp = X[i] - CB[pos + i];\r
+               dist += tmp*tmp;\r
+           }\r
+           \r
+           if (dist < mindist) {\r
+               mindist = dist;\r
+               minindex = j;\r
+           }\r
+           pos += dim;\r
+       }\r
+       for (i = 0; i < dim; i++) {\r
+           Xq[i] = CB[minindex*dim + i];\r
+       }\r
+       *index = minindex;\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  split vector quantization \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void SplitVQ( \r
+       float *qX,      /* (o) the quantized vector */\r
+       int *index,     /* (o) a vector of indexes for all vector\r
+                              codebooks in the split */\r
+       float *X,       /* (i) the vector to quantize */\r
+       const float *CB,/* (i) the quantizer codebook */\r
+       int nsplit,     /* the number of vector splits */\r
+       const int *dim, /* the dimension of X and qX */\r
+       const int *cbsize /* the number of vectors in the codebook */\r
+   ){\r
+       int    cb_pos, X_pos, i;\r
+       \r
+       cb_pos = 0;\r
+   \r
+   \r
+       X_pos= 0;\r
+       for (i = 0; i < nsplit; i++) {\r
+           vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, \r
+               cbsize[i], dim[i]);\r
+           X_pos += dim[i];\r
+           cb_pos += dim[i] * cbsize[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  scalar quantization \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void sort_sq( \r
+       float *xq,      /* (o) the quantized value */\r
+       int *index,     /* (o) the quantization index */\r
+       float x,    /* (i) the value to quantize */\r
+       const float *cb,/* (i) the quantization codebook */\r
+       int cb_size      /* (i) the size of the quantization codebook */\r
+   ){\r
+       int i;\r
+       \r
+       if (x <= cb[0]) {\r
+           *index = 0;\r
+           *xq = cb[0];\r
+       } else {\r
+           i = 0;\r
+           while ((x > cb[i]) && i < cb_size - 1) {\r
+               i++;\r
+           }\r
+           \r
+           if (x > ((cb[i] + cb[i - 1])/2)) {\r
+               *index = i;\r
+               *xq = cb[i];\r
+           } else {\r
+               *index = i - 1;\r
+               *xq = cb[i - 1];\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  check for stability of lsf coefficients\r
+    *---------------------------------------------------------------*/\r
+   \r
+   int LSF_check(    /* (o) 1 for stable lsf vectors and 0 for\r
+                              nonstable ones */\r
+       float *lsf,     /* (i) a table of lsf vectors */\r
+       int dim,    /* (i) the dimension of each lsf vector */\r
+       int NoAn    /* (i) the number of lsf vectors in the \r
+                              table */\r
+   ){\r
+       int k,n,m, Nit=2, change=0,pos;\r
+       float tmp;\r
+   \r
+   \r
+       static float eps=(float)0.039; /* 50 Hz */\r
+       static float eps2=(float)0.0195;\r
+       static float maxlsf=(float)3.14; /* 4000 Hz */\r
+       static float minlsf=(float)0.01; /* 0 Hz */\r
+       \r
+       /* LSF separation check*/\r
+   \r
+       for (n=0; n<Nit; n++) { /* Run through a couple of times */\r
+           for (m=0; m<NoAn; m++) { /* Number of analyses per frame */\r
+               for (k=0; k<(dim-1); k++) {\r
+                   pos=m*dim+k;\r
+                   \r
+                   if ((lsf[pos+1]-lsf[pos])<eps) {\r
+                       \r
+                       if (lsf[pos+1]<lsf[pos]) {\r
+                           tmp=lsf[pos+1];\r
+                           lsf[pos+1]= lsf[pos]+eps2;\r
+                           lsf[pos]= lsf[pos+1]-eps2;\r
+                       } else {\r
+                           lsf[pos]-=eps2;\r
+                           lsf[pos+1]+=eps2;\r
+                       }\r
+                       change=1;\r
+                   }\r
+                   \r
+                   if (lsf[pos]<minlsf) { \r
+                       lsf[pos]=minlsf;\r
+                       change=1;\r
+                   }\r
+                   \r
+                   if (lsf[pos]>maxlsf) { \r
+                       lsf[pos]=maxlsf;\r
+                       change=1;\r
+                   }               \r
+               }\r
+           }\r
+       }\r
+       \r
+       return change;  \r
+   }\r
+   \r
+   \r
index e2bc4b13407b2238476cbb1a218bb48db9bfe6f6..a6afa556c52c4a5bc736e6aac4d3de5895f5e94e 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    helpfun.h         \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_HELPFUN_H\r
-#define __iLBC_HELPFUN_H\r
-\r
-void autocorr( \r
-    float *r,       /* (o) autocorrelation vector */\r
-    const float *x, /* (i) data vector */\r
-    int N,          /* (i) length of data vector */\r
-    int order       /* largest lag for calculated \r
-                       autocorrelations */\r
-);\r
-\r
-void window( \r
-    float *z,       /* (o) the windowed data */\r
-    const float *x, /* (i) the original data vector */\r
-    const float *y, /* (i) the window */\r
-    int N           /* (i) length of all vectors */\r
-);\r
-\r
-\r
-\r
-void levdurb( \r
-    float *a,       /* (o) lpc coefficient vector starting \r
-                           with 1.0 */\r
-    float *k,       /* (o) reflection coefficients */\r
-    float *r,       /* (i) autocorrelation vector */\r
-    int order       /* (i) order of lpc filter */\r
-);\r
-\r
-void interpolate( \r
-    float *out,     /* (o) the interpolated vector */\r
-    float *in1,     /* (i) the first vector for the \r
-                           interpolation */\r
-    float *in2,     /* (i) the second vector for the \r
-                           interpolation */\r
-    float coef,     /* (i) interpolation weights */\r
-    int length      /* (i) length of all vectors */\r
-);\r
-           \r
-void bwexpand( \r
-    float *out,     /* (o) the bandwidth expanded lpc \r
-                           coefficients */\r
-    float *in,      /* (i) the lpc coefficients before bandwidth\r
-                           expansion */\r
-    float coef,     /* (i) the bandwidth expansion factor */\r
-    int length      /* (i) the length of lpc coefficient vectors */\r
-);\r
-\r
-void vq( \r
-    float *Xq,      /* (o) the quantized vector */\r
-    int *index,     /* (o) the quantization index */\r
-    const float *CB,/* (i) the vector quantization codebook */\r
-    float *X,       /* (i) the vector to quantize */\r
-    int n_cb,       /* (i) the number of vectors in the codebook */\r
-    int dim         /* (i) the dimension of all vectors */\r
-);  \r
-\r
-void SplitVQ( \r
-    float *qX,      /* (o) the quantized vector */\r
-    int *index,     /* (o) a vector of indexes for all vector\r
-                           codebooks in the split */\r
-    float *X,       /* (i) the vector to quantize */\r
-    const float *CB,/* (i) the quantizer codebook */\r
-    int nsplit,     /* the number of vector splits */\r
-    const int *dim, /* the dimension of X and qX */\r
-    const int *cbsize /* the number of vectors in the codebook */\r
-);\r
-\r
-\r
-void sort_sq( \r
-    float *xq,      /* (o) the quantized value */\r
-    int *index,     /* (o) the quantization index */\r
-    float x,    /* (i) the value to quantize */\r
-    const float *cb,/* (i) the quantization codebook */\r
-\r
-\r
-    int cb_size     /* (i) the size of the quantization codebook */\r
-);\r
-\r
-int LSF_check(      /* (o) 1 for stable lsf vectors and 0 for \r
-                           nonstable ones */\r
-    float *lsf,     /* (i) a table of lsf vectors */\r
-    int dim,    /* (i) the dimension of each lsf vector */\r
-    int NoAn    /* (i) the number of lsf vectors in the \r
-                           table */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       helpfun.h         \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_HELPFUN_H\r
+   #define __iLBC_HELPFUN_H\r
+   \r
+   void autocorr( \r
+       float *r,       /* (o) autocorrelation vector */\r
+       const float *x, /* (i) data vector */\r
+       int N,          /* (i) length of data vector */\r
+       int order       /* largest lag for calculated \r
+                          autocorrelations */\r
+   );\r
+   \r
+   void window( \r
+       float *z,       /* (o) the windowed data */\r
+       const float *x, /* (i) the original data vector */\r
+       const float *y, /* (i) the window */\r
+       int N           /* (i) length of all vectors */\r
+   );\r
+   \r
+   \r
+   \r
+   void levdurb( \r
+       float *a,       /* (o) lpc coefficient vector starting \r
+                              with 1.0 */\r
+       float *k,       /* (o) reflection coefficients */\r
+       float *r,       /* (i) autocorrelation vector */\r
+       int order       /* (i) order of lpc filter */\r
+   );\r
+   \r
+   void interpolate( \r
+       float *out,     /* (o) the interpolated vector */\r
+       float *in1,     /* (i) the first vector for the \r
+                              interpolation */\r
+       float *in2,     /* (i) the second vector for the \r
+                              interpolation */\r
+       float coef,     /* (i) interpolation weights */\r
+       int length      /* (i) length of all vectors */\r
+   );\r
+              \r
+   void bwexpand( \r
+       float *out,     /* (o) the bandwidth expanded lpc \r
+                              coefficients */\r
+       float *in,      /* (i) the lpc coefficients before bandwidth\r
+                              expansion */\r
+       float coef,     /* (i) the bandwidth expansion factor */\r
+       int length      /* (i) the length of lpc coefficient vectors */\r
+   );\r
+   \r
+   void vq( \r
+       float *Xq,      /* (o) the quantized vector */\r
+       int *index,     /* (o) the quantization index */\r
+       const float *CB,/* (i) the vector quantization codebook */\r
+       float *X,       /* (i) the vector to quantize */\r
+       int n_cb,       /* (i) the number of vectors in the codebook */\r
+       int dim         /* (i) the dimension of all vectors */\r
+   );  \r
+   \r
+   void SplitVQ( \r
+       float *qX,      /* (o) the quantized vector */\r
+       int *index,     /* (o) a vector of indexes for all vector\r
+                              codebooks in the split */\r
+       float *X,       /* (i) the vector to quantize */\r
+       const float *CB,/* (i) the quantizer codebook */\r
+       int nsplit,     /* the number of vector splits */\r
+       const int *dim, /* the dimension of X and qX */\r
+       const int *cbsize /* the number of vectors in the codebook */\r
+   );\r
+   \r
+   \r
+   void sort_sq( \r
+       float *xq,      /* (o) the quantized value */\r
+       int *index,     /* (o) the quantization index */\r
+       float x,    /* (i) the value to quantize */\r
+       const float *cb,/* (i) the quantization codebook */\r
+   \r
+   \r
+       int cb_size     /* (i) the size of the quantization codebook */\r
+   );\r
+   \r
+   int LSF_check(      /* (o) 1 for stable lsf vectors and 0 for \r
+                              nonstable ones */\r
+       float *lsf,     /* (i) a table of lsf vectors */\r
+       int dim,    /* (i) the dimension of each lsf vector */\r
+       int NoAn    /* (i) the number of lsf vectors in the \r
+                              table */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 54d997e755682fe7a4d6610c4c8dd0ede8a2eab8..4c35990906e8695855ef8e1f9f9058a372bd1c51 100644 (file)
@@ -1,60 +1,59 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    hpInput.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include "constants.h"\r
-#include "hpInput.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  Input high-pass filter                          \r
- *---------------------------------------------------------------*/\r
-\r
-void hpInput( \r
-    float *In,  /* (i) vector to filter */\r
-    int len,    /* (i) length of vector to filter */\r
-    float *Out, /* (o) the resulting filtered vector */\r
-    float *mem  /* (i/o) the filter state */\r
-){\r
-    int i;\r
-    float *pi, *po;\r
-\r
-    /* all-zero section*/\r
-\r
-    pi = &In[0];\r
-    po = &Out[0];\r
-    for (i=0; i<len; i++) {\r
-        *po = hpi_zero_coefsTbl[0] * (*pi);\r
-        *po += hpi_zero_coefsTbl[1] * mem[0];\r
-        *po += hpi_zero_coefsTbl[2] * mem[1];\r
-\r
-        mem[1] = mem[0];\r
-        mem[0] = *pi;\r
-        po++;\r
-\r
-\r
-        pi++;\r
-\r
-    }\r
-\r
-    /* all-pole section*/\r
-\r
-    po = &Out[0];\r
-    for (i=0; i<len; i++) {\r
-        *po -= hpi_pole_coefsTbl[1] * mem[2];\r
-        *po -= hpi_pole_coefsTbl[2] * mem[3];\r
-\r
-        mem[3] = mem[2];\r
-        mem[2] = *po;\r
-        po++;\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpInput.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Input high-pass filter                          \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void hpInput( \r
+       float *In,  /* (i) vector to filter */\r
+       int len,    /* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   ){\r
+       int i;\r
+       float *pi, *po;\r
+   \r
+       /* all-zero section*/\r
+   \r
+       pi = &In[0];\r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po = hpi_zero_coefsTbl[0] * (*pi);\r
+           *po += hpi_zero_coefsTbl[1] * mem[0];\r
+           *po += hpi_zero_coefsTbl[2] * mem[1];\r
+   \r
+           mem[1] = mem[0];\r
+           mem[0] = *pi;\r
+           po++;\r
+   \r
+   \r
+           pi++;\r
+   \r
+       }\r
+   \r
+       /* all-pole section*/\r
+   \r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po -= hpi_pole_coefsTbl[1] * mem[2];\r
+           *po -= hpi_pole_coefsTbl[2] * mem[3];\r
+   \r
+           mem[3] = mem[2];\r
+           mem[2] = *po;\r
+           po++;\r
+       }\r
+   }\r
+   \r
+   \r
index bd04762a83402b83010b1a7744f17cddf2663ad0..6c28e7ae622e639fb0870e79f37e8d6e53e93361 100644 (file)
@@ -1,27 +1,27 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    hpInput.h        \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-\r
-\r
-#ifndef __iLBC_HPINPUT_H\r
-#define __iLBC_HPINPUT_H\r
-\r
-void hpInput( \r
-    float *In,  /* (i) vector to filter */\r
-    int len,    /* (i) length of vector to filter */\r
-    float *Out, /* (o) the resulting filtered vector */\r
-    float *mem  /* (i/o) the filter state */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpInput.h        \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   \r
+   \r
+   #ifndef __iLBC_HPINPUT_H\r
+   #define __iLBC_HPINPUT_H\r
+   \r
+   void hpInput( \r
+       float *In,  /* (i) vector to filter */\r
+       int len,    /* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index d85444d44864303778883a752c92d6f04e5ee27d..8ecbdae9912766c3f1fb0199ae2a9f46ede232e0 100644 (file)
@@ -1,59 +1,59 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    hpOutput.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-\r
-\r
-******************************************************************/\r
-\r
-#include "constants.h"\r
-#include "hpOutput.h"\r
-/*----------------------------------------------------------------*\r
- *  Output high-pass filter                          \r
- *---------------------------------------------------------------*/\r
-\r
-void hpOutput(\r
-    float *In,  /* (i) vector to filter */\r
-    int len,/* (i) length of vector to filter */\r
-    float *Out, /* (o) the resulting filtered vector */\r
-    float *mem  /* (i/o) the filter state */\r
-){\r
-    int i;\r
-    float *pi, *po;\r
-\r
-    /* all-zero section*/\r
-\r
-    pi = &In[0];\r
-    po = &Out[0];\r
-    for (i=0; i<len; i++) {\r
-        *po = hpo_zero_coefsTbl[0] * (*pi);\r
-        *po += hpo_zero_coefsTbl[1] * mem[0];\r
-        *po += hpo_zero_coefsTbl[2] * mem[1];\r
-\r
-        mem[1] = mem[0];\r
-        mem[0] = *pi;\r
-        po++;\r
-        pi++;\r
-\r
-    }\r
-\r
-    /* all-pole section*/\r
-\r
-    po = &Out[0];\r
-    for (i=0; i<len; i++) {\r
-        *po -= hpo_pole_coefsTbl[1] * mem[2];\r
-        *po -= hpo_pole_coefsTbl[2] * mem[3];\r
-\r
-        mem[3] = mem[2];\r
-        mem[2] = *po;\r
-        po++;\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpOutput.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
   *  Output high-pass filter                          \r
   *---------------------------------------------------------------*/\r
+   \r
+   void hpOutput(\r
+       float *In,  /* (i) vector to filter */\r
+       int len,/* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   ){\r
+       int i;\r
+       float *pi, *po;\r
+   \r
+       /* all-zero section*/\r
+   \r
+       pi = &In[0];\r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po = hpo_zero_coefsTbl[0] * (*pi);\r
+           *po += hpo_zero_coefsTbl[1] * mem[0];\r
+           *po += hpo_zero_coefsTbl[2] * mem[1];\r
+   \r
+           mem[1] = mem[0];\r
+           mem[0] = *pi;\r
+           po++;\r
+           pi++;\r
+   \r
+       }\r
+   \r
+       /* all-pole section*/\r
+   \r
+       po = &Out[0];\r
+       for (i=0; i<len; i++) {\r
+           *po -= hpo_pole_coefsTbl[1] * mem[2];\r
+           *po -= hpo_pole_coefsTbl[2] * mem[3];\r
+   \r
+           mem[3] = mem[2];\r
+           mem[2] = *po;\r
+           po++;\r
+       }\r
+   }\r
+   \r
+   \r
index 50c4914c363bbc2a49452d79c2ab4a0408da79a3..0e92615405048ed300f5c85707daf7fc1406f6ff 100644 (file)
@@ -1,25 +1,25 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    hpOutput.h       \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_HPOUTPUT_H\r
-#define __iLBC_HPOUTPUT_H\r
-\r
-void hpOutput(\r
-    float *In,  /* (i) vector to filter */\r
-    int len,/* (i) length of vector to filter */\r
-    float *Out, /* (o) the resulting filtered vector */\r
-    float *mem  /* (i/o) the filter state */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       hpOutput.h       \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_HPOUTPUT_H\r
+   #define __iLBC_HPOUTPUT_H\r
+   \r
+   void hpOutput(\r
+       float *In,  /* (i) vector to filter */\r
+       int len,/* (i) length of vector to filter */\r
+       float *Out, /* (o) the resulting filtered vector */\r
+       float *mem  /* (i/o) the filter state */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 2d934b0af51a08f0c63b429d40ec8d92d4b5cf2f..9e90623c301eb2b734098f1eaf7e016b8df82271 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iCBConstruct.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "iCBConstruct.h"\r
-#include "gainquant.h"\r
-#include "getCBvec.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  Convert the codebook indexes to make the search easier\r
- *---------------------------------------------------------------*/\r
-\r
-\r
-\r
-void index_conv_enc(\r
-    int *index          /* (i/o) Codebook indexes */\r
-){\r
-    int k;\r
-\r
-    for (k=1; k<CB_NSTAGES; k++) {\r
-        \r
-        if ((index[k]>=108)&&(index[k]<172)) {\r
-            index[k]-=64;\r
-        } else if (index[k]>=236) {\r
-            index[k]-=128;\r
-        } else {\r
-            /* ERROR */\r
-        }\r
-    }\r
-}\r
-\r
-void index_conv_dec(\r
-    int *index          /* (i/o) Codebook indexes */\r
-){\r
-    int k;\r
-\r
-    for (k=1; k<CB_NSTAGES; k++) {\r
-        \r
-        if ((index[k]>=44)&&(index[k]<108)) {\r
-            index[k]+=64;\r
-        } else if ((index[k]>=108)&&(index[k]<128)) {\r
-            index[k]+=128;\r
-        } else {\r
-            /* ERROR */\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  Construct decoded vector from codebook and gains.\r
- *---------------------------------------------------------------*/\r
-\r
-void iCBConstruct(\r
-    float *decvector,   /* (o) Decoded vector */\r
-    int *index,         /* (i) Codebook indices */\r
-    int *gain_index,/* (i) Gain quantization indices */\r
-    float *mem,         /* (i) Buffer for codevector construction */\r
-    int lMem,           /* (i) Length of buffer */\r
-    int veclen,         /* (i) Length of vector */\r
-    int nStages         /* (i) Number of codebook stages */\r
-){\r
-    int j,k;\r
-    float gain[CB_NSTAGES];\r
-    float cbvec[SUBL];\r
-\r
-    /* gain de-quantization */\r
-\r
-    gain[0] = gaindequant(gain_index[0], 1.0, 32);\r
-\r
-\r
-    if (nStages > 1) {\r
-        gain[1] = gaindequant(gain_index[1], \r
-            (float)fabs(gain[0]), 16);  \r
-    }\r
-    if (nStages > 2) {\r
-        gain[2] = gaindequant(gain_index[2], \r
-            (float)fabs(gain[1]), 8);\r
-    }\r
-\r
-    /* codebook vector construction and construction of \r
-    total vector */\r
-\r
-    getCBvec(cbvec, mem, index[0], lMem, veclen);\r
-    for (j=0;j<veclen;j++){\r
-        decvector[j] = gain[0]*cbvec[j];\r
-    }\r
-    if (nStages > 1) {\r
-        for (k=1; k<nStages; k++) {\r
-            getCBvec(cbvec, mem, index[k], lMem, veclen);\r
-            for (j=0;j<veclen;j++) {\r
-                decvector[j] += gain[k]*cbvec[j];\r
-            }\r
-        }\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iCBConstruct.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "gainquant.h"\r
+   #include "getCBvec.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Convert the codebook indexes to make the search easier\r
+    *---------------------------------------------------------------*/\r
+   \r
+   \r
+   \r
+   void index_conv_enc(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   ){\r
+       int k;\r
+   \r
+       for (k=1; k<CB_NSTAGES; k++) {\r
+           \r
+           if ((index[k]>=108)&&(index[k]<172)) {\r
+               index[k]-=64;\r
+           } else if (index[k]>=236) {\r
+               index[k]-=128;\r
+           } else {\r
+               /* ERROR */\r
+           }\r
+       }\r
+   }\r
+   \r
+   void index_conv_dec(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   ){\r
+       int k;\r
+   \r
+       for (k=1; k<CB_NSTAGES; k++) {\r
+           \r
+           if ((index[k]>=44)&&(index[k]<108)) {\r
+               index[k]+=64;\r
+           } else if ((index[k]>=108)&&(index[k]<128)) {\r
+               index[k]+=128;\r
+           } else {\r
+               /* ERROR */\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Construct decoded vector from codebook and gains.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iCBConstruct(\r
+       float *decvector,   /* (o) Decoded vector */\r
+       int *index,         /* (i) Codebook indices */\r
+       int *gain_index,/* (i) Gain quantization indices */\r
+       float *mem,         /* (i) Buffer for codevector construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int veclen,         /* (i) Length of vector */\r
+       int nStages         /* (i) Number of codebook stages */\r
+   ){\r
+       int j,k;\r
+       float gain[CB_NSTAGES];\r
+       float cbvec[SUBL];\r
+   \r
+       /* gain de-quantization */\r
+   \r
+       gain[0] = gaindequant(gain_index[0], 1.0, 32);\r
+   \r
+   \r
+       if (nStages > 1) {\r
+           gain[1] = gaindequant(gain_index[1], \r
+               (float)fabs(gain[0]), 16);  \r
+       }\r
+       if (nStages > 2) {\r
+           gain[2] = gaindequant(gain_index[2], \r
+               (float)fabs(gain[1]), 8);\r
+       }\r
+   \r
+       /* codebook vector construction and construction of \r
+       total vector */\r
+   \r
+       getCBvec(cbvec, mem, index[0], lMem, veclen);\r
+       for (j=0;j<veclen;j++){\r
+           decvector[j] = gain[0]*cbvec[j];\r
+       }\r
+       if (nStages > 1) {\r
+           for (k=1; k<nStages; k++) {\r
+               getCBvec(cbvec, mem, index[k], lMem, veclen);\r
+               for (j=0;j<veclen;j++) {\r
+                   decvector[j] += gain[k]*cbvec[j];\r
+               }\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
index d8c69d993f21c5fa06e656ad51c0ba97c8daa25e..6cd9dcd2182791e60266ef94d344e6446bd5d893 100644 (file)
@@ -1,38 +1,38 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-\r
-\r
-    iCBConstruct.h   \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_ICBCONSTRUCT_H\r
-#define __iLBC_ICBCONSTRUCT_H\r
-\r
-void index_conv_enc(\r
-    int *index          /* (i/o) Codebook indexes */\r
-);\r
-\r
-void index_conv_dec(\r
-    int *index          /* (i/o) Codebook indexes */\r
-);\r
-\r
-void iCBConstruct(\r
-    float *decvector,   /* (o) Decoded vector */\r
-    int *index,         /* (i) Codebook indices */\r
-    int *gain_index,/* (i) Gain quantization indices */\r
-    float *mem,         /* (i) Buffer for codevector construction */\r
-    int lMem,           /* (i) Length of buffer */\r
-    int veclen,         /* (i) Length of vector */\r
-    int nStages         /* (i) Number of codebook stages */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+   \r
+   \r
+       iCBConstruct.h   \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ICBCONSTRUCT_H\r
+   #define __iLBC_ICBCONSTRUCT_H\r
+   \r
+   void index_conv_enc(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   );\r
+   \r
+   void index_conv_dec(\r
+       int *index          /* (i/o) Codebook indexes */\r
+   );\r
+   \r
+   void iCBConstruct(\r
+       float *decvector,   /* (o) Decoded vector */\r
+       int *index,         /* (i) Codebook indices */\r
+       int *gain_index,/* (i) Gain quantization indices */\r
+       float *mem,         /* (i) Buffer for codevector construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int veclen,         /* (i) Length of vector */\r
+       int nStages         /* (i) Number of codebook stages */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 80c6f2dd69eb54fff0854315d5cd166e6223cf6b..fa8f4851b7d374a861e8babd99279f3a024aec16 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iCBSearch.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <string.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "iCBSearch.h"\r
-#include "gainquant.h"\r
-#include "createCB.h"\r
-#include "filter.h"\r
-#include "constants.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  Search routine for codebook encoding and gain quantization.\r
- *---------------------------------------------------------------*/\r
-\r
-void iCBSearch(\r
-    iLBC_Enc_Inst_t *iLBCenc_inst, \r
-                        /* (i) the encoder state structure */\r
-    int *index,         /* (o) Codebook indices */\r
-    int *gain_index,/* (o) Gain quantization indices */\r
-    float *intarget,/* (i) Target vector for encoding */    \r
-    float *mem,         /* (i) Buffer for codebook construction */\r
-    int lMem,           /* (i) Length of buffer */\r
-    int lTarget,    /* (i) Length of vector */\r
-    int nStages,    /* (i) Number of codebook stages */\r
-    float *weightDenum, /* (i) weighting filter coefficients */\r
-    float *weightState, /* (i) weighting filter state */\r
-    int block           /* (i) the sub-block number */\r
-){\r
-    int i, j, icount, stage, best_index, range, counter;\r
-    float max_measure, gain, measure, crossDot, ftmp;\r
-    float gains[CB_NSTAGES];\r
-    float target[SUBL];\r
-    int base_index, sInd, eInd, base_size;\r
-    int sIndAug=0, eIndAug=0;\r
-    float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];\r
-\r
-\r
-    float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];\r
-    float *pp, *ppi=0, *ppo=0, *ppe=0;\r
-    float cbvectors[CB_MEML];\r
-    float tene, cene, cvec[SUBL];\r
-    float aug_vec[SUBL];\r
-\r
-    memset(cvec,0,SUBL*sizeof(float));  \r
-\r
-    /* Determine size of codebook sections */\r
-\r
-    base_size=lMem-lTarget+1;\r
-    \r
-    if (lTarget==SUBL) {\r
-        base_size=lMem-lTarget+1+lTarget/2;\r
-    }\r
-\r
-    /* setup buffer for weighting */\r
-\r
-    memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);\r
-    memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));\r
-    memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));\r
-\r
-    /* weighting */\r
-\r
-    AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, \r
-        lMem+lTarget, LPC_FILTERORDER);\r
-    \r
-    /* Construct the codebook and target needed */\r
-\r
-    memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));\r
-\r
-    tene=0.0;\r
-    for (i=0; i<lTarget; i++) {\r
-        tene+=target[i]*target[i];\r
-    }\r
-\r
-    /* Prepare search over one more codebook section. This section \r
-       is created by filtering the original buffer with a filter. */\r
-        \r
-    filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);\r
-\r
-    /* The Main Loop over stages */\r
-\r
-    for (stage=0; stage<nStages; stage++) {\r
-\r
-        range = search_rangeTbl[block][stage];\r
-\r
-        /* initialize search measure */\r
-\r
-        max_measure = (float)-10000000.0;\r
-        gain = (float)0.0;\r
-        best_index = 0;\r
-\r
-        /* Compute cross dot product between the target \r
-\r
-\r
-           and the CB memory */\r
-\r
-        crossDot=0.0;\r
-        pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
-        for (j=0; j<lTarget; j++) {\r
-            crossDot += target[j]*(*pp++);\r
-        }       \r
-        \r
-        if (stage==0) {\r
-\r
-            /* Calculate energy in the first block of \r
-              'lTarget' sampels. */\r
-            ppe = energy;\r
-            ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;\r
-            ppo = buf+LPC_FILTERORDER+lMem-1;\r
-\r
-            *ppe=0.0;\r
-            pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
-            for (j=0; j<lTarget; j++) {\r
-                *ppe+=(*pp)*(*pp);\r
-                               pp++;\r
-            }\r
-            \r
-            if (*ppe>0.0) {\r
-                invenergy[0] = (float) 1.0 / (*ppe + EPS);\r
-            } else {\r
-                invenergy[0] = (float) 0.0; \r
-            }\r
-            ppe++;\r
-\r
-            measure=(float)-10000000.0; \r
-            \r
-            if (crossDot > 0.0) {\r
-                   measure = crossDot*crossDot*invenergy[0];\r
-            }\r
-        }\r
-        else {\r
-            measure = crossDot*crossDot*invenergy[0];\r
-        }\r
-\r
-        /* check if measure is better */\r
-        ftmp = crossDot*invenergy[0];\r
-        \r
-        if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
-            best_index = 0;\r
-            max_measure = measure;\r
-            gain = ftmp;\r
-        }\r
-\r
-        /* loop over the main first codebook section, \r
-           full search */\r
-\r
-        for (icount=1; icount<range; icount++) {\r
-\r
-            /* calculate measure */\r
-\r
-\r
-\r
-            crossDot=0.0;\r
-            pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;\r
-\r
-            for (j=0; j<lTarget; j++) {\r
-                crossDot += target[j]*(*pp++);\r
-            }\r
-            \r
-            if (stage==0) {\r
-                *ppe++ = energy[icount-1] + (*ppi)*(*ppi) - \r
-                    (*ppo)*(*ppo);\r
-                ppo--;\r
-                ppi--;\r
-                \r
-                if (energy[icount]>0.0) {\r
-                    invenergy[icount] = \r
-                        (float)1.0/(energy[icount]+EPS);\r
-                } else {\r
-                    invenergy[icount] = (float) 0.0;\r
-                }\r
-\r
-                measure=(float)-10000000.0;\r
-                \r
-                if (crossDot > 0.0) {\r
-                    measure = crossDot*crossDot*invenergy[icount];\r
-                }\r
-            }\r
-            else {\r
-                measure = crossDot*crossDot*invenergy[icount];\r
-            }\r
-\r
-            /* check if measure is better */\r
-            ftmp = crossDot*invenergy[icount];\r
-\r
-            if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
-                best_index = icount;\r
-                max_measure = measure;\r
-                gain = ftmp;\r
-            }\r
-        }\r
-\r
-        /* Loop over augmented part in the first codebook \r
-         * section, full search.\r
-         * The vectors are interpolated.\r
-         */\r
-        \r
-        if (lTarget==SUBL) {        \r
-            \r
-            /* Search for best possible cb vector and \r
-               compute the CB-vectors' energy. */\r
-            searchAugmentedCB(20, 39, stage, base_size-lTarget/2, \r
-                target, buf+LPC_FILTERORDER+lMem,\r
-                &max_measure, &best_index, &gain, energy, \r
-                invenergy);\r
-\r
-\r
-        }\r
-\r
-        /* set search range for following codebook sections */\r
-\r
-        base_index=best_index;\r
-\r
-        /* unrestricted search */\r
-\r
-        if (CB_RESRANGE == -1) {\r
-            sInd=0;\r
-            eInd=range-1;\r
-            sIndAug=20;\r
-            eIndAug=39;\r
-        }\r
-\r
-        /* restriced search around best index from first \r
-        codebook section */\r
-\r
-        else {\r
-            /* Initialize search indices */\r
-            sIndAug=0;\r
-            eIndAug=0;\r
-            sInd=base_index-CB_RESRANGE/2;\r
-            eInd=sInd+CB_RESRANGE;\r
-            \r
-            if (lTarget==SUBL) {\r
-\r
-                if (sInd<0) {\r
-                    \r
-                    sIndAug = 40 + sInd;\r
-                    eIndAug = 39;\r
-                    sInd=0;\r
-\r
-                } else if ( base_index < (base_size-20) ) {\r
-                    \r
-                    if (eInd > range) {\r
-                        sInd -= (eInd-range);\r
-                        eInd = range;\r
-                    }\r
-                } else { /* base_index >= (base_size-20) */\r
-                    \r
-                    if (sInd < (base_size-20)) {\r
-                        sIndAug = 20;\r
-                        sInd = 0;\r
-                        eInd = 0;\r
-                        eIndAug = 19 + CB_RESRANGE;\r
-                        \r
-                        if(eIndAug > 39) {\r
-                            eInd = eIndAug-39;\r
-                            eIndAug = 39;\r
-                        }\r
-                    } else {\r
-                        sIndAug = 20 + sInd - (base_size-20);\r
-                        eIndAug = 39;\r
-\r
-\r
-                        sInd = 0;\r
-                        eInd = CB_RESRANGE - (eIndAug-sIndAug+1);\r
-                    }\r
-                }\r
-\r
-            } else { /* lTarget = 22 or 23 */\r
-                \r
-                if (sInd < 0) {\r
-                    eInd -= sInd;\r
-                    sInd = 0;\r
-                }\r
-                \r
-                if(eInd > range) {\r
-                    sInd -= (eInd - range);\r
-                    eInd = range;\r
-                }\r
-            }\r
-        }\r
-\r
-        /* search of higher codebook section */\r
-\r
-        /* index search range */\r
-        counter = sInd;\r
-        sInd += base_size;\r
-        eInd += base_size;\r
-        \r
-        \r
-        if (stage==0) {\r
-            ppe = energy+base_size;\r
-            *ppe=0.0;\r
-\r
-            pp=cbvectors+lMem-lTarget;\r
-            for (j=0; j<lTarget; j++) {\r
-                *ppe+=(*pp)*(*pp);\r
-                               pp++;\r
-            }\r
-\r
-            ppi = cbvectors + lMem - 1 - lTarget;\r
-            ppo = cbvectors + lMem - 1;\r
-            \r
-            for (j=0; j<(range-1); j++) {\r
-                *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);\r
-                ppo--;\r
-                ppi--;\r
-                ppe++;\r
-            }\r
-        }\r
-\r
-        /* loop over search range */\r
-\r
-        for (icount=sInd; icount<eInd; icount++) {\r
-\r
-            /* calculate measure */\r
-\r
-            crossDot=0.0;\r
-\r
-\r
-            pp=cbvectors + lMem - (counter++) - lTarget;\r
-\r
-            for (j=0;j<lTarget;j++) {\r
-                crossDot += target[j]*(*pp++);\r
-            }\r
-            \r
-            if (energy[icount]>0.0) {\r
-                invenergy[icount] =(float)1.0/(energy[icount]+EPS);\r
-            } else {\r
-                invenergy[icount] =(float)0.0;\r
-            }\r
-            \r
-            if (stage==0) {\r
-\r
-                measure=(float)-10000000.0;\r
-                \r
-                if (crossDot > 0.0) {\r
-                    measure = crossDot*crossDot*\r
-                        invenergy[icount];\r
-                }\r
-            }\r
-            else {\r
-                measure = crossDot*crossDot*invenergy[icount];\r
-            }\r
-\r
-            /* check if measure is better */\r
-            ftmp = crossDot*invenergy[icount];\r
-\r
-            if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
-                best_index = icount;\r
-                max_measure = measure;\r
-                gain = ftmp;\r
-            }\r
-        }\r
-\r
-        /* Search the augmented CB inside the limited range. */\r
-        \r
-        if ((lTarget==SUBL)&&(sIndAug!=0)) {\r
-            searchAugmentedCB(sIndAug, eIndAug, stage, \r
-                2*base_size-20, target, cbvectors+lMem,\r
-                &max_measure, &best_index, &gain, energy, \r
-                invenergy);\r
-        }\r
-\r
-        /* record best index */\r
-\r
-        index[stage] = best_index;\r
-\r
-        /* gain quantization */\r
-\r
-        if (stage==0){\r
-            \r
-            if (gain<0.0){\r
-                gain = 0.0;\r
-\r
-\r
-            }\r
-            \r
-            if (gain>CB_MAXGAIN) {\r
-                gain = (float)CB_MAXGAIN;\r
-            }\r
-            gain = gainquant(gain, 1.0, 32, &gain_index[stage]);\r
-        }\r
-        else {\r
-            if (stage==1) {\r
-                gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
-                    16, &gain_index[stage]);\r
-            } else {\r
-                gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
-                    8, &gain_index[stage]);\r
-            }\r
-        }\r
-\r
-        /* Extract the best (according to measure) \r
-           codebook vector */\r
-        \r
-        if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {\r
-            \r
-            if (index[stage]<base_size) {\r
-                pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];\r
-            } else {\r
-                pp=cbvectors+lMem-lTarget-\r
-                    index[stage]+base_size;\r
-            }\r
-        } else {\r
-            \r
-            if (index[stage]<base_size) {\r
-                if (index[stage]<(base_size-20)) {\r
-                    pp=buf+LPC_FILTERORDER+lMem-\r
-                        lTarget-index[stage];\r
-                } else {\r
-                    createAugmentedVec(index[stage]-base_size+40,\r
-                            buf+LPC_FILTERORDER+lMem,aug_vec);\r
-                    pp=aug_vec;\r
-                }\r
-            } else {\r
-                int filterno, position;\r
-\r
-                filterno=index[stage]/base_size;\r
-                position=index[stage]-filterno*base_size;\r
-\r
-                \r
-                if (position<(base_size-20)) {\r
-                    pp=cbvectors+filterno*lMem-lTarget-\r
-                        index[stage]+filterno*base_size;\r
-                } else {\r
-                    createAugmentedVec(\r
-                        index[stage]-(filterno+1)*base_size+40,\r
-                        cbvectors+filterno*lMem,aug_vec);\r
-                    pp=aug_vec;\r
-\r
-\r
-                }\r
-            }\r
-        }\r
-\r
-        /* Subtract the best codebook vector, according \r
-           to measure, from the target vector */\r
-\r
-        for (j=0;j<lTarget;j++) {\r
-            cvec[j] += gain*(*pp);\r
-            target[j] -= gain*(*pp++);\r
-        }\r
-\r
-        /* record quantized gain */\r
-\r
-        gains[stage]=gain;\r
-\r
-    }/* end of Main Loop. for (stage=0;... */\r
-\r
-    /* Gain adjustment for energy matching */\r
-    cene=0.0;\r
-    for (i=0; i<lTarget; i++) {\r
-        cene+=cvec[i]*cvec[i];\r
-    }\r
-    j=gain_index[0];\r
-\r
-    for (i=gain_index[0]; i<32; i++) {\r
-        ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];\r
-        \r
-        if ((ftmp<(tene*gains[0]*gains[0])) && \r
-            (gain_sq5Tbl[j]<(2.0*gains[0]))) {\r
-            j=i;\r
-        }\r
-    }\r
-    gain_index[0]=j;\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iCBSearch.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "gainquant.h"\r
+   #include "createCB.h"\r
+   #include "filter.h"\r
+   #include "constants.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Search routine for codebook encoding and gain quantization.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iCBSearch(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i) the encoder state structure */\r
+       int *index,         /* (o) Codebook indices */\r
+       int *gain_index,/* (o) Gain quantization indices */\r
+       float *intarget,/* (i) Target vector for encoding */    \r
+       float *mem,         /* (i) Buffer for codebook construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int lTarget,    /* (i) Length of vector */\r
+       int nStages,    /* (i) Number of codebook stages */\r
+       float *weightDenum, /* (i) weighting filter coefficients */\r
+       float *weightState, /* (i) weighting filter state */\r
+       int block           /* (i) the sub-block number */\r
+   ){\r
+       int i, j, icount, stage, best_index, range, counter;\r
+       float max_measure, gain, measure, crossDot, ftmp;\r
+       float gains[CB_NSTAGES];\r
+       float target[SUBL];\r
+       int base_index, sInd, eInd, base_size;\r
+       int sIndAug=0, eIndAug=0;\r
+       float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];\r
+   \r
+   \r
+       float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];\r
+       float *pp, *ppi=0, *ppo=0, *ppe=0;\r
+       float cbvectors[CB_MEML];\r
+       float tene, cene, cvec[SUBL];\r
+       float aug_vec[SUBL];\r
+   \r
+       memset(cvec,0,SUBL*sizeof(float));  \r
+   \r
+       /* Determine size of codebook sections */\r
+   \r
+       base_size=lMem-lTarget+1;\r
+       \r
+       if (lTarget==SUBL) {\r
+           base_size=lMem-lTarget+1+lTarget/2;\r
+       }\r
+   \r
+       /* setup buffer for weighting */\r
+   \r
+       memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);\r
+       memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));\r
+       memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));\r
+   \r
+       /* weighting */\r
+   \r
+       AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, \r
+           lMem+lTarget, LPC_FILTERORDER);\r
+       \r
+       /* Construct the codebook and target needed */\r
+   \r
+       memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));\r
+   \r
+       tene=0.0;\r
+       for (i=0; i<lTarget; i++) {\r
+           tene+=target[i]*target[i];\r
+       }\r
+   \r
+       /* Prepare search over one more codebook section. This section \r
+          is created by filtering the original buffer with a filter. */\r
+           \r
+       filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);\r
+   \r
+       /* The Main Loop over stages */\r
+   \r
+       for (stage=0; stage<nStages; stage++) {\r
+   \r
+           range = search_rangeTbl[block][stage];\r
+   \r
+           /* initialize search measure */\r
+   \r
+           max_measure = (float)-10000000.0;\r
+           gain = (float)0.0;\r
+           best_index = 0;\r
+   \r
+           /* Compute cross dot product between the target \r
+   \r
+   \r
+              and the CB memory */\r
+   \r
+           crossDot=0.0;\r
+           pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
+           for (j=0; j<lTarget; j++) {\r
+               crossDot += target[j]*(*pp++);\r
+           }       \r
+           \r
+           if (stage==0) {\r
+   \r
+               /* Calculate energy in the first block of \r
+                 'lTarget' sampels. */\r
+               ppe = energy;\r
+               ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;\r
+               ppo = buf+LPC_FILTERORDER+lMem-1;\r
+   \r
+               *ppe=0.0;\r
+               pp=buf+LPC_FILTERORDER+lMem-lTarget;\r
+               for (j=0; j<lTarget; j++) {\r
+                   *ppe+=(*pp)*(*pp++);\r
+               }\r
+               \r
+               if (*ppe>0.0) {\r
+                   invenergy[0] = (float) 1.0 / (*ppe + EPS);\r
+               } else {\r
+                   invenergy[0] = (float) 0.0; \r
+               }\r
+               ppe++;\r
+   \r
+               measure=(float)-10000000.0; \r
+               \r
+               if (crossDot > 0.0) {\r
+                      measure = crossDot*crossDot*invenergy[0];\r
+               }\r
+           }\r
+           else {\r
+               measure = crossDot*crossDot*invenergy[0];\r
+           }\r
+   \r
+           /* check if measure is better */\r
+           ftmp = crossDot*invenergy[0];\r
+           \r
+           if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+               best_index = 0;\r
+               max_measure = measure;\r
+               gain = ftmp;\r
+           }\r
+   \r
+           /* loop over the main first codebook section, \r
+              full search */\r
+   \r
+           for (icount=1; icount<range; icount++) {\r
+   \r
+               /* calculate measure */\r
+   \r
+   \r
+   \r
+               crossDot=0.0;\r
+               pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;\r
+   \r
+               for (j=0; j<lTarget; j++) {\r
+                   crossDot += target[j]*(*pp++);\r
+               }\r
+               \r
+               if (stage==0) {\r
+                   *ppe++ = energy[icount-1] + (*ppi)*(*ppi) - \r
+                       (*ppo)*(*ppo);\r
+                   ppo--;\r
+                   ppi--;\r
+                   \r
+                   if (energy[icount]>0.0) {\r
+                       invenergy[icount] = \r
+                           (float)1.0/(energy[icount]+EPS);\r
+                   } else {\r
+                       invenergy[icount] = (float) 0.0;\r
+                   }\r
+   \r
+                   measure=(float)-10000000.0;\r
+                   \r
+                   if (crossDot > 0.0) {\r
+                       measure = crossDot*crossDot*invenergy[icount];\r
+                   }\r
+               }\r
+               else {\r
+                   measure = crossDot*crossDot*invenergy[icount];\r
+               }\r
+   \r
+               /* check if measure is better */\r
+               ftmp = crossDot*invenergy[icount];\r
+   \r
+               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+                   best_index = icount;\r
+                   max_measure = measure;\r
+                   gain = ftmp;\r
+               }\r
+           }\r
+   \r
+           /* Loop over augmented part in the first codebook \r
+            * section, full search.\r
+            * The vectors are interpolated.\r
+            */\r
+           \r
+           if (lTarget==SUBL) {        \r
+               \r
+               /* Search for best possible cb vector and \r
+                  compute the CB-vectors' energy. */\r
+               searchAugmentedCB(20, 39, stage, base_size-lTarget/2, \r
+                   target, buf+LPC_FILTERORDER+lMem,\r
+                   &max_measure, &best_index, &gain, energy, \r
+                   invenergy);\r
+   \r
+   \r
+           }\r
+   \r
+           /* set search range for following codebook sections */\r
+   \r
+           base_index=best_index;\r
+   \r
+           /* unrestricted search */\r
+   \r
+           if (CB_RESRANGE == -1) {\r
+               sInd=0;\r
+               eInd=range-1;\r
+               sIndAug=20;\r
+               eIndAug=39;\r
+           }\r
+   \r
+           /* restriced search around best index from first \r
+           codebook section */\r
+   \r
+           else {\r
+               /* Initialize search indices */\r
+               sIndAug=0;\r
+               eIndAug=0;\r
+               sInd=base_index-CB_RESRANGE/2;\r
+               eInd=sInd+CB_RESRANGE;\r
+               \r
+               if (lTarget==SUBL) {\r
+   \r
+                   if (sInd<0) {\r
+                       \r
+                       sIndAug = 40 + sInd;\r
+                       eIndAug = 39;\r
+                       sInd=0;\r
+   \r
+                   } else if ( base_index < (base_size-20) ) {\r
+                       \r
+                       if (eInd > range) {\r
+                           sInd -= (eInd-range);\r
+                           eInd = range;\r
+                       }\r
+                   } else { /* base_index >= (base_size-20) */\r
+                       \r
+                       if (sInd < (base_size-20)) {\r
+                           sIndAug = 20;\r
+                           sInd = 0;\r
+                           eInd = 0;\r
+                           eIndAug = 19 + CB_RESRANGE;\r
+                           \r
+                           if(eIndAug > 39) {\r
+                               eInd = eIndAug-39;\r
+                               eIndAug = 39;\r
+                           }\r
+                       } else {\r
+                           sIndAug = 20 + sInd - (base_size-20);\r
+                           eIndAug = 39;\r
+   \r
+   \r
+                           sInd = 0;\r
+                           eInd = CB_RESRANGE - (eIndAug-sIndAug+1);\r
+                       }\r
+                   }\r
+   \r
+               } else { /* lTarget = 22 or 23 */\r
+                   \r
+                   if (sInd < 0) {\r
+                       eInd -= sInd;\r
+                       sInd = 0;\r
+                   }\r
+                   \r
+                   if(eInd > range) {\r
+                       sInd -= (eInd - range);\r
+                       eInd = range;\r
+                   }\r
+               }\r
+           }\r
+   \r
+           /* search of higher codebook section */\r
+   \r
+           /* index search range */\r
+           counter = sInd;\r
+           sInd += base_size;\r
+           eInd += base_size;\r
+           \r
+           \r
+           if (stage==0) {\r
+               ppe = energy+base_size;\r
+               *ppe=0.0;\r
+   \r
+               pp=cbvectors+lMem-lTarget;\r
+               for (j=0; j<lTarget; j++) {\r
+                   *ppe+=(*pp)*(*pp++);\r
+               }\r
+   \r
+               ppi = cbvectors + lMem - 1 - lTarget;\r
+               ppo = cbvectors + lMem - 1;\r
+               \r
+               for (j=0; j<(range-1); j++) {\r
+                   *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);\r
+                   ppo--;\r
+                   ppi--;\r
+                   ppe++;\r
+               }\r
+           }\r
+   \r
+           /* loop over search range */\r
+   \r
+           for (icount=sInd; icount<eInd; icount++) {\r
+   \r
+               /* calculate measure */\r
+   \r
+               crossDot=0.0;\r
+   \r
+   \r
+               pp=cbvectors + lMem - (counter++) - lTarget;\r
+   \r
+               for (j=0;j<lTarget;j++) {\r
+                   crossDot += target[j]*(*pp++);\r
+               }\r
+               \r
+               if (energy[icount]>0.0) {\r
+                   invenergy[icount] =(float)1.0/(energy[icount]+EPS);\r
+               } else {\r
+                   invenergy[icount] =(float)0.0;\r
+               }\r
+               \r
+               if (stage==0) {\r
+   \r
+                   measure=(float)-10000000.0;\r
+                   \r
+                   if (crossDot > 0.0) {\r
+                       measure = crossDot*crossDot*\r
+                           invenergy[icount];\r
+                   }\r
+               }\r
+               else {\r
+                   measure = crossDot*crossDot*invenergy[icount];\r
+               }\r
+   \r
+               /* check if measure is better */\r
+               ftmp = crossDot*invenergy[icount];\r
+   \r
+               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {\r
+                   best_index = icount;\r
+                   max_measure = measure;\r
+                   gain = ftmp;\r
+               }\r
+           }\r
+   \r
+           /* Search the augmented CB inside the limited range. */\r
+           \r
+           if ((lTarget==SUBL)&&(sIndAug!=0)) {\r
+               searchAugmentedCB(sIndAug, eIndAug, stage, \r
+                   2*base_size-20, target, cbvectors+lMem,\r
+                   &max_measure, &best_index, &gain, energy, \r
+                   invenergy);\r
+           }\r
+   \r
+           /* record best index */\r
+   \r
+           index[stage] = best_index;\r
+   \r
+           /* gain quantization */\r
+   \r
+           if (stage==0){\r
+               \r
+               if (gain<0.0){\r
+                   gain = 0.0;\r
+   \r
+   \r
+               }\r
+               \r
+               if (gain>CB_MAXGAIN) {\r
+                   gain = (float)CB_MAXGAIN;\r
+               }\r
+               gain = gainquant(gain, 1.0, 32, &gain_index[stage]);\r
+           }\r
+           else {\r
+               if (stage==1) {\r
+                   gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
+                       16, &gain_index[stage]);\r
+               } else {\r
+                   gain = gainquant(gain, (float)fabs(gains[stage-1]),\r
+                       8, &gain_index[stage]);\r
+               }\r
+           }\r
+   \r
+           /* Extract the best (according to measure) \r
+              codebook vector */\r
+           \r
+           if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {\r
+               \r
+               if (index[stage]<base_size) {\r
+                   pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];\r
+               } else {\r
+                   pp=cbvectors+lMem-lTarget-\r
+                       index[stage]+base_size;\r
+               }\r
+           } else {\r
+               \r
+               if (index[stage]<base_size) {\r
+                   if (index[stage]<(base_size-20)) {\r
+                       pp=buf+LPC_FILTERORDER+lMem-\r
+                           lTarget-index[stage];\r
+                   } else {\r
+                       createAugmentedVec(index[stage]-base_size+40,\r
+                               buf+LPC_FILTERORDER+lMem,aug_vec);\r
+                       pp=aug_vec;\r
+                   }\r
+               } else {\r
+                   int filterno, position;\r
+   \r
+                   filterno=index[stage]/base_size;\r
+                   position=index[stage]-filterno*base_size;\r
+   \r
+                   \r
+                   if (position<(base_size-20)) {\r
+                       pp=cbvectors+filterno*lMem-lTarget-\r
+                           index[stage]+filterno*base_size;\r
+                   } else {\r
+                       createAugmentedVec(\r
+                           index[stage]-(filterno+1)*base_size+40,\r
+                           cbvectors+filterno*lMem,aug_vec);\r
+                       pp=aug_vec;\r
+   \r
+   \r
+                   }\r
+               }\r
+           }\r
+   \r
+           /* Subtract the best codebook vector, according \r
+              to measure, from the target vector */\r
+   \r
+           for (j=0;j<lTarget;j++) {\r
+               cvec[j] += gain*(*pp);\r
+               target[j] -= gain*(*pp++);\r
+           }\r
+   \r
+           /* record quantized gain */\r
+   \r
+           gains[stage]=gain;\r
+   \r
+       }/* end of Main Loop. for (stage=0;... */\r
+   \r
+       /* Gain adjustment for energy matching */\r
+       cene=0.0;\r
+       for (i=0; i<lTarget; i++) {\r
+           cene+=cvec[i]*cvec[i];\r
+       }\r
+       j=gain_index[0];\r
+   \r
+       for (i=gain_index[0]; i<32; i++) {\r
+           ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];\r
+           \r
+           if ((ftmp<(tene*gains[0]*gains[0])) && \r
+               (gain_sq5Tbl[j]<(2.0*gains[0]))) {\r
+               j=i;\r
+           }\r
+       }\r
+       gain_index[0]=j;\r
+   }\r
+   \r
+   \r
index 390e3f3879a838590e3b5bbeaefca386e09504ce..4d426befebeeb4a3b8fc3534c035f108afea689c 100644 (file)
@@ -1,35 +1,35 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iCBSearch.h        \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_ICBSEARCH_H\r
-#define __iLBC_ICBSEARCH_H\r
-\r
-void iCBSearch(\r
-    iLBC_Enc_Inst_t *iLBCenc_inst, \r
-                        /* (i) the encoder state structure */\r
-    int *index,         /* (o) Codebook indices */\r
-    int *gain_index,/* (o) Gain quantization indices */\r
-    float *intarget,/* (i) Target vector for encoding */    \r
-    float *mem,         /* (i) Buffer for codebook construction */\r
-    int lMem,           /* (i) Length of buffer */\r
-    int lTarget,    /* (i) Length of vector */\r
-    int nStages,    /* (i) Number of codebook stages */\r
-    float *weightDenum, /* (i) weighting filter coefficients */\r
-\r
-\r
-    float *weightState, /* (i) weighting filter state */\r
-    int block           /* (i) the sub-block number */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iCBSearch.h        \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ICBSEARCH_H\r
+   #define __iLBC_ICBSEARCH_H\r
+   \r
+   void iCBSearch(\r
+       iLBC_Enc_Inst_t *iLBCenc_inst, \r
+                           /* (i) the encoder state structure */\r
+       int *index,         /* (o) Codebook indices */\r
+       int *gain_index,/* (o) Gain quantization indices */\r
+       float *intarget,/* (i) Target vector for encoding */    \r
+       float *mem,         /* (i) Buffer for codebook construction */\r
+       int lMem,           /* (i) Length of buffer */\r
+       int lTarget,    /* (i) Length of vector */\r
+       int nStages,    /* (i) Number of codebook stages */\r
+       float *weightDenum, /* (i) weighting filter coefficients */\r
+   \r
+   \r
+       float *weightState, /* (i) weighting filter state */\r
+       int block           /* (i) the sub-block number */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index 460603af8fd33bdf9ddc522eb24e00c8db752efb..8955e24082dfb618ac3635dc0398d0f939f4f89d 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iLBC_decode.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <stdlib.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "iLBC_decode.h"\r
-#include "StateConstructW.h"\r
-#include "LPCdecode.h"\r
-#include "iCBConstruct.h"\r
-#include "doCPLC.h"\r
-#include "helpfun.h"\r
-#include "constants.h"\r
-#include "packing.h"\r
-#include "string.h"\r
-#include "enhancer.h"\r
-#include "hpOutput.h"\r
-#include "syntFilter.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  Initiation of decoder instance.\r
- *---------------------------------------------------------------*/\r
-\r
-short initDecode(                   /* (o) Number of decoded \r
-                                           samples */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
-    int mode,                       /* (i) frame size mode */\r
-    int use_enhancer                /* (i) 1 to use enhancer\r
-                                           0 to run without \r
-                                             enhancer */\r
-){\r
-    int i;\r
-\r
-    iLBCdec_inst->mode = mode;\r
-\r
-    if (mode==30) {\r
-        iLBCdec_inst->blockl = BLOCKL_30MS;\r
-        iLBCdec_inst->nsub = NSUB_30MS;\r
-        iLBCdec_inst->nasub = NASUB_30MS;\r
-        iLBCdec_inst->lpc_n = LPC_N_30MS;\r
-\r
-\r
-        iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
-        iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;\r
-        iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
-        /* ULP init */\r
-        iLBCdec_inst->ULP_inst=&ULP_30msTbl;\r
-    }\r
-    else if (mode==20) {\r
-        iLBCdec_inst->blockl = BLOCKL_20MS;\r
-        iLBCdec_inst->nsub = NSUB_20MS;\r
-        iLBCdec_inst->nasub = NASUB_20MS;\r
-        iLBCdec_inst->lpc_n = LPC_N_20MS;\r
-        iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
-        iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;\r
-        iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
-        /* ULP init */\r
-        iLBCdec_inst->ULP_inst=&ULP_20msTbl;\r
-    }\r
-    else {\r
-        exit(2);\r
-    }\r
-\r
-    memset(iLBCdec_inst->syntMem, 0, \r
-        LPC_FILTERORDER*sizeof(float));\r
-    memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, \r
-        LPC_FILTERORDER*sizeof(float));\r
-\r
-    memset(iLBCdec_inst->old_syntdenum, 0, \r
-        ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));\r
-    for (i=0; i<NSUB_MAX; i++)\r
-        iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;\r
-\r
-    iLBCdec_inst->last_lag = 20;\r
-\r
-    iLBCdec_inst->prevLag = 120;\r
-    iLBCdec_inst->per = 0.0;\r
-    iLBCdec_inst->consPLICount = 0;\r
-    iLBCdec_inst->prevPLI = 0;\r
-    iLBCdec_inst->prevLpc[0] = 1.0;\r
-    memset(iLBCdec_inst->prevLpc+1,0,\r
-        LPC_FILTERORDER*sizeof(float));\r
-    memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));\r
-    iLBCdec_inst->seed=777;\r
-\r
-    memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));\r
-\r
-    iLBCdec_inst->use_enhancer = use_enhancer;\r
-    memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));\r
-    for (i=0;i<ENH_NBLOCKS_TOT;i++) \r
-        iLBCdec_inst->enh_period[i]=(float)40.0;\r
-\r
-    iLBCdec_inst->prev_enh_pl = 0;\r
-\r
-    return (iLBCdec_inst->blockl);\r
-}\r
-\r
-\r
-\r
-/*----------------------------------------------------------------*\r
- *  frame residual decoder function (subrutine to iLBC_decode) \r
- *---------------------------------------------------------------*/\r
-\r
-static void Decode(\r
-    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
-                                             structure */\r
-    float *decresidual,             /* (o) decoded residual frame */\r
-    int start,                      /* (i) location of start \r
-                                           state */\r
-    int idxForMax,                  /* (i) codebook index for the \r
-                                           maximum value */\r
-    int *idxVec,                /* (i) codebook indexes for the \r
-                                           samples  in the start \r
-                                           state */\r
-    float *syntdenum,               /* (i) the decoded synthesis\r
-                                           filter coefficients */\r
-    int *cb_index,                  /* (i) the indexes for the \r
-                                           adaptive codebook */\r
-    int *gain_index,            /* (i) the indexes for the \r
-                                           corresponding gains */\r
-    int *extra_cb_index,        /* (i) the indexes for the \r
-                                           adaptive codebook part \r
-                                           of start state */\r
-    int *extra_gain_index,          /* (i) the indexes for the \r
-                                           corresponding gains */\r
-    int state_first                 /* (i) 1 if non adaptive part \r
-                                           of start state comes \r
-                                           first 0 if that part \r
-                                           comes last */\r
-){\r
-    float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
-    int k, meml_gotten, Nfor, Nback, i;\r
-    int diff, start_pos;\r
-    int subcount, subframe;\r
-\r
-    diff = STATE_LEN - iLBCdec_inst->state_short_len;\r
-    \r
-    if (state_first == 1) {\r
-        start_pos = (start-1)*SUBL;\r
-    } else {\r
-        start_pos = (start-1)*SUBL + diff;\r
-    }\r
-\r
-    /* decode scalar part of start state */\r
-\r
-    StateConstructW(idxForMax, idxVec, \r
-        &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
-        &decresidual[start_pos], iLBCdec_inst->state_short_len);\r
-\r
-    \r
-    if (state_first) { /* put adaptive part in the end */\r
-                \r
-\r
-\r
-        /* setup memory */\r
-\r
-        memset(mem, 0, \r
-            (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));\r
-        memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, \r
-            decresidual+start_pos, \r
-            iLBCdec_inst->state_short_len*sizeof(float));\r
-        \r
-        /* construct decoded vector */\r
-\r
-        iCBConstruct(\r
-            &decresidual[start_pos+iLBCdec_inst->state_short_len],\r
-            extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,\r
-            stMemLTbl, diff, CB_NSTAGES);\r
-    \r
-    } \r
-    else {/* put adaptive part in the beginning */\r
-        \r
-        /* create reversed vectors for prediction */\r
-\r
-        for (k=0; k<diff; k++) {\r
-            reverseDecresidual[k] = \r
-                decresidual[(start+1)*SUBL-1-\r
-                        (k+iLBCdec_inst->state_short_len)];\r
-        }\r
-        \r
-        /* setup memory */\r
-\r
-        meml_gotten = iLBCdec_inst->state_short_len;\r
-        for (k=0; k<meml_gotten; k++){ \r
-            mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
-        } \r
-        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
-        \r
-        /* construct decoded vector */\r
-\r
-        iCBConstruct(reverseDecresidual, extra_cb_index, \r
-            extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,\r
-            diff, CB_NSTAGES);\r
-        \r
-        /* get decoded residual from reversed vector */\r
-\r
-        for (k=0; k<diff; k++) {\r
-            decresidual[start_pos-1-k] = reverseDecresidual[k];\r
-        }\r
-    }\r
-\r
-    /* counter for predicted sub-frames */\r
-\r
-    subcount=0;\r
-\r
-    /* forward prediction of sub-frames */\r
-\r
-    Nfor = iLBCdec_inst->nsub-start-1;\r
-\r
-\r
-    \r
-    if ( Nfor > 0 ){\r
-        \r
-        /* setup memory */\r
-\r
-        memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
-        memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,\r
-            STATE_LEN*sizeof(float));\r
-\r
-        /* loop over sub-frames to encode */\r
-\r
-        for (subframe=0; subframe<Nfor; subframe++) {\r
-            \r
-            /* construct decoded vector */\r
-\r
-            iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
-                cb_index+subcount*CB_NSTAGES, \r
-                gain_index+subcount*CB_NSTAGES, \r
-                mem+CB_MEML-memLfTbl[subcount], \r
-                memLfTbl[subcount], SUBL, CB_NSTAGES);\r
-\r
-            /* update memory */\r
-\r
-            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
-            memcpy(mem+CB_MEML-SUBL, \r
-                &decresidual[(start+1+subframe)*SUBL],\r
-                SUBL*sizeof(float));\r
-\r
-            subcount++;\r
-\r
-        }\r
-\r
-    }\r
-    \r
-    /* backward prediction of sub-frames */\r
-\r
-    Nback = start-1;\r
-\r
-    if ( Nback > 0 ) {\r
-\r
-        /* setup memory */\r
-\r
-        meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);\r
-        \r
-        if ( meml_gotten > CB_MEML ) { \r
-            meml_gotten=CB_MEML;\r
-        }\r
-        for (k=0; k<meml_gotten; k++) { \r
-            mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
-        }\r
-        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
-\r
-        /* loop over subframes to decode */\r
-\r
-\r
-\r
-        for (subframe=0; subframe<Nback; subframe++) {\r
-            \r
-            /* construct decoded vector */\r
-\r
-            iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
-                cb_index+subcount*CB_NSTAGES, \r
-                gain_index+subcount*CB_NSTAGES, \r
-                mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount], \r
-                SUBL, CB_NSTAGES);\r
-\r
-            /* update memory */\r
-\r
-            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
-            memcpy(mem+CB_MEML-SUBL, \r
-                &reverseDecresidual[subframe*SUBL],\r
-                SUBL*sizeof(float));\r
-\r
-            subcount++;\r
-        }\r
-\r
-        /* get decoded residual from reversed vector */\r
-\r
-        for (i=0; i<SUBL*Nback; i++)\r
-            decresidual[SUBL*Nback - i - 1] = \r
-            reverseDecresidual[i];\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  main decoder function \r
- *---------------------------------------------------------------*/\r
-\r
-void iLBC_decode( \r
-    float *decblock,            /* (o) decoded signal block */\r
-    unsigned char *bytes,           /* (i) encoded signal bits */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
-                                             structure */\r
-    int mode                    /* (i) 0: bad packet, PLC, \r
-                                           1: normal */\r
-){\r
-    float data[BLOCKL_MAX];\r
-    float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];\r
-    float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];\r
-    float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];\r
-    int k, i, start, idxForMax, pos, lastpart, ulp;\r
-    int lag, ilag;\r
-    float cc, maxcc;\r
-    int idxVec[STATE_LEN];\r
-    int check;\r
-    int gain_index[NASUB_MAX*CB_NSTAGES], \r
-        extra_gain_index[CB_NSTAGES];\r
-    int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];\r
-    int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
-    int state_first;\r
-\r
-\r
-    int last_bit;\r
-    unsigned char *pbytes;\r
-    float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
-    int order_plus_one;\r
-    float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
-    float decresidual[BLOCKL_MAX];\r
-    \r
-    if (mode>0) { /* the data are good */\r
-\r
-        /* decode data */\r
-        \r
-        pbytes=bytes;\r
-        pos=0;\r
-\r
-        /* Set everything to zero before decoding */\r
-\r
-        for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {\r
-            lsf_i[k]=0;\r
-        }\r
-        start=0;\r
-        state_first=0;\r
-        idxForMax=0;\r
-        for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
-            idxVec[k]=0;\r
-        }\r
-        for (k=0; k<CB_NSTAGES; k++) {\r
-            extra_cb_index[k]=0;\r
-        }\r
-        for (k=0; k<CB_NSTAGES; k++) {\r
-            extra_gain_index[k]=0;\r
-        }\r
-        for (i=0; i<iLBCdec_inst->nasub; i++) {\r
-            for (k=0; k<CB_NSTAGES; k++) {\r
-                cb_index[i*CB_NSTAGES+k]=0;\r
-            }\r
-        }\r
-        for (i=0; i<iLBCdec_inst->nasub; i++) {\r
-            for (k=0; k<CB_NSTAGES; k++) {\r
-                gain_index[i*CB_NSTAGES+k]=0;\r
-            }\r
-        }\r
-\r
-        /* loop over ULP classes */\r
-\r
-        for (ulp=0; ulp<3; ulp++) {\r
-        \r
-            /* LSF */\r
-            for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){\r
-                unpack( &pbytes, &lastpart, \r
-                    iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
-                packcombine(&lsf_i[k], lastpart,\r
-                    iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);\r
-            }\r
-\r
-\r
-\r
-            /* Start block info */\r
-\r
-            unpack( &pbytes, &lastpart, \r
-                iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);\r
-            packcombine(&start, lastpart, \r
-                iLBCdec_inst->ULP_inst->start_bits[ulp]);\r
-\r
-            unpack( &pbytes, &lastpart, \r
-                iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
-            packcombine(&state_first, lastpart,\r
-                iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);\r
-\r
-            unpack( &pbytes, &lastpart, \r
-                iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);\r
-            packcombine(&idxForMax, lastpart, \r
-                iLBCdec_inst->ULP_inst->scale_bits[ulp]);\r
-\r
-            for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
-                unpack( &pbytes, &lastpart, \r
-                    iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);\r
-                packcombine(idxVec+k, lastpart,\r
-                    iLBCdec_inst->ULP_inst->state_bits[ulp]);\r
-            }\r
-\r
-            /* 23/22 (20ms/30ms) sample block */\r
-\r
-            for (k=0; k<CB_NSTAGES; k++) {\r
-                unpack( &pbytes, &lastpart, \r
-                    iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp], \r
-                    &pos);\r
-                packcombine(extra_cb_index+k, lastpart, \r
-                    iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);\r
-            }\r
-            for (k=0; k<CB_NSTAGES; k++) {\r
-                unpack( &pbytes, &lastpart, \r
-                    iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp], \r
-                    &pos);\r
-                packcombine(extra_gain_index+k, lastpart,\r
-                    iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);\r
-            }\r
-                \r
-            /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
-\r
-            for (i=0; i<iLBCdec_inst->nasub; i++) {\r
-                for (k=0; k<CB_NSTAGES; k++) {\r
-                    unpack( &pbytes, &lastpart, \r
-                    iLBCdec_inst->ULP_inst->cb_index[i][k][ulp], \r
-                        &pos);\r
-                    packcombine(cb_index+i*CB_NSTAGES+k, lastpart, \r
-                    iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);\r
-                }\r
-            }\r
-            \r
-            for (i=0; i<iLBCdec_inst->nasub; i++) {\r
-\r
-\r
-                for (k=0; k<CB_NSTAGES; k++) {\r
-                    unpack( &pbytes, &lastpart, \r
-\r
-                    iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp], \r
-                        &pos);\r
-                    packcombine(gain_index+i*CB_NSTAGES+k, lastpart,\r
-                        iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);\r
-                }\r
-            }\r
-        }\r
-        /* Extract last bit. If it is 1 this indicates an \r
-           empty/lost frame */\r
-        unpack( &pbytes, &last_bit, 1, &pos);\r
-\r
-        /* Check for bit errors or empty/lost frames */\r
-        if (start<1)\r
-            mode = 0;\r
-        if (iLBCdec_inst->mode==20 && start>3)\r
-            mode = 0;\r
-        if (iLBCdec_inst->mode==30 && start>5)\r
-            mode = 0;\r
-        if (last_bit==1)\r
-            mode = 0;\r
-\r
-        if (mode==1) { /* No bit errors was detected, \r
-                          continue decoding */\r
-                \r
-            /* adjust index */\r
-            index_conv_dec(cb_index);\r
-\r
-            /* decode the lsf */\r
-\r
-            SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);\r
-            check=LSF_check(lsfdeq, LPC_FILTERORDER, \r
-                iLBCdec_inst->lpc_n);\r
-            DecoderInterpolateLSF(syntdenum, weightdenum, \r
-                lsfdeq, LPC_FILTERORDER, iLBCdec_inst);\r
-        \r
-            Decode(iLBCdec_inst, decresidual, start, idxForMax, \r
-                idxVec, syntdenum, cb_index, gain_index, \r
-                extra_cb_index, extra_gain_index, \r
-                state_first);\r
-\r
-            /* preparing the plc for a future loss! */\r
-\r
-            doThePLC(PLCresidual, PLClpc, 0, decresidual, \r
-                syntdenum + \r
-                (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),\r
-                (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
-\r
-        \r
-            memcpy(decresidual, PLCresidual, \r
-                iLBCdec_inst->blockl*sizeof(float));\r
-        }\r
-\r
-\r
-        \r
-    }\r
-    \r
-    if (mode == 0) {\r
-        /* the data is bad (either a PLC call\r
-         * was made or a severe bit error was detected)\r
-         */\r
-        \r
-        /* packet loss conceal */\r
-\r
-        memset(zeros, 0, BLOCKL_MAX*sizeof(float));\r
-        \r
-        one[0] = 1;\r
-        memset(one+1, 0, LPC_FILTERORDER*sizeof(float));\r
-        \r
-        start=0;\r
-        \r
-        doThePLC(PLCresidual, PLClpc, 1, zeros, one,\r
-            (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
-        memcpy(decresidual, PLCresidual, \r
-            iLBCdec_inst->blockl*sizeof(float));\r
-        \r
-        order_plus_one = LPC_FILTERORDER + 1;\r
-        for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
-            memcpy(syntdenum+(i*order_plus_one), PLClpc, \r
-                order_plus_one*sizeof(float));\r
-        }\r
-    }\r
-\r
-    if (iLBCdec_inst->use_enhancer == 1) {\r
-\r
-        /* post filtering */\r
-        \r
-        iLBCdec_inst->last_lag = \r
-            enhancerInterface(data, decresidual, iLBCdec_inst);\r
-\r
-        /* synthesis filtering */\r
-        \r
-        if (iLBCdec_inst->mode==20) {\r
-            /* Enhancer has 40 samples delay */\r
-            i=0;\r
-            syntFilter(data + i*SUBL, \r
-                iLBCdec_inst->old_syntdenum + \r
-                (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), \r
-                SUBL, iLBCdec_inst->syntMem);\r
-            for (i=1; i < iLBCdec_inst->nsub; i++) {\r
-                syntFilter(data + i*SUBL, \r
-                    syntdenum + (i-1)*(LPC_FILTERORDER+1), \r
-                    SUBL, iLBCdec_inst->syntMem);\r
-            }\r
-        } else if (iLBCdec_inst->mode==30) {\r
-            /* Enhancer has 80 samples delay */\r
-            for (i=0; i < 2; i++) {\r
-                syntFilter(data + i*SUBL, \r
-\r
-\r
-                    iLBCdec_inst->old_syntdenum + \r
-                    (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),\r
-                    SUBL, iLBCdec_inst->syntMem);\r
-            }\r
-            for (i=2; i < iLBCdec_inst->nsub; i++) {\r
-                syntFilter(data + i*SUBL, \r
-                    syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,\r
-                    iLBCdec_inst->syntMem);\r
-            }\r
-        }\r
-\r
-    } else {\r
-\r
-        /* Find last lag */\r
-        lag = 20;\r
-        maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
-            &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);\r
-        \r
-        for (ilag=21; ilag<120; ilag++) {\r
-            cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
-                &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], \r
-                ENH_BLOCKL);\r
-        \r
-            if (cc > maxcc) {\r
-                maxcc = cc;\r
-                lag = ilag;\r
-            }\r
-        }\r
-        iLBCdec_inst->last_lag = lag;\r
-\r
-        /* copy data and run synthesis filter */\r
-\r
-        memcpy(data, decresidual, \r
-            iLBCdec_inst->blockl*sizeof(float));\r
-        for (i=0; i < iLBCdec_inst->nsub; i++) {\r
-            syntFilter(data + i*SUBL, \r
-                syntdenum + i*(LPC_FILTERORDER+1), SUBL, \r
-                iLBCdec_inst->syntMem);\r
-        }\r
-    }\r
-\r
-    /* high pass filtering on output if desired, otherwise \r
-       copy to out */\r
-\r
-    hpOutput(data, iLBCdec_inst->blockl, \r
-                decblock,iLBCdec_inst->hpomem);\r
-\r
-    /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/\r
-\r
-    memcpy(iLBCdec_inst->old_syntdenum, syntdenum, \r
-\r
-        iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));\r
-\r
-    iLBCdec_inst->prev_enh_pl=0;\r
-\r
-\r
-\r
-    if (mode==0) { /* PLC was used */\r
-        iLBCdec_inst->prev_enh_pl=1;\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_decode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "StateConstructW.h"\r
+   #include "LPCdecode.h"\r
+   #include "iCBConstruct.h"\r
+   #include "doCPLC.h"\r
+   #include "helpfun.h"\r
+   #include "constants.h"\r
+   #include "packing.h"\r
+   #include "string.h"\r
+   #include "enhancer.h"\r
+   #include "hpOutput.h"\r
+   #include "syntFilter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Initiation of decoder instance.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   short initDecode(                   /* (o) Number of decoded \r
+                                              samples */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+       int mode,                       /* (i) frame size mode */\r
+       int use_enhancer                /* (i) 1 to use enhancer\r
+                                              0 to run without \r
+                                                enhancer */\r
+   ){\r
+       int i;\r
+   \r
+       iLBCdec_inst->mode = mode;\r
+   \r
+       if (mode==30) {\r
+           iLBCdec_inst->blockl = BLOCKL_30MS;\r
+           iLBCdec_inst->nsub = NSUB_30MS;\r
+           iLBCdec_inst->nasub = NASUB_30MS;\r
+           iLBCdec_inst->lpc_n = LPC_N_30MS;\r
+   \r
+   \r
+           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
+           iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;\r
+           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
+           /* ULP init */\r
+           iLBCdec_inst->ULP_inst=&ULP_30msTbl;\r
+       }\r
+       else if (mode==20) {\r
+           iLBCdec_inst->blockl = BLOCKL_20MS;\r
+           iLBCdec_inst->nsub = NSUB_20MS;\r
+           iLBCdec_inst->nasub = NASUB_20MS;\r
+           iLBCdec_inst->lpc_n = LPC_N_20MS;\r
+           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
+           iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;\r
+           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
+           /* ULP init */\r
+           iLBCdec_inst->ULP_inst=&ULP_20msTbl;\r
+       }\r
+       else {\r
+           exit(2);\r
+       }\r
+   \r
+       memset(iLBCdec_inst->syntMem, 0, \r
+           LPC_FILTERORDER*sizeof(float));\r
+       memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, \r
+           LPC_FILTERORDER*sizeof(float));\r
+   \r
+       memset(iLBCdec_inst->old_syntdenum, 0, \r
+           ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));\r
+       for (i=0; i<NSUB_MAX; i++)\r
+           iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;\r
+   \r
+       iLBCdec_inst->last_lag = 20;\r
+   \r
+       iLBCdec_inst->prevLag = 120;\r
+       iLBCdec_inst->per = 0.0;\r
+       iLBCdec_inst->consPLICount = 0;\r
+       iLBCdec_inst->prevPLI = 0;\r
+       iLBCdec_inst->prevLpc[0] = 1.0;\r
+       memset(iLBCdec_inst->prevLpc+1,0,\r
+           LPC_FILTERORDER*sizeof(float));\r
+       memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));\r
+       iLBCdec_inst->seed=777;\r
+   \r
+       memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));\r
+   \r
+       iLBCdec_inst->use_enhancer = use_enhancer;\r
+       memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));\r
+       for (i=0;i<ENH_NBLOCKS_TOT;i++) \r
+           iLBCdec_inst->enh_period[i]=(float)40.0;\r
+   \r
+       iLBCdec_inst->prev_enh_pl = 0;\r
+   \r
+       return (iLBCdec_inst->blockl);\r
+   }\r
+   \r
+   \r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  frame residual decoder function (subrutine to iLBC_decode) \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void Decode(\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                                structure */\r
+       float *decresidual,             /* (o) decoded residual frame */\r
+       int start,                      /* (i) location of start \r
+                                              state */\r
+       int idxForMax,                  /* (i) codebook index for the \r
+                                              maximum value */\r
+       int *idxVec,                /* (i) codebook indexes for the \r
+                                              samples  in the start \r
+                                              state */\r
+       float *syntdenum,               /* (i) the decoded synthesis\r
+                                              filter coefficients */\r
+       int *cb_index,                  /* (i) the indexes for the \r
+                                              adaptive codebook */\r
+       int *gain_index,            /* (i) the indexes for the \r
+                                              corresponding gains */\r
+       int *extra_cb_index,        /* (i) the indexes for the \r
+                                              adaptive codebook part \r
+                                              of start state */\r
+       int *extra_gain_index,          /* (i) the indexes for the \r
+                                              corresponding gains */\r
+       int state_first                 /* (i) 1 if non adaptive part \r
+                                              of start state comes \r
+                                              first 0 if that part \r
+                                              comes last */\r
+   ){\r
+       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
+       int k, meml_gotten, Nfor, Nback, i;\r
+       int diff, start_pos;\r
+       int subcount, subframe;\r
+   \r
+       diff = STATE_LEN - iLBCdec_inst->state_short_len;\r
+       \r
+       if (state_first == 1) {\r
+           start_pos = (start-1)*SUBL;\r
+       } else {\r
+           start_pos = (start-1)*SUBL + diff;\r
+       }\r
+   \r
+       /* decode scalar part of start state */\r
+   \r
+       StateConstructW(idxForMax, idxVec, \r
+           &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+           &decresidual[start_pos], iLBCdec_inst->state_short_len);\r
+   \r
+       \r
+       if (state_first) { /* put adaptive part in the end */\r
+                   \r
+   \r
+   \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, \r
+               (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));\r
+           memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, \r
+               decresidual+start_pos, \r
+               iLBCdec_inst->state_short_len*sizeof(float));\r
+           \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(\r
+               &decresidual[start_pos+iLBCdec_inst->state_short_len],\r
+               extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,\r
+               stMemLTbl, diff, CB_NSTAGES);\r
+       \r
+       } \r
+       else {/* put adaptive part in the beginning */\r
+           \r
+           /* create reversed vectors for prediction */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               reverseDecresidual[k] = \r
+                   decresidual[(start+1)*SUBL-1-\r
+                           (k+iLBCdec_inst->state_short_len)];\r
+           }\r
+           \r
+           /* setup memory */\r
+   \r
+           meml_gotten = iLBCdec_inst->state_short_len;\r
+           for (k=0; k<meml_gotten; k++){ \r
+               mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
+           } \r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+           \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(reverseDecresidual, extra_cb_index, \r
+               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,\r
+               diff, CB_NSTAGES);\r
+           \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               decresidual[start_pos-1-k] = reverseDecresidual[k];\r
+           }\r
+       }\r
+   \r
+       /* counter for predicted sub-frames */\r
+   \r
+       subcount=0;\r
+   \r
+       /* forward prediction of sub-frames */\r
+   \r
+       Nfor = iLBCdec_inst->nsub-start-1;\r
+   \r
+   \r
+       \r
+       if ( Nfor > 0 ){\r
+           \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
+           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,\r
+               STATE_LEN*sizeof(float));\r
+   \r
+           /* loop over sub-frames to encode */\r
+   \r
+           for (subframe=0; subframe<Nfor; subframe++) {\r
+               \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &decresidual[(start+1+subframe)*SUBL],\r
+                   SUBL*sizeof(float));\r
+   \r
+               subcount++;\r
+   \r
+           }\r
+   \r
+       }\r
+       \r
+       /* backward prediction of sub-frames */\r
+   \r
+       Nback = start-1;\r
+   \r
+       if ( Nback > 0 ) {\r
+   \r
+           /* setup memory */\r
+   \r
+           meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);\r
+           \r
+           if ( meml_gotten > CB_MEML ) { \r
+               meml_gotten=CB_MEML;\r
+           }\r
+           for (k=0; k<meml_gotten; k++) { \r
+               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
+           }\r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+   \r
+           /* loop over subframes to decode */\r
+   \r
+   \r
+   \r
+           for (subframe=0; subframe<Nback; subframe++) {\r
+               \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount], \r
+                   SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &reverseDecresidual[subframe*SUBL],\r
+                   SUBL*sizeof(float));\r
+   \r
+               subcount++;\r
+           }\r
+   \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (i=0; i<SUBL*Nback; i++)\r
+               decresidual[SUBL*Nback - i - 1] = \r
+               reverseDecresidual[i];\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  main decoder function \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iLBC_decode( \r
+       float *decblock,            /* (o) decoded signal block */\r
+       unsigned char *bytes,           /* (i) encoded signal bits */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                                structure */\r
+       int mode                    /* (i) 0: bad packet, PLC, \r
+                                              1: normal */\r
+   ){\r
+       float data[BLOCKL_MAX];\r
+       float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];\r
+       float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];\r
+       float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];\r
+       int k, i, start, idxForMax, pos, lastpart, ulp;\r
+       int lag, ilag;\r
+       float cc, maxcc;\r
+       int idxVec[STATE_LEN];\r
+       int check;\r
+       int gain_index[NASUB_MAX*CB_NSTAGES], \r
+           extra_gain_index[CB_NSTAGES];\r
+       int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];\r
+       int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
+       int state_first;\r
+   \r
+   \r
+       int last_bit;\r
+       unsigned char *pbytes;\r
+       float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
+       int order_plus_one;\r
+       float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+       float decresidual[BLOCKL_MAX];\r
+       \r
+       if (mode>0) { /* the data are good */\r
+   \r
+           /* decode data */\r
+           \r
+           pbytes=bytes;\r
+           pos=0;\r
+   \r
+           /* Set everything to zero before decoding */\r
+   \r
+           for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {\r
+               lsf_i[k]=0;\r
+           }\r
+           start=0;\r
+           state_first=0;\r
+           idxForMax=0;\r
+           for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
+               idxVec[k]=0;\r
+           }\r
+           for (k=0; k<CB_NSTAGES; k++) {\r
+               extra_cb_index[k]=0;\r
+           }\r
+           for (k=0; k<CB_NSTAGES; k++) {\r
+               extra_gain_index[k]=0;\r
+           }\r
+           for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   cb_index[i*CB_NSTAGES+k]=0;\r
+               }\r
+           }\r
+           for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   gain_index[i*CB_NSTAGES+k]=0;\r
+               }\r
+           }\r
+   \r
+           /* loop over ULP classes */\r
+   \r
+           for (ulp=0; ulp<3; ulp++) {\r
+           \r
+               /* LSF */\r
+               for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
+                   packcombine(&lsf_i[k], lastpart,\r
+                       iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);\r
+               }\r
+   \r
+   \r
+   \r
+               /* Start block info */\r
+   \r
+               unpack( &pbytes, &lastpart, \r
+                   iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);\r
+               packcombine(&start, lastpart, \r
+                   iLBCdec_inst->ULP_inst->start_bits[ulp]);\r
+   \r
+               unpack( &pbytes, &lastpart, \r
+                   iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
+               packcombine(&state_first, lastpart,\r
+                   iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);\r
+   \r
+               unpack( &pbytes, &lastpart, \r
+                   iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);\r
+               packcombine(&idxForMax, lastpart, \r
+                   iLBCdec_inst->ULP_inst->scale_bits[ulp]);\r
+   \r
+               for (k=0; k<iLBCdec_inst->state_short_len; k++) {\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);\r
+                   packcombine(idxVec+k, lastpart,\r
+                       iLBCdec_inst->ULP_inst->state_bits[ulp]);\r
+               }\r
+   \r
+               /* 23/22 (20ms/30ms) sample block */\r
+   \r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                       &pos);\r
+                   packcombine(extra_cb_index+k, lastpart, \r
+                       iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);\r
+               }\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                       &pos);\r
+                   packcombine(extra_gain_index+k, lastpart,\r
+                       iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);\r
+               }\r
+                   \r
+               /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
+   \r
+               for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+                   for (k=0; k<CB_NSTAGES; k++) {\r
+                       unpack( &pbytes, &lastpart, \r
+                       iLBCdec_inst->ULP_inst->cb_index[i][k][ulp], \r
+                           &pos);\r
+                       packcombine(cb_index+i*CB_NSTAGES+k, lastpart, \r
+                       iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);\r
+                   }\r
+               }\r
+               \r
+               for (i=0; i<iLBCdec_inst->nasub; i++) {\r
+   \r
+   \r
+                   for (k=0; k<CB_NSTAGES; k++) {\r
+                       unpack( &pbytes, &lastpart, \r
+   \r
+                       iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                           &pos);\r
+                       packcombine(gain_index+i*CB_NSTAGES+k, lastpart,\r
+                           iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);\r
+                   }\r
+               }\r
+           }\r
+           /* Extract last bit. If it is 1 this indicates an \r
+              empty/lost frame */\r
+           unpack( &pbytes, &last_bit, 1, &pos);\r
+   \r
+           /* Check for bit errors or empty/lost frames */\r
+           if (start<1)\r
+               mode = 0;\r
+           if (iLBCdec_inst->mode==20 && start>3)\r
+               mode = 0;\r
+           if (iLBCdec_inst->mode==30 && start>5)\r
+               mode = 0;\r
+           if (last_bit==1)\r
+               mode = 0;\r
+   \r
+           if (mode==1) { /* No bit errors was detected, \r
+                             continue decoding */\r
+                   \r
+               /* adjust index */\r
+               index_conv_dec(cb_index);\r
+   \r
+               /* decode the lsf */\r
+   \r
+               SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);\r
+               check=LSF_check(lsfdeq, LPC_FILTERORDER, \r
+                   iLBCdec_inst->lpc_n);\r
+               DecoderInterpolateLSF(syntdenum, weightdenum, \r
+                   lsfdeq, LPC_FILTERORDER, iLBCdec_inst);\r
+           \r
+               Decode(iLBCdec_inst, decresidual, start, idxForMax, \r
+                   idxVec, syntdenum, cb_index, gain_index, \r
+                   extra_cb_index, extra_gain_index, \r
+                   state_first);\r
+   \r
+               /* preparing the plc for a future loss! */\r
+   \r
+               doThePLC(PLCresidual, PLClpc, 0, decresidual, \r
+                   syntdenum + \r
+                   (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),\r
+                   (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
+   \r
+           \r
+               memcpy(decresidual, PLCresidual, \r
+                   iLBCdec_inst->blockl*sizeof(float));\r
+           }\r
+   \r
+   \r
+           \r
+       }\r
+       \r
+       if (mode == 0) {\r
+           /* the data is bad (either a PLC call\r
+            * was made or a severe bit error was detected)\r
+            */\r
+           \r
+           /* packet loss conceal */\r
+   \r
+           memset(zeros, 0, BLOCKL_MAX*sizeof(float));\r
+           \r
+           one[0] = 1;\r
+           memset(one+1, 0, LPC_FILTERORDER*sizeof(float));\r
+           \r
+           start=0;\r
+           \r
+           doThePLC(PLCresidual, PLClpc, 1, zeros, one,\r
+               (*iLBCdec_inst).last_lag, iLBCdec_inst);\r
+           memcpy(decresidual, PLCresidual, \r
+               iLBCdec_inst->blockl*sizeof(float));\r
+           \r
+           order_plus_one = LPC_FILTERORDER + 1;\r
+           for (i = 0; i < iLBCdec_inst->nsub; i++) {\r
+               memcpy(syntdenum+(i*order_plus_one), PLClpc, \r
+                   order_plus_one*sizeof(float));\r
+           }\r
+       }\r
+   \r
+       if (iLBCdec_inst->use_enhancer == 1) {\r
+   \r
+           /* post filtering */\r
+           \r
+           iLBCdec_inst->last_lag = \r
+               enhancerInterface(data, decresidual, iLBCdec_inst);\r
+   \r
+           /* synthesis filtering */\r
+           \r
+           if (iLBCdec_inst->mode==20) {\r
+               /* Enhancer has 40 samples delay */\r
+               i=0;\r
+               syntFilter(data + i*SUBL, \r
+                   iLBCdec_inst->old_syntdenum + \r
+                   (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), \r
+                   SUBL, iLBCdec_inst->syntMem);\r
+               for (i=1; i < iLBCdec_inst->nsub; i++) {\r
+                   syntFilter(data + i*SUBL, \r
+                       syntdenum + (i-1)*(LPC_FILTERORDER+1), \r
+                       SUBL, iLBCdec_inst->syntMem);\r
+               }\r
+           } else if (iLBCdec_inst->mode==30) {\r
+               /* Enhancer has 80 samples delay */\r
+               for (i=0; i < 2; i++) {\r
+                   syntFilter(data + i*SUBL, \r
+   \r
+   \r
+                       iLBCdec_inst->old_syntdenum + \r
+                       (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),\r
+                       SUBL, iLBCdec_inst->syntMem);\r
+               }\r
+               for (i=2; i < iLBCdec_inst->nsub; i++) {\r
+                   syntFilter(data + i*SUBL, \r
+                       syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,\r
+                       iLBCdec_inst->syntMem);\r
+               }\r
+           }\r
+   \r
+       } else {\r
+   \r
+           /* Find last lag */\r
+           lag = 20;\r
+           maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
+               &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);\r
+           \r
+           for (ilag=21; ilag<120; ilag++) {\r
+               cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], \r
+                   &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], \r
+                   ENH_BLOCKL);\r
+           \r
+               if (cc > maxcc) {\r
+                   maxcc = cc;\r
+                   lag = ilag;\r
+               }\r
+           }\r
+           iLBCdec_inst->last_lag = lag;\r
+   \r
+           /* copy data and run synthesis filter */\r
+   \r
+           memcpy(data, decresidual, \r
+               iLBCdec_inst->blockl*sizeof(float));\r
+           for (i=0; i < iLBCdec_inst->nsub; i++) {\r
+               syntFilter(data + i*SUBL, \r
+                   syntdenum + i*(LPC_FILTERORDER+1), SUBL, \r
+                   iLBCdec_inst->syntMem);\r
+           }\r
+       }\r
+   \r
+       /* high pass filtering on output if desired, otherwise \r
+          copy to out */\r
+   \r
+       hpOutput(data, iLBCdec_inst->blockl, \r
+                   decblock,iLBCdec_inst->hpomem);\r
+   \r
+       /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/\r
+   \r
+       memcpy(iLBCdec_inst->old_syntdenum, syntdenum, \r
+   \r
+           iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));\r
+   \r
+       iLBCdec_inst->prev_enh_pl=0;\r
+   \r
+   \r
+   \r
+       if (mode==0) { /* PLC was used */\r
+           iLBCdec_inst->prev_enh_pl=1;\r
+       }\r
+   }\r
+   \r
+   \r
index ae9c481041fce9903c234d7e3ac6bec4a48e7d5c..29f27fbb8b33254991537ba717cd35639fd31140 100644 (file)
@@ -1,40 +1,40 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iLBC_decode.h    \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_ILBCDECODE_H\r
-#define __iLBC_ILBCDECODE_H\r
-\r
-#include "iLBC_define.h"\r
-\r
-short initDecode(                   /* (o) Number of decoded \r
-                                           samples */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
-    int mode,                       /* (i) frame size mode */\r
-    int use_enhancer                /* (i) 1 to use enhancer\r
-                                           0 to run without \r
-                                             enhancer */\r
-);\r
-\r
-void iLBC_decode( \r
-    float *decblock,            /* (o) decoded signal block */\r
-    unsigned char *bytes,           /* (i) encoded signal bits */\r
-    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
-                                             structure */\r
-    int mode                    /* (i) 0: bad packet, PLC, \r
-                                           1: normal */\r
-);\r
-\r
-\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_decode.h    \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ILBCDECODE_H\r
+   #define __iLBC_ILBCDECODE_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   short initDecode(                   /* (o) Number of decoded \r
+                                              samples */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */\r
+       int mode,                       /* (i) frame size mode */\r
+       int use_enhancer                /* (i) 1 to use enhancer\r
+                                              0 to run without \r
+                                                enhancer */\r
+   );\r
+   \r
+   void iLBC_decode( \r
+       float *decblock,            /* (o) decoded signal block */\r
+       unsigned char *bytes,           /* (i) encoded signal bits */\r
+       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state \r
+                                                structure */\r
+       int mode                    /* (i) 0: bad packet, PLC, \r
+                                              1: normal */\r
+   );\r
+   \r
+   \r
+   \r
+   #endif\r
+   \r
+   \r
index 85ef7e6854c1210c08c512002cbf20c3a5374e99..2dd9278b411a7793b9fb262f5bda8ede20131f4e 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iLBC_define.h    \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-#include <string.h>\r
-\r
-#ifndef __iLBC_ILBCDEFINE_H\r
-#define __iLBC_ILBCDEFINE_H\r
-\r
-/* general codec settings */\r
-\r
-#define FS                      (float)8000.0\r
-#define BLOCKL_20MS             160\r
-#define BLOCKL_30MS             240\r
-#define BLOCKL_MAX              240\r
-#define NSUB_20MS               4\r
-#define NSUB_30MS               6\r
-#define NSUB_MAX            6\r
-#define NASUB_20MS              2\r
-#define NASUB_30MS              4\r
-#define NASUB_MAX               4\r
-#define SUBL                40\r
-#define STATE_LEN               80\r
-#define STATE_SHORT_LEN_30MS    58\r
-#define STATE_SHORT_LEN_20MS    57\r
-\r
-/* LPC settings */\r
-\r
-#define LPC_FILTERORDER         10\r
-#define LPC_CHIRP_SYNTDENUM     (float)0.9025\r
-#define LPC_CHIRP_WEIGHTDENUM   (float)0.4222\r
-#define LPC_LOOKBACK        60\r
-#define LPC_N_20MS              1\r
-#define LPC_N_30MS              2\r
-#define LPC_N_MAX               2\r
-#define LPC_ASYMDIFF        20\r
-#define LPC_BW                  (float)60.0\r
-#define LPC_WN                  (float)1.0001\r
-#define LSF_NSPLIT              3\r
-\r
-#define LSF_NUMBER_OF_STEPS     4\r
-#define LPC_HALFORDER           (LPC_FILTERORDER/2)\r
-\r
-/* cb settings */\r
-\r
-#define CB_NSTAGES              3\r
-#define CB_EXPAND               2\r
-#define CB_MEML                 147\r
-#define CB_FILTERLEN        2*4\r
-#define CB_HALFFILTERLEN    4\r
-#define CB_RESRANGE             34\r
-#define CB_MAXGAIN              (float)1.3 \r
-\r
-/* enhancer */\r
-\r
-#define ENH_BLOCKL              80  /* block length */\r
-#define ENH_BLOCKL_HALF         (ENH_BLOCKL/2)\r
-#define ENH_HL                  3   /* 2*ENH_HL+1 is number blocks\r
-                                       in said second sequence */\r
-#define ENH_SLOP            2   /* max difference estimated and\r
-                                       correct pitch period */\r
-#define ENH_PLOCSL              20  /* pitch-estimates and pitch-\r
-                                       locations buffer length */\r
-#define ENH_OVERHANG        2\r
-#define ENH_UPS0            4   /* upsampling rate */\r
-#define ENH_FL0                 3   /* 2*FLO+1 is the length of \r
-                                       each filter */\r
-#define ENH_VECTL               (ENH_BLOCKL+2*ENH_FL0)\r
-#define ENH_CORRDIM             (2*ENH_SLOP+1)\r
-#define ENH_NBLOCKS             (BLOCKL_MAX/ENH_BLOCKL)\r
-#define ENH_NBLOCKS_EXTRA       5\r
-#define ENH_NBLOCKS_TOT         8   /* ENH_NBLOCKS + \r
-                                       ENH_NBLOCKS_EXTRA */\r
-#define ENH_BUFL            (ENH_NBLOCKS_TOT)*ENH_BLOCKL\r
-#define ENH_ALPHA0              (float)0.05\r
-\r
-/* Down sampling */\r
-\r
-#define FILTERORDER_DS          7\r
-#define DELAY_DS            3\r
-#define FACTOR_DS               2\r
-\r
-/* bit stream defs */\r
-\r
-#define NO_OF_BYTES_20MS    38\r
-#define NO_OF_BYTES_30MS    50\r
-#define NO_OF_WORDS_20MS    19\r
-#define NO_OF_WORDS_30MS    25\r
-#define STATE_BITS              3\r
-#define BYTE_LEN            8\r
-#define ULP_CLASSES             3\r
-\r
-/* help parameters */\r
-\r
-\r
-#define FLOAT_MAX               (float)1.0e37\r
-#define EPS                     (float)2.220446049250313e-016\r
-#define PI                      (float)3.14159265358979323846\r
-#define MIN_SAMPLE              -32768\r
-#define MAX_SAMPLE              32767\r
-#define TWO_PI                  (float)6.283185307\r
-#define PI2                     (float)0.159154943\r
-\r
-/* type definition encoder instance */\r
-typedef struct iLBC_ULP_Inst_t_ {\r
-    int lsf_bits[6][ULP_CLASSES+2];\r
-    int start_bits[ULP_CLASSES+2];\r
-    int startfirst_bits[ULP_CLASSES+2];\r
-    int scale_bits[ULP_CLASSES+2];\r
-    int state_bits[ULP_CLASSES+2];\r
-    int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];\r
-    int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];\r
-    int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
-    int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
-} iLBC_ULP_Inst_t;\r
-\r
-/* type definition encoder instance */\r
-typedef struct iLBC_Enc_Inst_t_ {\r
-\r
-    /* flag for frame size mode */\r
-    int mode;\r
-\r
-    /* basic parameters for different frame sizes */\r
-    int blockl;\r
-    int nsub;\r
-    int nasub;\r
-    int no_of_bytes, no_of_words;\r
-    int lpc_n;\r
-    int state_short_len;\r
-    const iLBC_ULP_Inst_t *ULP_inst;\r
-\r
-    /* analysis filter state */\r
-    float anaMem[LPC_FILTERORDER];\r
-\r
-    /* old lsf parameters for interpolation */\r
-    float lsfold[LPC_FILTERORDER];\r
-    float lsfdeqold[LPC_FILTERORDER];\r
-\r
-    /* signal buffer for LP analysis */\r
-    float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];\r
-\r
-    /* state of input HP filter */\r
-    float hpimem[4];\r
-\r
-} iLBC_Enc_Inst_t;\r
-\r
-/* type definition decoder instance */\r
-typedef struct iLBC_Dec_Inst_t_ {\r
-\r
-\r
-    /* flag for frame size mode */\r
-    int mode;\r
-\r
-    /* basic parameters for different frame sizes */\r
-    int blockl;\r
-    int nsub;\r
-    int nasub;\r
-    int no_of_bytes, no_of_words;\r
-    int lpc_n;\r
-    int state_short_len;\r
-    const iLBC_ULP_Inst_t *ULP_inst;\r
-\r
-    /* synthesis filter state */\r
-    float syntMem[LPC_FILTERORDER];\r
-\r
-    /* old LSF for interpolation */\r
-    float lsfdeqold[LPC_FILTERORDER];\r
-\r
-    /* pitch lag estimated in enhancer and used in PLC */\r
-    int last_lag;\r
-\r
-    /* PLC state information */\r
-    int prevLag, consPLICount, prevPLI, prev_enh_pl;\r
-    float prevLpc[LPC_FILTERORDER+1];\r
-    float prevResidual[NSUB_MAX*SUBL];\r
-    float per;\r
-    unsigned long seed;\r
-\r
-    /* previous synthesis filter parameters */\r
-    float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
-\r
-    /* state of output HP filter */\r
-    float hpomem[4];\r
-\r
-    /* enhancer state information */\r
-    int use_enhancer;\r
-    float enh_buf[ENH_BUFL];\r
-    float enh_period[ENH_NBLOCKS_TOT];\r
-\r
-} iLBC_Dec_Inst_t;\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_define.h    \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   #include <string.h>\r
+   \r
+   #ifndef __iLBC_ILBCDEFINE_H\r
+   #define __iLBC_ILBCDEFINE_H\r
+   \r
+   /* general codec settings */\r
+   \r
+   #define FS                      (float)8000.0\r
+   #define BLOCKL_20MS             160\r
+   #define BLOCKL_30MS             240\r
+   #define BLOCKL_MAX              240\r
+   #define NSUB_20MS               4\r
+   #define NSUB_30MS               6\r
+   #define NSUB_MAX            6\r
+   #define NASUB_20MS              2\r
+   #define NASUB_30MS              4\r
+   #define NASUB_MAX               4\r
+   #define SUBL                40\r
+   #define STATE_LEN               80\r
+   #define STATE_SHORT_LEN_30MS    58\r
+   #define STATE_SHORT_LEN_20MS    57\r
+   \r
+   /* LPC settings */\r
+   \r
+   #define LPC_FILTERORDER         10\r
+   #define LPC_CHIRP_SYNTDENUM     (float)0.9025\r
+   #define LPC_CHIRP_WEIGHTDENUM   (float)0.4222\r
+   #define LPC_LOOKBACK        60\r
+   #define LPC_N_20MS              1\r
+   #define LPC_N_30MS              2\r
+   #define LPC_N_MAX               2\r
+   #define LPC_ASYMDIFF        20\r
+   #define LPC_BW                  (float)60.0\r
+   #define LPC_WN                  (float)1.0001\r
+   #define LSF_NSPLIT              3\r
+   \r
+   \r
+   #define LSF_NUMBER_OF_STEPS     4\r
+   #define LPC_HALFORDER           (LPC_FILTERORDER/2)\r
+   \r
+   /* cb settings */\r
+   \r
+   #define CB_NSTAGES              3\r
+   #define CB_EXPAND               2\r
+   #define CB_MEML                 147\r
+   #define CB_FILTERLEN        2*4\r
+   #define CB_HALFFILTERLEN    4\r
+   #define CB_RESRANGE             34\r
+   #define CB_MAXGAIN              (float)1.3 \r
+   \r
+   /* enhancer */\r
+   \r
+   #define ENH_BLOCKL              80  /* block length */\r
+   #define ENH_BLOCKL_HALF         (ENH_BLOCKL/2)\r
+   #define ENH_HL                  3   /* 2*ENH_HL+1 is number blocks\r
+                                          in said second sequence */\r
+   #define ENH_SLOP            2   /* max difference estimated and\r
+                                          correct pitch period */\r
+   #define ENH_PLOCSL              20  /* pitch-estimates and pitch-\r
+                                          locations buffer length */\r
+   #define ENH_OVERHANG        2\r
+   #define ENH_UPS0            4   /* upsampling rate */\r
+   #define ENH_FL0                 3   /* 2*FLO+1 is the length of \r
+                                          each filter */\r
+   #define ENH_VECTL               (ENH_BLOCKL+2*ENH_FL0)\r
+   #define ENH_CORRDIM             (2*ENH_SLOP+1)\r
+   #define ENH_NBLOCKS             (BLOCKL_MAX/ENH_BLOCKL)\r
+   #define ENH_NBLOCKS_EXTRA       5\r
+   #define ENH_NBLOCKS_TOT         8   /* ENH_NBLOCKS + \r
+                                          ENH_NBLOCKS_EXTRA */\r
+   #define ENH_BUFL            (ENH_NBLOCKS_TOT)*ENH_BLOCKL\r
+   #define ENH_ALPHA0              (float)0.05\r
+   \r
+   /* Down sampling */\r
+   \r
+   #define FILTERORDER_DS          7\r
+   #define DELAY_DS            3\r
+   #define FACTOR_DS               2\r
+   \r
+   /* bit stream defs */\r
+   \r
+   #define NO_OF_BYTES_20MS    38\r
+   #define NO_OF_BYTES_30MS    50\r
+   #define NO_OF_WORDS_20MS    19\r
+   #define NO_OF_WORDS_30MS    25\r
+   #define STATE_BITS              3\r
+   #define BYTE_LEN            8\r
+   #define ULP_CLASSES             3\r
+   \r
+   /* help parameters */\r
+   \r
+   \r
+   \r
+   #define FLOAT_MAX               (float)1.0e37\r
+   #define EPS                     (float)2.220446049250313e-016\r
+   #define PI                      (float)3.14159265358979323846\r
+   #define MIN_SAMPLE              -32768\r
+   #define MAX_SAMPLE              32767\r
+   #define TWO_PI                  (float)6.283185307\r
+   #define PI2                     (float)0.159154943\r
+   \r
+   /* type definition encoder instance */\r
+   typedef struct iLBC_ULP_Inst_t_ {\r
+       int lsf_bits[6][ULP_CLASSES+2];\r
+       int start_bits[ULP_CLASSES+2];\r
+       int startfirst_bits[ULP_CLASSES+2];\r
+       int scale_bits[ULP_CLASSES+2];\r
+       int state_bits[ULP_CLASSES+2];\r
+       int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];\r
+       int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];\r
+       int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
+       int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];\r
+   } iLBC_ULP_Inst_t;\r
+   \r
+   /* type definition encoder instance */\r
+   typedef struct iLBC_Enc_Inst_t_ {\r
+   \r
+       /* flag for frame size mode */\r
+       int mode;\r
+   \r
+       /* basic parameters for different frame sizes */\r
+       int blockl;\r
+       int nsub;\r
+       int nasub;\r
+       int no_of_bytes, no_of_words;\r
+       int lpc_n;\r
+       int state_short_len;\r
+       const iLBC_ULP_Inst_t *ULP_inst;\r
+   \r
+       /* analysis filter state */\r
+       float anaMem[LPC_FILTERORDER];\r
+   \r
+       /* old lsf parameters for interpolation */\r
+       float lsfold[LPC_FILTERORDER];\r
+       float lsfdeqold[LPC_FILTERORDER];\r
+   \r
+       /* signal buffer for LP analysis */\r
+       float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];\r
+   \r
+       /* state of input HP filter */\r
+       float hpimem[4];\r
+   \r
+   } iLBC_Enc_Inst_t;\r
+   \r
+   /* type definition decoder instance */\r
+   typedef struct iLBC_Dec_Inst_t_ {\r
+   \r
+   \r
+   \r
+       /* flag for frame size mode */\r
+       int mode;\r
+   \r
+       /* basic parameters for different frame sizes */\r
+       int blockl;\r
+       int nsub;\r
+       int nasub;\r
+       int no_of_bytes, no_of_words;\r
+       int lpc_n;\r
+       int state_short_len;\r
+       const iLBC_ULP_Inst_t *ULP_inst;\r
+   \r
+       /* synthesis filter state */\r
+       float syntMem[LPC_FILTERORDER];\r
+   \r
+       /* old LSF for interpolation */\r
+       float lsfdeqold[LPC_FILTERORDER];\r
+   \r
+       /* pitch lag estimated in enhancer and used in PLC */\r
+       int last_lag;\r
+   \r
+       /* PLC state information */\r
+       int prevLag, consPLICount, prevPLI, prev_enh_pl;\r
+       float prevLpc[LPC_FILTERORDER+1];\r
+       float prevResidual[NSUB_MAX*SUBL];\r
+       float per;\r
+       unsigned long seed;\r
+   \r
+       /* previous synthesis filter parameters */\r
+       float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];\r
+   \r
+       /* state of output HP filter */\r
+       float hpomem[4];\r
+   \r
+       /* enhancer state information */\r
+       int use_enhancer;\r
+       float enh_buf[ENH_BUFL];\r
+       float enh_period[ENH_NBLOCKS_TOT];\r
+   \r
+   } iLBC_Dec_Inst_t;\r
+   \r
+   #endif\r
+   \r
+   \r
index e874242b3502bd0e345f869140e5ed93cecab909..5ed1e861be75452315b7469c3fb6a59eb9c80a0e 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iLBC_encode.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "iLBC_encode.h"\r
-#include "LPCencode.h"\r
-#include "FrameClassify.h"\r
-#include "StateSearchW.h"\r
-#include "StateConstructW.h"\r
-#include "helpfun.h"\r
-#include "constants.h"\r
-#include "packing.h"\r
-#include "iCBSearch.h"\r
-#include "iCBConstruct.h"\r
-#include "hpInput.h"\r
-#include "anaFilter.h"\r
-#include "syntFilter.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  Initiation of encoder instance.\r
- *---------------------------------------------------------------*/\r
-\r
-short initEncode(                   /* (o) Number of bytes \r
-                                           encoded */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
-    int mode                    /* (i) frame size mode */\r
-){\r
-    iLBCenc_inst->mode = mode;\r
-    if (mode==30) {\r
-        iLBCenc_inst->blockl = BLOCKL_30MS;\r
-        iLBCenc_inst->nsub = NSUB_30MS;\r
-\r
-\r
-        iLBCenc_inst->nasub = NASUB_30MS;\r
-        iLBCenc_inst->lpc_n = LPC_N_30MS;\r
-        iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
-        iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;\r
-        iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
-        /* ULP init */\r
-        iLBCenc_inst->ULP_inst=&ULP_30msTbl;\r
-    }\r
-    else if (mode==20) {\r
-        iLBCenc_inst->blockl = BLOCKL_20MS;\r
-        iLBCenc_inst->nsub = NSUB_20MS;\r
-        iLBCenc_inst->nasub = NASUB_20MS;\r
-        iLBCenc_inst->lpc_n = LPC_N_20MS;\r
-        iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
-        iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;\r
-        iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
-        /* ULP init */\r
-        iLBCenc_inst->ULP_inst=&ULP_20msTbl;\r
-    }\r
-    else {\r
-        exit(2);\r
-    }\r
-\r
-    memset((*iLBCenc_inst).anaMem, 0, \r
-        LPC_FILTERORDER*sizeof(float));\r
-    memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,\r
-        LPC_FILTERORDER*sizeof(float));\r
-    memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,\r
-        LPC_FILTERORDER*sizeof(float));\r
-    memset((*iLBCenc_inst).lpc_buffer, 0, \r
-        (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));\r
-    memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));\r
-\r
-    return (iLBCenc_inst->no_of_bytes);\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  main encoder function \r
- *---------------------------------------------------------------*/\r
-\r
-void iLBC_encode(\r
-    unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
-    float *block,                   /* (o) speech vector to \r
-                                           encode */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
-                                           state */\r
-){\r
-    \r
-    float data[BLOCKL_MAX];\r
-    float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];\r
-\r
-    int start, idxForMax, idxVec[STATE_LEN];\r
-    float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
-    int n, k, meml_gotten, Nfor, Nback, i, pos;\r
-\r
-\r
-    int gain_index[CB_NSTAGES*NASUB_MAX], \r
-        extra_gain_index[CB_NSTAGES];\r
-    int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];\r
-    int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
-    unsigned char *pbytes;\r
-    int diff, start_pos, state_first;\r
-    float en1, en2;\r
-    int index, ulp, firstpart;\r
-    int subcount, subframe;\r
-    float weightState[LPC_FILTERORDER];\r
-    float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
-    float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
-    float decresidual[BLOCKL_MAX];\r
-\r
-    /* high pass filtering of input signal if such is not done \r
-           prior to calling this function */\r
-\r
-    hpInput(block, iLBCenc_inst->blockl, \r
-                data, (*iLBCenc_inst).hpimem);\r
-\r
-    /* otherwise simply copy */\r
-\r
-    /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/\r
-        \r
-    /* LPC of hp filtered input data */\r
-\r
-    LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);\r
-\r
-\r
-    /* inverse filter to get residual */\r
-\r
-    for (n=0; n<iLBCenc_inst->nsub; n++) {\r
-        anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], \r
-            SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);\r
-    }\r
-\r
-    /* find state location */\r
-\r
-    start = FrameClassify(iLBCenc_inst, residual);\r
-    \r
-    /* check if state should be in first or last part of the \r
-    two subframes */\r
-\r
-    diff = STATE_LEN - iLBCenc_inst->state_short_len;\r
-    en1 = 0;\r
-    index = (start-1)*SUBL;\r
-    for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
-        en1 += residual[index+i]*residual[index+i];\r
-    }\r
-    en2 = 0;\r
-    index = (start-1)*SUBL+diff;\r
-    for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
-        en2 += residual[index+i]*residual[index+i];\r
-    }\r
-\r
-\r
-    \r
-    \r
-    if (en1 > en2) {\r
-        state_first = 1;\r
-        start_pos = (start-1)*SUBL;\r
-    } else {\r
-        state_first = 0;\r
-        start_pos = (start-1)*SUBL + diff;\r
-    }\r
-\r
-    /* scalar quantization of state */\r
-\r
-    StateSearchW(iLBCenc_inst, &residual[start_pos], \r
-        &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
-        &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, \r
-        idxVec, iLBCenc_inst->state_short_len, state_first);\r
-\r
-    StateConstructW(idxForMax, idxVec, \r
-        &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
-        &decresidual[start_pos], iLBCenc_inst->state_short_len);\r
-\r
-    /* predictive quantization in state */\r
-    \r
-    if (state_first) { /* put adaptive part in the end */\r
-        \r
-        /* setup memory */\r
-\r
-        memset(mem, 0, \r
-            (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));\r
-        memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, \r
-            decresidual+start_pos, \r
-            iLBCenc_inst->state_short_len*sizeof(float));\r
-        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
-\r
-        /* encode sub-frames */\r
-\r
-        iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
-            &residual[start_pos+iLBCenc_inst->state_short_len], \r
-            mem+CB_MEML-stMemLTbl,\r
-            stMemLTbl, diff, CB_NSTAGES, \r
-            &weightdenum[start*(LPC_FILTERORDER+1)], \r
-            weightState, 0);\r
-\r
-        /* construct decoded vector */\r
-\r
-        iCBConstruct(\r
-            &decresidual[start_pos+iLBCenc_inst->state_short_len],\r
-            extra_cb_index, extra_gain_index, \r
-            mem+CB_MEML-stMemLTbl, \r
-            stMemLTbl, diff, CB_NSTAGES);\r
-    \r
-    } \r
-    else { /* put adaptive part in the beginning */\r
-        \r
-\r
-\r
-        /* create reversed vectors for prediction */\r
-\r
-        for (k=0; k<diff; k++) {\r
-            reverseResidual[k] = residual[(start+1)*SUBL-1\r
-                -(k+iLBCenc_inst->state_short_len)];\r
-        }\r
-        \r
-        /* setup memory */\r
-\r
-        meml_gotten = iLBCenc_inst->state_short_len;\r
-        for (k=0; k<meml_gotten; k++) { \r
-            mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
-        } \r
-        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
-        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
-        \r
-        /* encode sub-frames */\r
-\r
-        iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
-            reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
-            diff, CB_NSTAGES, \r
-            &weightdenum[(start-1)*(LPC_FILTERORDER+1)], \r
-            weightState, 0);\r
-\r
-        /* construct decoded vector */\r
-\r
-        iCBConstruct(reverseDecresidual, extra_cb_index, \r
-            extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
-            diff, CB_NSTAGES);\r
-        \r
-        /* get decoded residual from reversed vector */\r
-\r
-        for (k=0; k<diff; k++) {\r
-            decresidual[start_pos-1-k] = reverseDecresidual[k];\r
-        }\r
-    }\r
-\r
-    /* counter for predicted sub-frames */\r
-\r
-    subcount=0;\r
-\r
-    /* forward prediction of sub-frames */\r
-\r
-    Nfor = iLBCenc_inst->nsub-start-1;\r
-\r
-    \r
-    if ( Nfor > 0 ) {\r
-        \r
-        /* setup memory */\r
-\r
-        memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
-        memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, \r
-            STATE_LEN*sizeof(float));\r
-        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
-\r
-\r
-\r
-        /* loop over sub-frames to encode */\r
-\r
-        for (subframe=0; subframe<Nfor; subframe++) {\r
-\r
-            /* encode sub-frame */\r
-\r
-            iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
-                gain_index+subcount*CB_NSTAGES, \r
-                &residual[(start+1+subframe)*SUBL], \r
-                mem+CB_MEML-memLfTbl[subcount], \r
-                memLfTbl[subcount], SUBL, CB_NSTAGES, \r
-                &weightdenum[(start+1+subframe)*\r
-                            (LPC_FILTERORDER+1)],\r
-                weightState, subcount+1);\r
-\r
-            /* construct decoded vector */\r
-\r
-            iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
-                cb_index+subcount*CB_NSTAGES, \r
-                gain_index+subcount*CB_NSTAGES, \r
-                mem+CB_MEML-memLfTbl[subcount], \r
-                memLfTbl[subcount], SUBL, CB_NSTAGES);\r
-\r
-            /* update memory */\r
-\r
-            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
-            memcpy(mem+CB_MEML-SUBL, \r
-                &decresidual[(start+1+subframe)*SUBL], \r
-                SUBL*sizeof(float));\r
-            memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
-\r
-            subcount++;\r
-        }\r
-    }\r
-    \r
-\r
-    /* backward prediction of sub-frames */\r
-\r
-    Nback = start-1;\r
-\r
-    \r
-    if ( Nback > 0 ) {\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_encode.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   #include <string.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "LPCencode.h"\r
+   #include "FrameClassify.h"\r
+   #include "StateSearchW.h"\r
+   #include "StateConstructW.h"\r
+   #include "helpfun.h"\r
+   #include "constants.h"\r
+   #include "packing.h"\r
+   #include "iCBSearch.h"\r
+   #include "iCBConstruct.h"\r
+   #include "hpInput.h"\r
+   #include "anaFilter.h"\r
+   #include "syntFilter.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  Initiation of encoder instance.\r
+    *---------------------------------------------------------------*/\r
+   \r
+   short initEncode(                   /* (o) Number of bytes \r
+                                              encoded */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
+       int mode                    /* (i) frame size mode */\r
+   ){\r
+       iLBCenc_inst->mode = mode;\r
+       if (mode==30) {\r
+           iLBCenc_inst->blockl = BLOCKL_30MS;\r
+           iLBCenc_inst->nsub = NSUB_30MS;\r
+   \r
+   \r
+           iLBCenc_inst->nasub = NASUB_30MS;\r
+           iLBCenc_inst->lpc_n = LPC_N_30MS;\r
+           iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;\r
+           iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;\r
+           iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;\r
+           /* ULP init */\r
+           iLBCenc_inst->ULP_inst=&ULP_30msTbl;\r
+       }\r
+       else if (mode==20) {\r
+           iLBCenc_inst->blockl = BLOCKL_20MS;\r
+           iLBCenc_inst->nsub = NSUB_20MS;\r
+           iLBCenc_inst->nasub = NASUB_20MS;\r
+           iLBCenc_inst->lpc_n = LPC_N_20MS;\r
+           iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;\r
+           iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;\r
+           iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;\r
+           /* ULP init */\r
+           iLBCenc_inst->ULP_inst=&ULP_20msTbl;\r
+       }\r
+       else {\r
+           exit(2);\r
+       }\r
+   \r
+       memset((*iLBCenc_inst).anaMem, 0, \r
+           LPC_FILTERORDER*sizeof(float));\r
+       memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,\r
+           LPC_FILTERORDER*sizeof(float));\r
+       memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,\r
+           LPC_FILTERORDER*sizeof(float));\r
+       memset((*iLBCenc_inst).lpc_buffer, 0, \r
+           (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));\r
+       memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));\r
+   \r
+       return (iLBCenc_inst->no_of_bytes);\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  main encoder function \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void iLBC_encode(\r
+       unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
+       float *block,                   /* (o) speech vector to \r
+                                              encode */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
+                                              state */\r
+   ){\r
+       \r
+       float data[BLOCKL_MAX];\r
+       float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];\r
+   \r
+       int start, idxForMax, idxVec[STATE_LEN];\r
+       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];\r
+       int n, k, meml_gotten, Nfor, Nback, i, pos;\r
+   \r
+   \r
+       int gain_index[CB_NSTAGES*NASUB_MAX], \r
+           extra_gain_index[CB_NSTAGES];\r
+       int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];\r
+       int lsf_i[LSF_NSPLIT*LPC_N_MAX];\r
+       unsigned char *pbytes;\r
+       int diff, start_pos, state_first;\r
+       float en1, en2;\r
+       int index, ulp, firstpart;\r
+       int subcount, subframe;\r
+       float weightState[LPC_FILTERORDER];\r
+       float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+       float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; \r
+       float decresidual[BLOCKL_MAX];\r
+   \r
+       /* high pass filtering of input signal if such is not done \r
+              prior to calling this function */\r
+   \r
+       hpInput(block, iLBCenc_inst->blockl, \r
+                   data, (*iLBCenc_inst).hpimem);\r
+   \r
+       /* otherwise simply copy */\r
+   \r
+       /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/\r
+           \r
+       /* LPC of hp filtered input data */\r
+   \r
+       LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);\r
+   \r
+   \r
+       /* inverse filter to get residual */\r
+   \r
+       for (n=0; n<iLBCenc_inst->nsub; n++) {\r
+           anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], \r
+               SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);\r
+       }\r
+   \r
+       /* find state location */\r
+   \r
+       start = FrameClassify(iLBCenc_inst, residual);\r
+       \r
+       /* check if state should be in first or last part of the \r
+       two subframes */\r
+   \r
+       diff = STATE_LEN - iLBCenc_inst->state_short_len;\r
+       en1 = 0;\r
+       index = (start-1)*SUBL;\r
+       for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
+           en1 += residual[index+i]*residual[index+i];\r
+       }\r
+       en2 = 0;\r
+       index = (start-1)*SUBL+diff;\r
+       for (i = 0; i < iLBCenc_inst->state_short_len; i++) {\r
+           en2 += residual[index+i]*residual[index+i];\r
+       }\r
+   \r
+   \r
+       \r
+       \r
+       if (en1 > en2) {\r
+           state_first = 1;\r
+           start_pos = (start-1)*SUBL;\r
+       } else {\r
+           state_first = 0;\r
+           start_pos = (start-1)*SUBL + diff;\r
+       }\r
+   \r
+       /* scalar quantization of state */\r
+   \r
+       StateSearchW(iLBCenc_inst, &residual[start_pos], \r
+           &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+           &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, \r
+           idxVec, iLBCenc_inst->state_short_len, state_first);\r
+   \r
+       StateConstructW(idxForMax, idxVec, \r
+           &syntdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+           &decresidual[start_pos], iLBCenc_inst->state_short_len);\r
+   \r
+       /* predictive quantization in state */\r
+       \r
+       if (state_first) { /* put adaptive part in the end */\r
+           \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, \r
+               (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));\r
+           memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, \r
+               decresidual+start_pos, \r
+               iLBCenc_inst->state_short_len*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+           /* encode sub-frames */\r
+   \r
+           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
+               &residual[start_pos+iLBCenc_inst->state_short_len], \r
+               mem+CB_MEML-stMemLTbl,\r
+               stMemLTbl, diff, CB_NSTAGES, \r
+               &weightdenum[start*(LPC_FILTERORDER+1)], \r
+               weightState, 0);\r
+   \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(\r
+               &decresidual[start_pos+iLBCenc_inst->state_short_len],\r
+               extra_cb_index, extra_gain_index, \r
+               mem+CB_MEML-stMemLTbl, \r
+               stMemLTbl, diff, CB_NSTAGES);\r
+       \r
+       } \r
+       else { /* put adaptive part in the beginning */\r
+           \r
+   \r
+   \r
+           /* create reversed vectors for prediction */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               reverseResidual[k] = residual[(start+1)*SUBL-1\r
+                   -(k+iLBCenc_inst->state_short_len)];\r
+           }\r
+           \r
+           /* setup memory */\r
+   \r
+           meml_gotten = iLBCenc_inst->state_short_len;\r
+           for (k=0; k<meml_gotten; k++) { \r
+               mem[CB_MEML-1-k] = decresidual[start_pos + k];\r
+           } \r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+           \r
+           /* encode sub-frames */\r
+   \r
+           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, \r
+               reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
+               diff, CB_NSTAGES, \r
+               &weightdenum[(start-1)*(LPC_FILTERORDER+1)], \r
+               weightState, 0);\r
+   \r
+           /* construct decoded vector */\r
+   \r
+           iCBConstruct(reverseDecresidual, extra_cb_index, \r
+               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, \r
+               diff, CB_NSTAGES);\r
+           \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (k=0; k<diff; k++) {\r
+               decresidual[start_pos-1-k] = reverseDecresidual[k];\r
+           }\r
+       }\r
+   \r
+       /* counter for predicted sub-frames */\r
+   \r
+       subcount=0;\r
+   \r
+       /* forward prediction of sub-frames */\r
+   \r
+       Nfor = iLBCenc_inst->nsub-start-1;\r
+   \r
+       \r
+       if ( Nfor > 0 ) {\r
+           \r
+           /* setup memory */\r
+   \r
+           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));\r
+           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, \r
+               STATE_LEN*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+   \r
+   \r
+           /* loop over sub-frames to encode */\r
+   \r
+           for (subframe=0; subframe<Nfor; subframe++) {\r
+   \r
+               /* encode sub-frame */\r
+   \r
+               iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   &residual[(start+1+subframe)*SUBL], \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES, \r
+                   &weightdenum[(start+1+subframe)*\r
+                               (LPC_FILTERORDER+1)],\r
+                   weightState, subcount+1);\r
+   \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&decresidual[(start+1+subframe)*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &decresidual[(start+1+subframe)*SUBL], \r
+                   SUBL*sizeof(float));\r
+               memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+               subcount++;\r
+           }\r
+       }\r
+       \r
+   \r
+       /* backward prediction of sub-frames */\r
+   \r
+       Nback = start-1;\r
+   \r
+       \r
+       if ( Nback > 0 ) {\r
+                  \r
+           /* create reverse order vectors */\r
+   \r
+           for (n=0; n<Nback; n++) {\r
+               for (k=0; k<SUBL; k++) {\r
+                   reverseResidual[n*SUBL+k] = \r
+                       residual[(start-1)*SUBL-1-n*SUBL-k];\r
+                   reverseDecresidual[n*SUBL+k] = \r
+                       decresidual[(start-1)*SUBL-1-n*SUBL-k];\r
+               }\r
+           }\r
+   \r
+   \r
+   \r
+           /* setup memory */\r
+   \r
+           meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);\r
+   \r
+           \r
+           if ( meml_gotten > CB_MEML ) { \r
+               meml_gotten=CB_MEML;\r
+           }\r
+           for (k=0; k<meml_gotten; k++) { \r
+               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
+           } \r
+           memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
+           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+           /* loop over sub-frames to encode */\r
+   \r
+           for (subframe=0; subframe<Nback; subframe++) {\r
                \r
-        /* create reverse order vectors */\r
-\r
-        for (n=0; n<Nback; n++) {\r
-            for (k=0; k<SUBL; k++) {\r
-                reverseResidual[n*SUBL+k] = \r
-                    residual[(start-1)*SUBL-1-n*SUBL-k];\r
-                reverseDecresidual[n*SUBL+k] = \r
-                    decresidual[(start-1)*SUBL-1-n*SUBL-k];\r
-            }\r
-        }\r
-\r
-\r
-\r
-        /* setup memory */\r
-\r
-        meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);\r
-\r
-        \r
-        if ( meml_gotten > CB_MEML ) { \r
-            meml_gotten=CB_MEML;\r
-        }\r
-        for (k=0; k<meml_gotten; k++) { \r
-            mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];\r
-        } \r
-        memset(mem, 0, (CB_MEML-k)*sizeof(float));\r
-        memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
-\r
-        /* loop over sub-frames to encode */\r
-\r
-        for (subframe=0; subframe<Nback; subframe++) {\r
-            \r
-            /* encode sub-frame */\r
-\r
-            iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
-                gain_index+subcount*CB_NSTAGES, \r
-                &reverseResidual[subframe*SUBL], \r
-                mem+CB_MEML-memLfTbl[subcount], \r
-                memLfTbl[subcount], SUBL, CB_NSTAGES, \r
-                &weightdenum[(start-2-subframe)*\r
-                            (LPC_FILTERORDER+1)], \r
-                weightState, subcount+1);\r
-\r
-            /* construct decoded vector */\r
-\r
-            iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
-                cb_index+subcount*CB_NSTAGES, \r
-                gain_index+subcount*CB_NSTAGES, \r
-                mem+CB_MEML-memLfTbl[subcount], \r
-                memLfTbl[subcount], SUBL, CB_NSTAGES);\r
-\r
-            /* update memory */\r
-\r
-            memmove(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
-            memcpy(mem+CB_MEML-SUBL, \r
-                &reverseDecresidual[subframe*SUBL],\r
-                SUBL*sizeof(float));\r
-            memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
-\r
-            subcount++;\r
-\r
-        }\r
-\r
-        /* get decoded residual from reversed vector */\r
-\r
-        for (i=0; i<SUBL*Nback; i++) {\r
-            decresidual[SUBL*Nback - i - 1] = \r
-\r
-\r
-                reverseDecresidual[i];\r
-        }\r
-    }\r
-    /* end encoding part */\r
-\r
-    /* adjust index */\r
-    index_conv_enc(cb_index);\r
-\r
-    /* pack bytes */\r
-\r
-    pbytes=bytes;\r
-    pos=0;\r
-\r
-    /* loop over the 3 ULP classes */\r
-\r
-    for (ulp=0; ulp<3; ulp++) {\r
-    \r
-        /* LSF */\r
-        for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {\r
-            packsplit(&lsf_i[k], &firstpart, &lsf_i[k], \r
-                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], \r
-                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+\r
-                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+\r
-                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);\r
-            dopack( &pbytes, firstpart, \r
-                iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
-        }\r
-\r
-        /* Start block info */\r
-\r
-        packsplit(&start, &firstpart, &start, \r
-            iLBCenc_inst->ULP_inst->start_bits[ulp], \r
-            iLBCenc_inst->ULP_inst->start_bits[ulp]+\r
-            iLBCenc_inst->ULP_inst->start_bits[ulp+1]+\r
-            iLBCenc_inst->ULP_inst->start_bits[ulp+2]);\r
-        dopack( &pbytes, firstpart, \r
-            iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);\r
-\r
-        packsplit(&state_first, &firstpart, &state_first, \r
-            iLBCenc_inst->ULP_inst->startfirst_bits[ulp], \r
-            iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+\r
-            iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+\r
-            iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);\r
-        dopack( &pbytes, firstpart, \r
-            iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
-\r
-        packsplit(&idxForMax, &firstpart, &idxForMax, \r
-            iLBCenc_inst->ULP_inst->scale_bits[ulp], \r
-            iLBCenc_inst->ULP_inst->scale_bits[ulp]+\r
-            iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+\r
-            iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);\r
-        dopack( &pbytes, firstpart, \r
-            iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);\r
-\r
-\r
-\r
-        for (k=0; k<iLBCenc_inst->state_short_len; k++) {\r
-            packsplit(idxVec+k, &firstpart, idxVec+k, \r
-                iLBCenc_inst->ULP_inst->state_bits[ulp], \r
-                iLBCenc_inst->ULP_inst->state_bits[ulp]+\r
-                iLBCenc_inst->ULP_inst->state_bits[ulp+1]+\r
-                iLBCenc_inst->ULP_inst->state_bits[ulp+2]);\r
-            dopack( &pbytes, firstpart, \r
-                iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);\r
-        }\r
-\r
-        /* 23/22 (20ms/30ms) sample block */\r
-\r
-        for (k=0;k<CB_NSTAGES;k++) {\r
-            packsplit(extra_cb_index+k, &firstpart, \r
-                extra_cb_index+k, \r
-                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
-                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+\r
-                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+\r
-                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);\r
-            dopack( &pbytes, firstpart, \r
-                iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
-                &pos);\r
-        }\r
-\r
-        for (k=0;k<CB_NSTAGES;k++) {\r
-            packsplit(extra_gain_index+k, &firstpart, \r
-                extra_gain_index+k, \r
-                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
-                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+\r
-                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+\r
-                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);\r
-            dopack( &pbytes, firstpart, \r
-                iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
-                &pos);\r
-        }\r
-            \r
-        /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
-\r
-        for (i=0; i<iLBCenc_inst->nasub; i++) {\r
-            for (k=0; k<CB_NSTAGES; k++) {\r
-                packsplit(cb_index+i*CB_NSTAGES+k, &firstpart, \r
-                    cb_index+i*CB_NSTAGES+k, \r
-                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
-                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+\r
-                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+\r
-                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);\r
-                dopack( &pbytes, firstpart, \r
-                    iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
-                    &pos);\r
-            }\r
-        }\r
-        \r
-        for (i=0; i<iLBCenc_inst->nasub; i++) {\r
-            for (k=0; k<CB_NSTAGES; k++) {\r
-\r
-\r
-                packsplit(gain_index+i*CB_NSTAGES+k, &firstpart, \r
-                    gain_index+i*CB_NSTAGES+k, \r
-                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
-                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+\r
-                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+\r
-                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);\r
-                dopack( &pbytes, firstpart, \r
-                    iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
-                    &pos);\r
-            }\r
-        }\r
-    }\r
-\r
-    /* set the last bit to zero (otherwise the decoder \r
-       will treat it as a lost frame) */\r
-    dopack( &pbytes, 0, 1, &pos);\r
-}\r
-\r
+               /* encode sub-frame */\r
+   \r
+               iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   &reverseResidual[subframe*SUBL], \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES, \r
+                   &weightdenum[(start-2-subframe)*\r
+                               (LPC_FILTERORDER+1)], \r
+                   weightState, subcount+1);\r
+   \r
+               /* construct decoded vector */\r
+   \r
+               iCBConstruct(&reverseDecresidual[subframe*SUBL], \r
+                   cb_index+subcount*CB_NSTAGES, \r
+                   gain_index+subcount*CB_NSTAGES, \r
+                   mem+CB_MEML-memLfTbl[subcount], \r
+                   memLfTbl[subcount], SUBL, CB_NSTAGES);\r
+   \r
+               /* update memory */\r
+   \r
+               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));\r
+               memcpy(mem+CB_MEML-SUBL, \r
+                   &reverseDecresidual[subframe*SUBL],\r
+                   SUBL*sizeof(float));\r
+               memset(weightState, 0, LPC_FILTERORDER*sizeof(float));\r
+   \r
+               subcount++;\r
+   \r
+           }\r
+   \r
+           /* get decoded residual from reversed vector */\r
+   \r
+           for (i=0; i<SUBL*Nback; i++) {\r
+               decresidual[SUBL*Nback - i - 1] = \r
+   \r
+   \r
+                   reverseDecresidual[i];\r
+           }\r
+       }\r
+       /* end encoding part */\r
+   \r
+       /* adjust index */\r
+       index_conv_enc(cb_index);\r
+   \r
+       /* pack bytes */\r
+   \r
+       pbytes=bytes;\r
+       pos=0;\r
+   \r
+       /* loop over the 3 ULP classes */\r
+   \r
+       for (ulp=0; ulp<3; ulp++) {\r
+       \r
+           /* LSF */\r
+           for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {\r
+               packsplit(&lsf_i[k], &firstpart, &lsf_i[k], \r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], \r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+\r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);\r
+           }\r
+   \r
+           /* Start block info */\r
+   \r
+           packsplit(&start, &firstpart, &start, \r
+               iLBCenc_inst->ULP_inst->start_bits[ulp], \r
+               iLBCenc_inst->ULP_inst->start_bits[ulp]+\r
+               iLBCenc_inst->ULP_inst->start_bits[ulp+1]+\r
+               iLBCenc_inst->ULP_inst->start_bits[ulp+2]);\r
+           dopack( &pbytes, firstpart, \r
+               iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);\r
+   \r
+           packsplit(&state_first, &firstpart, &state_first, \r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp], \r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+\r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+\r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);\r
+           dopack( &pbytes, firstpart, \r
+               iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);\r
+   \r
+           packsplit(&idxForMax, &firstpart, &idxForMax, \r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp], \r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp]+\r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+\r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);\r
+           dopack( &pbytes, firstpart, \r
+               iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);\r
+   \r
+   \r
+   \r
+           for (k=0; k<iLBCenc_inst->state_short_len; k++) {\r
+               packsplit(idxVec+k, &firstpart, idxVec+k, \r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp], \r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp]+\r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);\r
+           }\r
+   \r
+           /* 23/22 (20ms/30ms) sample block */\r
+   \r
+           for (k=0;k<CB_NSTAGES;k++) {\r
+               packsplit(extra_cb_index+k, &firstpart, \r
+                   extra_cb_index+k, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], \r
+                   &pos);\r
+           }\r
+   \r
+           for (k=0;k<CB_NSTAGES;k++) {\r
+               packsplit(extra_gain_index+k, &firstpart, \r
+                   extra_gain_index+k, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+\r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);\r
+               dopack( &pbytes, firstpart, \r
+                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], \r
+                   &pos);\r
+           }\r
+               \r
+           /* The two/four (20ms/30ms) 40 sample sub-blocks */\r
+   \r
+           for (i=0; i<iLBCenc_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+                   packsplit(cb_index+i*CB_NSTAGES+k, &firstpart, \r
+                       cb_index+i*CB_NSTAGES+k, \r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+\r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+\r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);\r
+                   dopack( &pbytes, firstpart, \r
+                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], \r
+                       &pos);\r
+               }\r
+           }\r
+           \r
+           for (i=0; i<iLBCenc_inst->nasub; i++) {\r
+               for (k=0; k<CB_NSTAGES; k++) {\r
+   \r
+   \r
+                   packsplit(gain_index+i*CB_NSTAGES+k, &firstpart, \r
+                       gain_index+i*CB_NSTAGES+k, \r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+\r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+\r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);\r
+                   dopack( &pbytes, firstpart, \r
+                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], \r
+                       &pos);\r
+               }\r
+           }\r
+       }\r
+   \r
+       /* set the last bit to zero (otherwise the decoder \r
+          will treat it as a lost frame) */\r
+       dopack( &pbytes, 0, 1, &pos);\r
+   }\r
+   \r
 \r
 \r
index dc46790f0fb47a95a68526a29e6b49cd6c40a805..a219e0b0b2b49e94b4e9bbe4815a2c3e920b807f 100644 (file)
@@ -1,37 +1,37 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    iLBC_encode.h    \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_ILBCENCODE_H\r
-#define __iLBC_ILBCENCODE_H\r
-\r
-#include "iLBC_define.h"\r
-\r
-short initEncode(                   /* (o) Number of bytes \r
-                                           encoded */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
-    int mode                    /* (i) frame size mode */\r
-);\r
-\r
-void iLBC_encode(\r
-\r
-\r
-    unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
-    float *block,                   /* (o) speech vector to \r
-                                           encode */\r
-    iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
-                                           state */\r
-);\r
-\r
-#endif\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       iLBC_encode.h    \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_ILBCENCODE_H\r
+   #define __iLBC_ILBCENCODE_H\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   short initEncode(                   /* (o) Number of bytes \r
+                                              encoded */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */\r
+       int mode                    /* (i) frame size mode */\r
+   );\r
+   \r
+   void iLBC_encode(\r
+   \r
+   \r
+       unsigned char *bytes,           /* (o) encoded data bits iLBC */\r
+       float *block,                   /* (o) speech vector to \r
+                                              encode */\r
+       iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder \r
+                                              state */\r
+   );\r
+   \r
+   #endif\r
+   \r
 \r
 \r
index 1be19da26030effabf41ad9f65c99adf8c2c7d02..9739e338f6de21ea3c5b62efc06079eff114672c 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    lsf.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <string.h>\r
-#include <math.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "lsf.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  conversion from lpc coefficients to lsf coefficients \r
- *---------------------------------------------------------------*/\r
-\r
-void a2lsf( \r
-    float *freq,/* (o) lsf coefficients */\r
-    float *a    /* (i) lpc coefficients */\r
-){\r
-    float steps[LSF_NUMBER_OF_STEPS] = \r
-        {(float)0.00635, (float)0.003175, (float)0.0015875, \r
-        (float)0.00079375};\r
-    float step;\r
-    int step_idx;\r
-    int lsp_index;  \r
-    float p[LPC_HALFORDER];\r
-    float q[LPC_HALFORDER];\r
-    float p_pre[LPC_HALFORDER];\r
-\r
-\r
-    float q_pre[LPC_HALFORDER];\r
-    float old_p, old_q, *old;\r
-    float *pq_coef; \r
-    float omega, old_omega;\r
-    int i;\r
-    float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;\r
-\r
-    for (i=0; i<LPC_HALFORDER; i++) {\r
-        p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);\r
-        q[i] = a[LPC_FILTERORDER - i] - a[i + 1];\r
-    }\r
-    \r
-    p_pre[0] = (float)-1.0 - p[0];\r
-    p_pre[1] = - p_pre[0] - p[1];\r
-    p_pre[2] = - p_pre[1] - p[2];\r
-    p_pre[3] = - p_pre[2] - p[3];\r
-    p_pre[4] = - p_pre[3] - p[4];\r
-    p_pre[4] = p_pre[4] / 2;\r
-    \r
-    q_pre[0] = (float)1.0 - q[0];\r
-    q_pre[1] = q_pre[0] - q[1];\r
-    q_pre[2] = q_pre[1] - q[2];\r
-    q_pre[3] = q_pre[2] - q[3];\r
-    q_pre[4] = q_pre[3] - q[4];\r
-    q_pre[4] = q_pre[4] / 2;\r
-    \r
-    omega = 0.0;\r
-    old_omega = 0.0;\r
-\r
-    old_p = FLOAT_MAX;\r
-    old_q = FLOAT_MAX;\r
-    \r
-    /* Here we loop through lsp_index to find all the \r
-       LPC_FILTERORDER roots for omega. */  \r
-\r
-    for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {\r
-        \r
-        /* Depending on lsp_index being even or odd, we \r
-        alternatively solve the roots for the two LSP equations. */\r
-\r
-        \r
-        if ((lsp_index & 0x1) == 0) {\r
-            pq_coef = p_pre;\r
-            old = &old_p;\r
-        } else {\r
-            pq_coef = q_pre;\r
-            old = &old_q;\r
-        }\r
-        \r
-        /* Start with low resolution grid */\r
-\r
-        for (step_idx = 0, step = steps[step_idx]; \r
-            step_idx < LSF_NUMBER_OF_STEPS;){\r
-            \r
-\r
-\r
-            /*  cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) + \r
-            pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */\r
-\r
-            hlp = (float)cos(omega * TWO_PI);\r
-            hlp1 = (float)2.0 * hlp + pq_coef[0];\r
-            hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 + \r
-                pq_coef[1];\r
-            hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];\r
-            hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];\r
-            hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];\r
-            \r
-            \r
-            if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){\r
-                \r
-                if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){\r
-                    \r
-                    if (fabs(hlp5) >= fabs(*old)) {\r
-                        freq[lsp_index] = omega - step;\r
-                    } else {\r
-                        freq[lsp_index] = omega;\r
-                    }   \r
-                    \r
-                    \r
-                    if ((*old) >= 0.0){\r
-                        *old = (float)-1.0 * FLOAT_MAX;\r
-                    } else {\r
-                        *old = FLOAT_MAX;\r
-                    }\r
-\r
-                    omega = old_omega;\r
-                    step_idx = 0;\r
-                    \r
-                    step_idx = LSF_NUMBER_OF_STEPS;\r
-                } else {\r
-                    \r
-                    if (step_idx == 0) {\r
-                        old_omega = omega;\r
-                    }\r
-\r
-                    step_idx++;\r
-                    omega -= steps[step_idx];\r
-\r
-                    /* Go back one grid step */\r
-\r
-                    step = steps[step_idx];\r
-                }\r
-            } else {\r
-                \r
-            /* increment omega until they are of different sign, \r
-            and we know there is at least one root between omega \r
-            and old_omega */\r
-                *old = hlp5;\r
-                omega += step;\r
-            }\r
-\r
-\r
-        }\r
-    }\r
-\r
-    for (i = 0; i<LPC_FILTERORDER; i++) {\r
-        freq[i] = freq[i] * TWO_PI;\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  conversion from lsf coefficients to lpc coefficients \r
- *---------------------------------------------------------------*/\r
-\r
-void lsf2a( \r
-    float *a_coef,  /* (o) lpc coefficients */\r
-    float *freq     /* (i) lsf coefficients */\r
-){\r
-    int i, j;\r
-    float hlp;\r
-    float p[LPC_HALFORDER], q[LPC_HALFORDER];\r
-    float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],\r
-        a2[LPC_HALFORDER];\r
-    float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER], \r
-        b2[LPC_HALFORDER];\r
-\r
-    for (i=0; i<LPC_FILTERORDER; i++) {\r
-        freq[i] = freq[i] * PI2;\r
-    }\r
-\r
-    /* Check input for ill-conditioned cases.  This part is not \r
-    found in the TIA standard.  It involves the following 2 IF \r
-    blocks. If "freq" is judged ill-conditioned, then we first \r
-    modify freq[0] and freq[LPC_HALFORDER-1] (normally \r
-    LPC_HALFORDER = 10 for LPC applications), then we adjust \r
-    the other "freq" values slightly */\r
-\r
-    \r
-    if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){\r
-\r
-        \r
-        if (freq[0] <= 0.0) {\r
-            freq[0] = (float)0.022;\r
-        }\r
-\r
-        \r
-        if (freq[LPC_FILTERORDER - 1] >= 0.5) {\r
-            freq[LPC_FILTERORDER - 1] = (float)0.499;\r
-        }\r
-\r
-        hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / \r
-            (float) (LPC_FILTERORDER - 1);\r
-\r
-        for (i=1; i<LPC_FILTERORDER; i++) {\r
-            freq[i] = freq[i - 1] + hlp;\r
-        }\r
-\r
-\r
-    }\r
-    \r
-    memset(a1, 0, LPC_HALFORDER*sizeof(float));\r
-    memset(a2, 0, LPC_HALFORDER*sizeof(float));\r
-    memset(b1, 0, LPC_HALFORDER*sizeof(float));\r
-    memset(b2, 0, LPC_HALFORDER*sizeof(float));\r
-    memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));\r
-    memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));\r
-        \r
-    /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and \r
-    cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.  \r
-    Note that for this code p[i] specifies the coefficients \r
-    used in .Q_A(z) while q[i] specifies the coefficients used \r
-    in .P_A(z) */\r
-\r
-    for (i=0; i<LPC_HALFORDER; i++) {\r
-        p[i] = (float)cos(TWO_PI * freq[2 * i]);\r
-        q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);\r
-    }\r
-    \r
-    a[0] = 0.25;\r
-    b[0] = 0.25;\r
-    \r
-    for (i= 0; i<LPC_HALFORDER; i++) {\r
-        a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
-        b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
-        a2[i] = a1[i];\r
-        a1[i] = a[i];\r
-        b2[i] = b1[i];\r
-        b1[i] = b[i];\r
-    }\r
-    \r
-    for (j=0; j<LPC_FILTERORDER; j++) {\r
-        \r
-        if (j == 0) {\r
-            a[0] = 0.25;\r
-            b[0] = -0.25;\r
-        } else {\r
-            a[0] = b[0] = 0.0;\r
-        }\r
-        \r
-        for (i=0; i<LPC_HALFORDER; i++) {\r
-            a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
-            b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
-            a2[i] = a1[i];\r
-            a1[i] = a[i];\r
-            b2[i] = b1[i];\r
-            b1[i] = b[i];\r
-        }\r
-\r
-        a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);\r
-    }\r
-\r
-    a_coef[0] = 1.0;\r
-\r
-\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       lsf.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <string.h>\r
+   #include <math.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  conversion from lpc coefficients to lsf coefficients \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void a2lsf( \r
+       float *freq,/* (o) lsf coefficients */\r
+       float *a    /* (i) lpc coefficients */\r
+   ){\r
+       float steps[LSF_NUMBER_OF_STEPS] = \r
+           {(float)0.00635, (float)0.003175, (float)0.0015875, \r
+           (float)0.00079375};\r
+       float step;\r
+       int step_idx;\r
+       int lsp_index;  \r
+       float p[LPC_HALFORDER];\r
+       float q[LPC_HALFORDER];\r
+       float p_pre[LPC_HALFORDER];\r
+   \r
+   \r
+       float q_pre[LPC_HALFORDER];\r
+       float old_p, old_q, *old;\r
+       float *pq_coef; \r
+       float omega, old_omega;\r
+       int i;\r
+       float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;\r
+   \r
+       for (i=0; i<LPC_HALFORDER; i++) {\r
+           p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);\r
+           q[i] = a[LPC_FILTERORDER - i] - a[i + 1];\r
+       }\r
+       \r
+       p_pre[0] = (float)-1.0 - p[0];\r
+       p_pre[1] = - p_pre[0] - p[1];\r
+       p_pre[2] = - p_pre[1] - p[2];\r
+       p_pre[3] = - p_pre[2] - p[3];\r
+       p_pre[4] = - p_pre[3] - p[4];\r
+       p_pre[4] = p_pre[4] / 2;\r
+       \r
+       q_pre[0] = (float)1.0 - q[0];\r
+       q_pre[1] = q_pre[0] - q[1];\r
+       q_pre[2] = q_pre[1] - q[2];\r
+       q_pre[3] = q_pre[2] - q[3];\r
+       q_pre[4] = q_pre[3] - q[4];\r
+       q_pre[4] = q_pre[4] / 2;\r
+       \r
+       omega = 0.0;\r
+       old_omega = 0.0;\r
+   \r
+       old_p = FLOAT_MAX;\r
+       old_q = FLOAT_MAX;\r
+       \r
+       /* Here we loop through lsp_index to find all the \r
+          LPC_FILTERORDER roots for omega. */  \r
+   \r
+       for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {\r
+           \r
+           /* Depending on lsp_index being even or odd, we \r
+           alternatively solve the roots for the two LSP equations. */\r
+   \r
+           \r
+           if ((lsp_index & 0x1) == 0) {\r
+               pq_coef = p_pre;\r
+               old = &old_p;\r
+           } else {\r
+               pq_coef = q_pre;\r
+               old = &old_q;\r
+           }\r
+           \r
+           /* Start with low resolution grid */\r
+   \r
+           for (step_idx = 0, step = steps[step_idx]; \r
+               step_idx < LSF_NUMBER_OF_STEPS;){\r
+               \r
+   \r
+   \r
+               /*  cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) + \r
+               pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */\r
+   \r
+               hlp = (float)cos(omega * TWO_PI);\r
+               hlp1 = (float)2.0 * hlp + pq_coef[0];\r
+               hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 + \r
+                   pq_coef[1];\r
+               hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];\r
+               hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];\r
+               hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];\r
+               \r
+               \r
+               if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){\r
+                   \r
+                   if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){\r
+                       \r
+                       if (fabs(hlp5) >= fabs(*old)) {\r
+                           freq[lsp_index] = omega - step;\r
+                       } else {\r
+                           freq[lsp_index] = omega;\r
+                       }   \r
+                       \r
+                       \r
+                       if ((*old) >= 0.0){\r
+                           *old = (float)-1.0 * FLOAT_MAX;\r
+                       } else {\r
+                           *old = FLOAT_MAX;\r
+                       }\r
+   \r
+                       omega = old_omega;\r
+                       step_idx = 0;\r
+                       \r
+                       step_idx = LSF_NUMBER_OF_STEPS;\r
+                   } else {\r
+                       \r
+                       if (step_idx == 0) {\r
+                           old_omega = omega;\r
+                       }\r
+   \r
+                       step_idx++;\r
+                       omega -= steps[step_idx];\r
+   \r
+                       /* Go back one grid step */\r
+   \r
+                       step = steps[step_idx];\r
+                   }\r
+               } else {\r
+                   \r
+               /* increment omega until they are of different sign, \r
+               and we know there is at least one root between omega \r
+               and old_omega */\r
+                   *old = hlp5;\r
+                   omega += step;\r
+               }\r
+   \r
+   \r
+           }\r
+       }\r
+   \r
+       for (i = 0; i<LPC_FILTERORDER; i++) {\r
+           freq[i] = freq[i] * TWO_PI;\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  conversion from lsf coefficients to lpc coefficients \r
+    *---------------------------------------------------------------*/\r
+   \r
+   void lsf2a( \r
+       float *a_coef,  /* (o) lpc coefficients */\r
+       float *freq     /* (i) lsf coefficients */\r
+   ){\r
+       int i, j;\r
+       float hlp;\r
+       float p[LPC_HALFORDER], q[LPC_HALFORDER];\r
+       float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],\r
+           a2[LPC_HALFORDER];\r
+       float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER], \r
+           b2[LPC_HALFORDER];\r
+   \r
+       for (i=0; i<LPC_FILTERORDER; i++) {\r
+           freq[i] = freq[i] * PI2;\r
+       }\r
+   \r
+       /* Check input for ill-conditioned cases.  This part is not \r
+       found in the TIA standard.  It involves the following 2 IF \r
+       blocks. If "freq" is judged ill-conditioned, then we first \r
+       modify freq[0] and freq[LPC_HALFORDER-1] (normally \r
+       LPC_HALFORDER = 10 for LPC applications), then we adjust \r
+       the other "freq" values slightly */\r
+   \r
+       \r
+       if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){\r
+   \r
+           \r
+           if (freq[0] <= 0.0) {\r
+               freq[0] = (float)0.022;\r
+           }\r
+   \r
+           \r
+           if (freq[LPC_FILTERORDER - 1] >= 0.5) {\r
+               freq[LPC_FILTERORDER - 1] = (float)0.499;\r
+           }\r
+   \r
+           hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / \r
+               (float) (LPC_FILTERORDER - 1);\r
+   \r
+           for (i=1; i<LPC_FILTERORDER; i++) {\r
+               freq[i] = freq[i - 1] + hlp;\r
+           }\r
+   \r
+   \r
+       }\r
+       \r
+       memset(a1, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(a2, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(b1, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(b2, 0, LPC_HALFORDER*sizeof(float));\r
+       memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));\r
+       memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));\r
+           \r
+       /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and \r
+       cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.  \r
+       Note that for this code p[i] specifies the coefficients \r
+       used in .Q_A(z) while q[i] specifies the coefficients used \r
+       in .P_A(z) */\r
+   \r
+       for (i=0; i<LPC_HALFORDER; i++) {\r
+           p[i] = (float)cos(TWO_PI * freq[2 * i]);\r
+           q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);\r
+       }\r
+       \r
+       a[0] = 0.25;\r
+       b[0] = 0.25;\r
+       \r
+       for (i= 0; i<LPC_HALFORDER; i++) {\r
+           a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
+           b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
+           a2[i] = a1[i];\r
+           a1[i] = a[i];\r
+           b2[i] = b1[i];\r
+           b1[i] = b[i];\r
+       }\r
+       \r
+       for (j=0; j<LPC_FILTERORDER; j++) {\r
+           \r
+           if (j == 0) {\r
+               a[0] = 0.25;\r
+               b[0] = -0.25;\r
+           } else {\r
+               a[0] = b[0] = 0.0;\r
+           }\r
+           \r
+           for (i=0; i<LPC_HALFORDER; i++) {\r
+               a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];\r
+               b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];\r
+               a2[i] = a1[i];\r
+               a1[i] = a[i];\r
+               b2[i] = b1[i];\r
+               b1[i] = b[i];\r
+           }\r
+   \r
+           a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);\r
+       }\r
+   \r
+       a_coef[0] = 1.0;\r
+   \r
+   \r
+   }\r
+   \r
+   \r
index 02f270a6b7b8e86f153c279ace9fd17b2a11343f..ec889ebc17559bb3a6f33f1dceec111a69f93cc1 100644 (file)
@@ -1,30 +1,30 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    lsf.h             \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_LSF_H\r
-#define __iLBC_LSF_H\r
-\r
-void a2lsf( \r
-    float *freq,/* (o) lsf coefficients */\r
-    float *a    /* (i) lpc coefficients */\r
-);\r
-\r
-void lsf2a( \r
-    float *a_coef,  /* (o) lpc coefficients */\r
-    float *freq     /* (i) lsf coefficients */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       lsf.h             \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   \r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_LSF_H\r
+   #define __iLBC_LSF_H\r
+   \r
+   void a2lsf( \r
+       float *freq,/* (o) lsf coefficients */\r
+       float *a    /* (i) lpc coefficients */\r
+   );\r
+   \r
+   void lsf2a( \r
+       float *a_coef,  /* (o) lpc coefficients */\r
+       float *freq     /* (i) lsf coefficients */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index c6e1980f3c9a90c076807cd713d71dae945925ee..47565614b3ba3279acf1f65ddda74473e867a5b3 100644 (file)
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    packing.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include <math.h>\r
-#include <stdlib.h>\r
-\r
-#include "iLBC_define.h"\r
-#include "constants.h"\r
-#include "helpfun.h"\r
-#include "packing.h"\r
-#include "string.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  splitting an integer into first most significant bits and \r
- *  remaining least significant bits\r
- *---------------------------------------------------------------*/\r
-\r
-void packsplit(\r
-    int *index,                 /* (i) the value to split */\r
-    int *firstpart,             /* (o) the value specified by most \r
-                                       significant bits */\r
-    int *rest,                  /* (o) the value specified by least\r
-                                       significant bits */\r
-    int bitno_firstpart,    /* (i) number of bits in most \r
-                                       significant part */\r
-    int bitno_total             /* (i) number of bits in full range\r
-                                       of value */\r
-){\r
-    int bitno_rest = bitno_total-bitno_firstpart;\r
-\r
-\r
-\r
-    *firstpart = *index>>(bitno_rest);\r
-    *rest = *index-(*firstpart<<(bitno_rest));\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  combining a value corresponding to msb's with a value \r
- *  corresponding to lsb's\r
- *---------------------------------------------------------------*/\r
-\r
-void packcombine( \r
-    int *index,                 /* (i/o) the msb value in the \r
-                                       combined value out */\r
-    int rest,                   /* (i) the lsb value */\r
-    int bitno_rest              /* (i) the number of bits in the \r
-                                       lsb part */\r
-){\r
-    *index = *index<<bitno_rest;\r
-    *index += rest;\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  packing of bits into bitstream, i.e., vector of bytes\r
- *---------------------------------------------------------------*/\r
-\r
-void dopack( \r
-    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
-                                       place in bitstream to pack \r
-                                       new data, on exit pointer \r
-                                       to place in bitstream to \r
-                                       pack future data */\r
-    int index,                  /* (i) the value to pack */\r
-    int bitno,                  /* (i) the number of bits that the \r
-                                       value will fit within */\r
-    int *pos                /* (i/o) write position in the \r
-                                       current byte */\r
-){\r
-    int posLeft;\r
-    \r
-    /* Clear the bits before starting in a new byte */\r
-    \r
-    if ((*pos)==0) {\r
-        **bitstream=0;\r
-    }\r
-\r
-    while (bitno>0) {\r
-        \r
-        /* Jump to the next byte if end of this byte is reached*/\r
-        \r
-        if (*pos==8) {\r
-            *pos=0;\r
-            (*bitstream)++;\r
-            **bitstream=0;\r
-        }\r
-\r
-\r
-\r
-        posLeft=8-(*pos);\r
-\r
-        /* Insert index into the bitstream */\r
-        \r
-        if (bitno <= posLeft) {\r
-            **bitstream |= (unsigned char)(index<<(posLeft-bitno));\r
-            *pos+=bitno;\r
-            bitno=0;\r
-        } else {\r
-            **bitstream |= (unsigned char)(index>>(bitno-posLeft));\r
-            \r
-            *pos=8;\r
-            index-=((index>>(bitno-posLeft))<<(bitno-posLeft));\r
-            \r
-            bitno-=posLeft;\r
-        }\r
-    }\r
-}\r
-\r
-/*----------------------------------------------------------------*\r
- *  unpacking of bits from bitstream, i.e., vector of bytes\r
- *---------------------------------------------------------------*/\r
-\r
-void unpack( \r
-    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
-                                       place in bitstream to \r
-                                       unpack new data from, on \r
-                                       exit pointer to place in \r
-                                       bitstream to unpack future \r
-                                       data from */\r
-    int *index,                 /* (o) resulting value */\r
-    int bitno,                  /* (i) number of bits used to \r
-                                       represent the value */\r
-    int *pos                /* (i/o) read position in the \r
-                                       current byte */\r
-){\r
-    int BitsLeft;\r
-\r
-    *index=0;\r
-\r
-    while (bitno>0) {\r
-        \r
-        /* move forward in bitstream when the end of the \r
-           byte is reached */\r
-        \r
-        if (*pos==8) {\r
-            *pos=0;\r
-            (*bitstream)++;\r
-        }\r
-\r
-        BitsLeft=8-(*pos);\r
-\r
-        /* Extract bits to index */\r
-        \r
-\r
-\r
-        if (BitsLeft>=bitno) {\r
-            *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));\r
-            \r
-            *pos+=bitno;\r
-            bitno=0;\r
-        } else {\r
-            \r
-            if ((8-bitno)>0) {\r
-                *index+=((((**bitstream)<<(*pos)) & 0xFF)>>\r
-                    (8-bitno));\r
-                *pos=8;\r
-            } else {\r
-                *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<\r
-                    (bitno-8));\r
-                *pos=8;\r
-            }\r
-            bitno-=BitsLeft;\r
-        }\r
-    }\r
-}\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       packing.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include <math.h>\r
+   #include <stdlib.h>\r
+   \r
+   #include "iLBC_define.h"\r
+   #include "constants.h"\r
+   #include "helpfun.h"\r
+   #include "string.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  splitting an integer into first most significant bits and \r
+    *  remaining least significant bits\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void packsplit(\r
+       int *index,                 /* (i) the value to split */\r
+       int *firstpart,             /* (o) the value specified by most \r
+                                          significant bits */\r
+       int *rest,                  /* (o) the value specified by least\r
+                                          significant bits */\r
+       int bitno_firstpart,    /* (i) number of bits in most \r
+                                          significant part */\r
+       int bitno_total             /* (i) number of bits in full range\r
+                                          of value */\r
+   ){\r
+       int bitno_rest = bitno_total-bitno_firstpart;\r
+   \r
+   \r
+   \r
+       *firstpart = *index>>(bitno_rest);\r
+       *rest = *index-(*firstpart<<(bitno_rest));\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  combining a value corresponding to msb's with a value \r
+    *  corresponding to lsb's\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void packcombine( \r
+       int *index,                 /* (i/o) the msb value in the \r
+                                          combined value out */\r
+       int rest,                   /* (i) the lsb value */\r
+       int bitno_rest              /* (i) the number of bits in the \r
+                                          lsb part */\r
+   ){\r
+       *index = *index<<bitno_rest;\r
+       *index += rest;\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  packing of bits into bitstream, i.e., vector of bytes\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void dopack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                          place in bitstream to pack \r
+                                          new data, on exit pointer \r
+                                          to place in bitstream to \r
+                                          pack future data */\r
+       int index,                  /* (i) the value to pack */\r
+       int bitno,                  /* (i) the number of bits that the \r
+                                          value will fit within */\r
+       int *pos                /* (i/o) write position in the \r
+                                          current byte */\r
+   ){\r
+       int posLeft;\r
+       \r
+       /* Clear the bits before starting in a new byte */\r
+       \r
+       if ((*pos)==0) {\r
+           **bitstream=0;\r
+       }\r
+   \r
+       while (bitno>0) {\r
+           \r
+           /* Jump to the next byte if end of this byte is reached*/\r
+           \r
+           if (*pos==8) {\r
+               *pos=0;\r
+               (*bitstream)++;\r
+               **bitstream=0;\r
+           }\r
+   \r
+   \r
+   \r
+           posLeft=8-(*pos);\r
+   \r
+           /* Insert index into the bitstream */\r
+           \r
+           if (bitno <= posLeft) {\r
+               **bitstream |= (unsigned char)(index<<(posLeft-bitno));\r
+               *pos+=bitno;\r
+               bitno=0;\r
+           } else {\r
+               **bitstream |= (unsigned char)(index>>(bitno-posLeft));\r
+               \r
+               *pos=8;\r
+               index-=((index>>(bitno-posLeft))<<(bitno-posLeft));\r
+               \r
+               bitno-=posLeft;\r
+           }\r
+       }\r
+   }\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  unpacking of bits from bitstream, i.e., vector of bytes\r
+    *---------------------------------------------------------------*/\r
+   \r
+   void unpack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                          place in bitstream to \r
+                                          unpack new data from, on \r
+                                          exit pointer to place in \r
+                                          bitstream to unpack future \r
+                                          data from */\r
+       int *index,                 /* (o) resulting value */\r
+       int bitno,                  /* (i) number of bits used to \r
+                                          represent the value */\r
+       int *pos                /* (i/o) read position in the \r
+                                          current byte */\r
+   ){\r
+       int BitsLeft;\r
+   \r
+       *index=0;\r
+   \r
+       while (bitno>0) {\r
+           \r
+           /* move forward in bitstream when the end of the \r
+              byte is reached */\r
+           \r
+           if (*pos==8) {\r
+               *pos=0;\r
+               (*bitstream)++;\r
+           }\r
+   \r
+           BitsLeft=8-(*pos);\r
+   \r
+           /* Extract bits to index */\r
+           \r
+   \r
+   \r
+           if (BitsLeft>=bitno) {\r
+               *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));\r
+               \r
+               *pos+=bitno;\r
+               bitno=0;\r
+           } else {\r
+               \r
+               if ((8-bitno)>0) {\r
+                   *index+=((((**bitstream)<<(*pos)) & 0xFF)>>\r
+                       (8-bitno));\r
+                   *pos=8;\r
+               } else {\r
+                   *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<\r
+                       (bitno-8));\r
+                   *pos=8;\r
+               }\r
+               bitno-=BitsLeft;\r
+           }\r
+       }\r
+   }\r
+   \r
+   \r
index 77db258440e132e56431ce33713f3a797b4b2d01..5e70b0cda1a3c05898bf92fe445e33280379d941 100644 (file)
@@ -1,67 +1,67 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    packing.h              \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __PACKING_H\r
-#define __PACKING_H\r
-\r
-void packsplit(\r
-    int *index,                 /* (i) the value to split */\r
-    int *firstpart,             /* (o) the value specified by most \r
-                                       significant bits */\r
-    int *rest,                  /* (o) the value specified by least \r
-                                       significant bits */\r
-    int bitno_firstpart,    /* (i) number of bits in most \r
-                                       significant part */\r
-    int bitno_total             /* (i) number of bits in full range \r
-                                       of value */\r
-);\r
-\r
-void packcombine( \r
-    int *index,                 /* (i/o) the msb value in the \r
-                                       combined value out */\r
-    int rest,                   /* (i) the lsb value */\r
-    int bitno_rest              /* (i) the number of bits in the \r
-                                       lsb part */\r
-);\r
-\r
-void dopack( \r
-    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
-                                       place in bitstream to pack \r
-                                       new data, on exit pointer \r
-                                       to place in bitstream to \r
-                                       pack future data */\r
-    int index,                  /* (i) the value to pack */\r
-    int bitno,                  /* (i) the number of bits that the \r
-                                       value will fit within */\r
-    int *pos                /* (i/o) write position in the \r
-                                       current byte */\r
-);\r
-\r
-void unpack( \r
-    unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
-\r
-\r
-                                       place in bitstream to \r
-                                       unpack new data from, on \r
-                                       exit pointer to place in \r
-                                       bitstream to unpack future \r
-                                       data from */\r
-    int *index,                 /* (o) resulting value */\r
-    int bitno,                  /* (i) number of bits used to \r
-                                       represent the value */\r
-    int *pos                /* (i/o) read position in the \r
-                                       current byte */\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       packing.h              \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __PACKING_H\r
+   #define __PACKING_H\r
+   \r
+   void packsplit(\r
+       int *index,                 /* (i) the value to split */\r
+       int *firstpart,             /* (o) the value specified by most \r
+                                          significant bits */\r
+       int *rest,                  /* (o) the value specified by least \r
+                                          significant bits */\r
+       int bitno_firstpart,    /* (i) number of bits in most \r
+                                          significant part */\r
+       int bitno_total             /* (i) number of bits in full range \r
+                                          of value */\r
+   );\r
+   \r
+   void packcombine( \r
+       int *index,                 /* (i/o) the msb value in the \r
+                                          combined value out */\r
+       int rest,                   /* (i) the lsb value */\r
+       int bitno_rest              /* (i) the number of bits in the \r
+                                          lsb part */\r
+   );\r
+   \r
+   void dopack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+                                          place in bitstream to pack \r
+                                          new data, on exit pointer \r
+                                          to place in bitstream to \r
+                                          pack future data */\r
+       int index,                  /* (i) the value to pack */\r
+       int bitno,                  /* (i) the number of bits that the \r
+                                          value will fit within */\r
+       int *pos                /* (i/o) write position in the \r
+                                          current byte */\r
+   );\r
+   \r
+   void unpack( \r
+       unsigned char **bitstream,  /* (i/o) on entrance pointer to \r
+   \r
+   \r
+                                          place in bitstream to \r
+                                          unpack new data from, on \r
+                                          exit pointer to place in \r
+                                          bitstream to unpack future \r
+                                          data from */\r
+       int *index,                 /* (o) resulting value */\r
+       int bitno,                  /* (i) number of bits used to \r
+                                          represent the value */\r
+       int *pos                /* (i/o) read position in the \r
+                                          current byte */\r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index ff2e714c7500f79ca37c78abdd7054e248dac011..31bb87a13423d1afbdc124ab0820441b07dd4e8c 100644 (file)
@@ -1,70 +1,68 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    syntFilter.c \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#include "iLBC_define.h"\r
-#include "syntFilter.h"\r
-\r
-/*----------------------------------------------------------------*\r
- *  LP synthesis filter.\r
- *---------------------------------------------------------------*/\r
-    \r
-void syntFilter(\r
-    float *Out,     /* (i/o) Signal to be filtered */\r
-    float *a,       /* (i) LP parameters */\r
-    int len,    /* (i) Length of signal */\r
-    float *mem      /* (i/o) Filter state */\r
-){\r
-    int i, j;\r
-    float *po, *pi, *pa, *pm;\r
-\r
-    po=Out;\r
-\r
-    /* Filter first part using memory from past */\r
-\r
-    for (i=0; i<LPC_FILTERORDER; i++) {\r
-        pi=&Out[i-1];\r
-        pa=&a[1];\r
-        pm=&mem[LPC_FILTERORDER-1];\r
-        for (j=1; j<=i; j++) {\r
-            *po-=(*pa++)*(*pi--);\r
-        }\r
-        for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
-            *po-=(*pa++)*(*pm--);\r
-        }\r
-        po++;\r
-    }\r
-\r
-    /* Filter last part where the state is entierly in \r
-       the output vector */\r
-    \r
-    for (i=LPC_FILTERORDER; i<len; i++) {\r
-\r
-\r
-        pi=&Out[i-1];\r
-        pa=&a[1];\r
-        for (j=1; j<LPC_FILTERORDER+1; j++) {\r
-            *po-=(*pa++)*(*pi--);\r
-        }\r
-        po++;\r
-    }\r
-\r
-    /* Update state vector */\r
-\r
-    memcpy(mem, &Out[len-LPC_FILTERORDER], \r
-        LPC_FILTERORDER*sizeof(float));\r
-}\r
-\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       syntFilter.c \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #include "iLBC_define.h"\r
+   \r
+   /*----------------------------------------------------------------*\r
+    *  LP synthesis filter.\r
+    *---------------------------------------------------------------*/\r
+       \r
+   void syntFilter(\r
+       float *Out,     /* (i/o) Signal to be filtered */\r
+       float *a,       /* (i) LP parameters */\r
+       int len,    /* (i) Length of signal */\r
+       float *mem      /* (i/o) Filter state */\r
+   ){\r
+       int i, j;\r
+       float *po, *pi, *pa, *pm;\r
+   \r
+       po=Out;\r
+   \r
+       /* Filter first part using memory from past */\r
+   \r
+       for (i=0; i<LPC_FILTERORDER; i++) {\r
+           pi=&Out[i-1];\r
+           pa=&a[1];\r
+           pm=&mem[LPC_FILTERORDER-1];\r
+           for (j=1; j<=i; j++) {\r
+               *po-=(*pa++)*(*pi--);\r
+           }\r
+           for (j=i+1; j<LPC_FILTERORDER+1; j++) {\r
+               *po-=(*pa++)*(*pm--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Filter last part where the state is entierly in \r
+          the output vector */\r
+       \r
+       for (i=LPC_FILTERORDER; i<len; i++) {\r
+   \r
+   \r
+           pi=&Out[i-1];\r
+           pa=&a[1];\r
+           for (j=1; j<LPC_FILTERORDER+1; j++) {\r
+               *po-=(*pa++)*(*pi--);\r
+           }\r
+           po++;\r
+       }\r
+   \r
+       /* Update state vector */\r
+   \r
+       memcpy(mem, &Out[len-LPC_FILTERORDER], \r
+           LPC_FILTERORDER*sizeof(float));\r
+   }\r
+   \r
+   \r
 \r
 \r
 \r
@@ -105,4 +103,5 @@ void syntFilter(
 \r
 \r
 \r
+   \r
 \r
index 9e1ad3f230fa30a2a1be8640b53dd533522336d7..62aa677299ed79b599f2d0931b112d52c5f4f039 100644 (file)
@@ -1,27 +1,27 @@
-\r
-/******************************************************************\r
-\r
-    iLBC Speech Coder ANSI-C Source Code\r
-\r
-    syntFilter.h               \r
-\r
-    Copyright (C) The Internet Society (2004). \r
-    All Rights Reserved.\r
-\r
-******************************************************************/\r
-\r
-#ifndef __iLBC_SYNTFILTER_H\r
-#define __iLBC_SYNTFILTER_H\r
-\r
-void syntFilter(\r
-    float *Out,     /* (i/o) Signal to be filtered */\r
-    float *a,       /* (i) LP parameters */\r
-    int len,    /* (i) Length of signal */\r
-    float *mem      /* (i/o) Filter state */\r
-\r
-\r
-);\r
-\r
-#endif\r
-\r
-\r
+   \r
+   /******************************************************************\r
+   \r
+       iLBC Speech Coder ANSI-C Source Code\r
+   \r
+       syntFilter.h               \r
+   \r
+       Copyright (C) The Internet Society (2004). \r
+       All Rights Reserved.\r
+   \r
+   ******************************************************************/\r
+   \r
+   #ifndef __iLBC_SYNTFILTER_H\r
+   #define __iLBC_SYNTFILTER_H\r
+   \r
+   void syntFilter(\r
+       float *Out,     /* (i/o) Signal to be filtered */\r
+       float *a,       /* (i) LP parameters */\r
+       int len,    /* (i) Length of signal */\r
+       float *mem      /* (i/o) Filter state */\r
+   \r
+   \r
+   );\r
+   \r
+   #endif\r
+   \r
+   \r
index ccb314156144f13cd8b3fee4c84fd77befb1bee3..6485f0bf74e016930e2f6217d51b9e1a66071490 100644 (file)
@@ -3,7 +3,7 @@
 # \r
 \r
 # default C compiler\r
-CC?= gcc\r
+CC= gcc\r
 \r
 # \r
 # These definitions for CFLAGS and LIB_TARGET_DIR are used when one\r
@@ -14,62 +14,57 @@ CC?= gcc
 # definitions.\r
 # \r
 \r
-LIB_TARGET_DIR = .\r
+LIB_TARGET_DIR = ..\r
 \r
 # \r
 # -I$(LIB_TARGET_DIR) option needed so that #include "machine.h"\r
 # directives can find the machine.h file.\r
 # \r
 \r
-WARNINGS = -Wall -Wno-comment -Wno-error\r
-CFLAGS += $(OPTIMIZE) -I$(LIB_TARGET_DIR) $(WARNINGS)\r
-ifneq (${OSARCH},CYGWIN)\r
-CFLAGS += -fPIC\r
-endif\r
-#CFLAGS+= $(shell if uname -m | grep -q 86; then echo "-mpentium" ; fi)\r
-\r
-#fix for PPC processors and ALPHA, And UltraSparc too\r
-ifneq ($(OSARCH),Darwin)\r
-ifneq ($(findstring BSD,${OSARCH}),BSD)\r
-ifneq ($(PROC),ppc)\r
-ifneq ($(PROC),x86_64)\r
-ifneq ($(PROC),alpha)\r
-#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.\r
-#This works for even old (2.96) versions of gcc and provides a small boost either way.\r
-#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.\r
-#So we go lowest common available by gcc and go a step down, still a step up from\r
-#the default as we now have a better instruction set to work with. - Belgarath\r
-ifeq ($(PROC),ultrasparc)\r
-        CFLAGS+= -mtune=$(PROC) -mcpu=v8 -O3 -fomit-frame-pointer\r
-else\r
-ifneq ($(OSARCH),SunOS)\r
-ifneq  ($(OSARCH),arm)\r
-#        CFLAGS+= -march=$(PROC)\r
-endif\r
-endif\r
-endif\r
-endif\r
-endif\r
-endif\r
-endif\r
-endif\r
+WARNINGS = -Wall\r
+CFLAGS = -O3 -I$(LIB_TARGET_DIR) $(WARNINGS)\r
 \r
 LIB = $(LIB_TARGET_DIR)/liblpc10.a\r
 \r
 .PHONY: all clean\r
 \r
 all:   $(LIB)\r
+       ranlib $(LIB)\r
 \r
-OBJ=   f2clib.o analys.o bsynz.o chanwr.o dcbias.o decode.o \\r
-               deemp.o difmag.o dyptrk.o encode.o energy.o ham84.o \\r
-               hp100.o invert.o irc2pc.o ivfilt.o lpcdec.o lpcenc.o \\r
-               lpcini.o lpfilt.o median.o mload.o onset.o pitsyn.o \\r
-               placea.o placev.o preemp.o prepro.o random.o rcchk.o \\r
-               synths.o tbdm.o voicin.o vparms.o\r
-\r
-$(LIB): $(OBJ)\r
-       $(AR) cr $@ $(OBJ)\r
-       ranlib $@\r
+$(LIB):                $(LIB)(f2clib.o)        \\r
+               $(LIB)(analys.o)        \\r
+               $(LIB)(bsynz.o)         \\r
+               $(LIB)(chanwr.o)        \\r
+               $(LIB)(dcbias.o)        \\r
+               $(LIB)(decode.o)        \\r
+               $(LIB)(deemp.o)         \\r
+               $(LIB)(difmag.o)        \\r
+               $(LIB)(dyptrk.o)        \\r
+               $(LIB)(encode.o)        \\r
+               $(LIB)(energy.o)        \\r
+               $(LIB)(ham84.o)         \\r
+               $(LIB)(hp100.o)         \\r
+               $(LIB)(invert.o)        \\r
+               $(LIB)(irc2pc.o)        \\r
+               $(LIB)(ivfilt.o)        \\r
+               $(LIB)(lpcdec.o)        \\r
+               $(LIB)(lpcenc.o)        \\r
+               $(LIB)(lpcini.o)        \\r
+               $(LIB)(lpfilt.o)        \\r
+               $(LIB)(median.o)        \\r
+               $(LIB)(mload.o)         \\r
+               $(LIB)(onset.o)         \\r
+               $(LIB)(pitsyn.o)        \\r
+               $(LIB)(placea.o)        \\r
+               $(LIB)(placev.o)        \\r
+               $(LIB)(preemp.o)        \\r
+               $(LIB)(prepro.o)        \\r
+               $(LIB)(random.o)        \\r
+               $(LIB)(rcchk.o)         \\r
+               $(LIB)(synths.o)        \\r
+               $(LIB)(tbdm.o)          \\r
+               $(LIB)(voicin.o)        \\r
+               $(LIB)(vparms.o)\r
 \r
 clean:\r
-       -rm -f *.o $(LIB)\r
+       -rm -f *.o\r
index 007a09e94958db7ede0d52bc01bef7f51407a918..2cff625f096b486ef4ed7b8c5a5548afe14328d0 100644 (file)
@@ -1,20 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: analys.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.2  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:16:01  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,8 +24,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
-#include "f2c.h"\r
-\r
 #ifdef P_R_O_T_O_T_Y_P_E_S\r
 extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_encoder_state *st);\r
 /* comlen contrl_ 12 */\r
@@ -60,6 +52,8 @@ extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real
        -lf2c -lm   (in that order)\r
 */\r
 \r
+#include "f2c.h"\r
+\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -87,21 +81,15 @@ static integer c__1 = 1;
 \r
 /*     ANALYS Version 55 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: analys.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:16:01  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -240,7 +228,11 @@ static integer c__1 = 1;
     extern /* Subroutine */ int onset_(real *, integer *, integer *, integer *\r
            , integer *, integer *, integer *, struct lpc10_encoder_state *);\r
     integer *osptr;\r
-    extern int dcbias_(integer *, real *, real *);\r
+    extern /* Subroutine */ placea_(integer *, integer *\r
+           , integer *, integer *, integer *, integer *, integer *, integer *\r
+           , integer *), dcbias_(integer *, real *, real *), placev_(integer \r
+           *, integer *, integer *, integer *, integer *, integer *, integer \r
+           *, integer *, integer *, integer *, integer *);\r
     integer ipitch;\r
     integer *obound;\r
     extern /* Subroutine */ int preemp_(real *, real *, integer *, real *, \r
@@ -259,21 +251,15 @@ static integer c__1 = 1;
            *, integer *, integer *, struct lpc10_encoder_state *);\r
     real phi[100]      /* was [10][10] */, psi[10];\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: analys.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:16:01  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -299,21 +285,15 @@ static integer c__1 = 1;
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
 /*       Arguments to ANALYS */\r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: analys.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:16:01  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -508,10 +488,10 @@ static integer c__1 = 1;
     voibuf[0] = voibuf[2];\r
     voibuf[1] = voibuf[3];\r
     for (i__ = 1; i__ <= 2; ++i__) {\r
-       vwin[(i__ << 1) - 2] = vwin[((i__ + 1) << 1) - 2] - contrl_1.lframe;\r
-       vwin[(i__ << 1) - 1] = vwin[((i__ + 1) << 1) - 1] - contrl_1.lframe;\r
-       awin[(i__ << 1) - 2] = awin[((i__ + 1) << 1) - 2] - contrl_1.lframe;\r
-       awin[(i__ << 1) - 1] = awin[((i__ + 1) << 1) - 1] - contrl_1.lframe;\r
+       vwin[(i__ << 1) - 2] = vwin[(i__ + (1 << 1)) - 2] - contrl_1.lframe;\r
+       vwin[(i__ << 1) - 1] = vwin[(i__ + (1 << 1)) - 1] - contrl_1.lframe;\r
+       awin[(i__ << 1) - 2] = awin[(i__ + (1 << 1)) - 2] - contrl_1.lframe;\r
+       awin[(i__ << 1) - 1] = awin[(i__ + (1 << 1)) - 1] - contrl_1.lframe;\r
 /*       EWIN(*,J) is unused for J .NE. AF, so the following shift is \r
 */\r
 /*       unnecessary.  It also causes error messages when the C versio\r
@@ -524,7 +504,7 @@ n */
 /*        EWIN(2,I) = EWIN(2,I+1) - LFRAME */\r
        obound[i__ - 1] = obound[i__];\r
        voibuf[i__ * 2] = voibuf[(i__ + 1) * 2];\r
-       voibuf[(i__ << 1) + 1] = voibuf[((i__ + 1) << 1) + 1];\r
+       voibuf[(i__ << 1) + 1] = voibuf[(i__ + (1 << 1)) + 1];\r
        rmsbuf[i__ - 1] = rmsbuf[i__];\r
        i__1 = contrl_1.order;\r
        for (j = 1; j <= i__1; ++j) {\r
index 7c75abc9ca446265867e727d75efcd85b688c92e..4f1cbf655a0e8a1e7d8e273cac9f7f292d1c9b7c 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: bsynz.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:18:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -27,6 +24,12 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int bsynz_(real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: random_ 4 0 */\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -34,12 +37,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int bsynz_(real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st);\r
-/* comlen contrl_ 12 */\r
-/*:ref: random_ 4 0 */\r
-#endif\r
-\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -53,18 +50,15 @@ extern struct {
 \r
 /*     BSYNZ Version 54 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: bsynz.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:18:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -155,18 +149,15 @@ extern struct {
     real xy, sum, ssq;\r
     real lpi0, hpi0;\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: bsynz.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:18:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -192,18 +183,15 @@ extern struct {
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: bsynz.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:18:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 2253e7b69c0b17074088150758ef86d0ff0f23c5..c486b2b7dd31ceaec549e21f827007e6cd655b78 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: chanwr.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:20:24  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -24,6 +18,11 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int chanwr_(integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st);\r
+extern int chanrd_(integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -35,18 +34,12 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 /*     CHANL Version 49 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: chanwr.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:20:24  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index b0908042ca3ced9b027b987c9c42c1b1b04fcba8..d43a82fd9bd869327e68a7014f25ffd22aca6d5e 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: dcbias.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:40:23  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int dcbias_(integer *len, real *speech, real *sigout);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int dcbias_(integer *len, real *speech, real *sigout);\r
-#endif\r
-\r
 /* ********************************************************************* */\r
 \r
 /*     DCBIAS Version 50 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: dcbias.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:40:23  jaf\r
  * Initial revision\r
index ee1ecb388b9dddce244df06af4ce71eb38123394..1ac5b7411f92270a4e7efe7463fe1bba798eecf6 100644 (file)
@@ -1,20 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: decode_.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.2  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:22:39  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,13 +24,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
-/*  -- translated by f2c (version 19951025).\r
-   You must link the resulting object file with the libraries:\r
-       -lf2c -lm   (in that order)\r
-*/\r
-\r
-#include "f2c.h"\r
-\r
 #ifdef P_R_O_T_O_T_Y_P_E_S\r
 extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);\r
 /* comlen contrl_ 12 */\r
@@ -44,6 +31,13 @@ extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice,
 /*:ref: median_ 4 3 4 4 4 */\r
 #endif\r
 \r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -61,21 +55,15 @@ static integer c__2 = 2;
 \r
 /*     DECODE Version 54 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: decode_.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:22:39  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -205,21 +193,15 @@ static integer c__2 = 2;
     extern integer median_(integer *, integer *, integer *);\r
     integer ishift, errcnt, lsb;\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: decode_.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:22:39  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -245,21 +227,15 @@ static integer c__2 = 2;
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: decode_.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:22:39  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -542,9 +518,9 @@ static integer c__2 = 2;
        }\r
        for (i__ = 1; i__ <= 6; ++i__) {\r
            if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))\r
-                    >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *\r
+                    >= corth[ixcor + (i__ + (2 << 2)) - 5] && (i__2 = drc[i__ *\r
                     3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[\r
-                   ixcor + ((i__ + 2) << 2) - 5]) {\r
+                   ixcor + (i__ + (2 << 2)) - 5]) {\r
                irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[\r
                        i__ * 3 - 3]);\r
            }\r
index e6715e8c54cc20342bd100eaa1f85aaf2fa9d8b3..8ea98c4a35f9cff4e3d0d60e2da42c5e8b2269d0 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: deemp.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:23:46  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -27,6 +21,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -34,26 +32,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);\r
-#endif\r
-\r
 /* ***************************************************************** */\r
 \r
 /*     DEEMP Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: deemp.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:23:46  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 03b12c377777166a4bc4749ce08fa994d1c0e6b1..564bda6f69af8f624f032f09e5b1091a6fe92dfe 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: difmag.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:32:31  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr);\r
-#endif\r
-\r
 /* ********************************************************************** */\r
 \r
 /*     DIFMAG Version 49 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:14  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: difmag.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:31  jaf\r
  * Initial revision\r
index 4656b004e0a9a59b960714f14a3d2ebe964fa05e..2d60223b149eba93c6e400a6ae3c15be8e3e97b4 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: dyptrk.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:25:29  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -27,6 +21,11 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int dyptrk_(real *amdf, integer *ltau, integer *minptr, integer *voice, integer *pitch, integer *midx, struct lpc10_encoder_state *st);\r
+/* comlen contrl_ 12 */\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -34,11 +33,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int dyptrk_(real *amdf, integer *ltau, integer *minptr, integer *voice, integer *pitch, integer *midx, struct lpc10_encoder_state *st);\r
-/* comlen contrl_ 12 */\r
-#endif\r
-\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -52,18 +46,12 @@ extern struct {
 \r
 /*     DYPTRK Version 52 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: dyptrk.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:25:29  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -147,18 +135,12 @@ extern struct {
     real alpha, minsc, maxsc;\r
 \r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: dyptrk.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:25:29  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 21a784647a914659a16c2e1dcf7de2f7a1dc7bbb..c0f081d07bc307faf3de70bc19021191eb07ebff 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: encode_.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:32:21  jaf\r
  * Initial revision\r
@@ -19,6 +16,11 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int encode_(integer *voice, integer *pitch, real *rms, real *rc, integer *ipitch, integer *irms, integer *irc);\r
+/* comlen contrl_ 12 */\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,11 +28,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int encode_(integer *voice, integer *pitch, real *rms, real *rc, integer *ipitch, integer *irms, integer *irc);\r
-/* comlen contrl_ 12 */\r
-#endif\r
-\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -48,18 +45,15 @@ static integer c__2 = 2;
 \r
 /*     ENCODE Version 54 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: encode_.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:21  jaf\r
  * Initial revision\r
@@ -139,18 +133,15 @@ static integer c__2 = 2;
     /* Local variables */\r
     integer idel, nbit, i__, j, i2, i3, mrk;\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: encode_.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:21  jaf\r
  * Initial revision\r
@@ -168,18 +159,15 @@ static integer c__2 = 2;
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: encode_.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:21  jaf\r
  * Initial revision\r
index 601bc588ddf5ce054bc092adbc18a328d3759aef..7a84eed9b3aa3462204016f81e9aaa92e27e3c40 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: energy.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:32:17  jaf\r
  * Initial revision\r
@@ -19,6 +16,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int energy_(integer *len, real *speech, real *rms);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +27,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int energy_(integer *len, real *speech, real *rms);\r
-#endif\r
-\r
 /* ********************************************************************* */\r
 \r
 /*     ENERGY Version 50 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: energy.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:17  jaf\r
  * Initial revision\r
index 71946f04cb163596af28d3bb72af0ab50f8a2c4e..684a85ddef0786d719105854aaf03f22006316c7 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: f2c.h,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:26:28  jaf\r
  * Any typedef defining a type that was used in lpc10_encoder_state or\r
@@ -215,17 +209,17 @@ typedef shortlogical (*K_fp)(...);
 typedef /* Character */ VOID (*H_fp)(...);\r
 typedef /* Subroutine */ int (*S_fp)(...);\r
 #else\r
-typedef int /* Unknown procedure type */ (*U_fp)(VOID);\r
-typedef shortint (*J_fp)(VOID);\r
-typedef integer (*I_fp)(VOID);\r
-typedef real (*R_fp)(VOID);\r
-typedef doublereal (*D_fp)(VOID), (*E_fp)(VOID);\r
-typedef /* Complex */ VOID (*C_fp)(VOID);\r
-typedef /* Double Complex */ VOID (*Z_fp)(VOID);\r
-typedef logical (*L_fp)(VOID);\r
-typedef shortlogical (*K_fp)(VOID);\r
-typedef /* Character */ VOID (*H_fp)(VOID);\r
-typedef /* Subroutine */ int (*S_fp)(VOID);\r
+typedef int /* Unknown procedure type */ (*U_fp)();\r
+typedef shortint (*J_fp)();\r
+typedef integer (*I_fp)();\r
+typedef real (*R_fp)();\r
+typedef doublereal (*D_fp)(), (*E_fp)();\r
+typedef /* Complex */ VOID (*C_fp)();\r
+typedef /* Double Complex */ VOID (*Z_fp)();\r
+typedef logical (*L_fp)();\r
+typedef shortlogical (*K_fp)();\r
+typedef /* Character */ VOID (*H_fp)();\r
+typedef /* Subroutine */ int (*S_fp)();\r
 #endif\r
 /* E_fp is for real functions when -R is not specified */\r
 typedef VOID C_f;      /* complex function */\r
@@ -255,71 +249,4 @@ typedef doublereal E_f;    /* real function with -R not specified */
 #undef unix\r
 #undef vax\r
 #endif\r
-\r
-#ifdef KR_headers\r
-extern integer pow_ii(ap, bp);\r
-extern double r_sign(a,b);\r
-extern integer i_nint(x);\r
-#else\r
-extern integer pow_ii(integer *ap, integer *bp);\r
-extern double r_sign(real *a, real *b);\r
-extern integer i_nint(real *x);\r
-\r
 #endif\r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int bsynz_(real *coef, integer *ip, integer *iv, \r
-                  real *sout, real *rms, real *ratio, real *g2pass,\r
-                  struct lpc10_decoder_state *st);\r
-extern int chanwr_(integer *order, integer *ipitv, integer *irms,\r
-                   integer *irc, integer *ibits, struct lpc10_encoder_state *st);\r
-extern int chanrd_(integer *order, integer *ipitv, integer *irms,\r
-                   integer *irc, integer *ibits);\r
-extern int chanwr_0_(int n__, integer *order, integer *ipitv, \r
-                     integer *irms, integer *irc, integer *ibits,\r
-                     struct lpc10_encoder_state *st);\r
-extern int dcbias_(integer *len, real *speech, real *sigout);\r
-extern int decode_(integer *ipitv, integer *irms, integer *irc, \r
-                   integer *voice, integer *pitch, real *rms,\r
-                   real *rc, struct lpc10_decoder_state *st);\r
-extern int deemp_(real *x, integer *n, struct lpc10_decoder_state *st);\r
-extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau,\r
-                   integer *maxlag, real *amdf, integer *minptr, integer *maxptr);\r
-extern int dyptrk_(real *amdf, integer *ltau, integer *\r
-                   minptr, integer *voice, integer *pitch, integer *midx,\r
-                   struct lpc10_encoder_state *st);\r
-extern int encode_(integer *voice, integer *pitch, real *rms, real *rc,\r
-                   integer *ipitch, integer *irms, integer *irc);\r
-extern int energy_(integer *len, real *speech, real *rms);\r
-extern int ham84_(integer *input, integer *output, integer *errcnt);\r
-extern int hp100_(real *speech, integer *start, integer *end,\r
-                 struct lpc10_encoder_state *st);\r
-extern int inithp100_(void);\r
-extern int invert_(integer *order, real *phi, real *psi, real *rc);\r
-extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);\r
-extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);\r
-extern int lpcdec_(integer *bits, real *speech);\r
-extern int initlpcdec_(void);\r
-extern int lpcenc_(real *speech, integer *bits);\r
-extern int initlpcenc_(void);\r
-extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);\r
-extern integer median_(integer *d1, integer *d2, integer *d3);\r
-extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);\r
-extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);\r
-extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);\r
-extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);\r
-extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);\r
-extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);\r
-extern int prepro_(real *speech, integer *length,\r
-                  struct lpc10_encoder_state *st);\r
-extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);\r
-extern integer random_(struct lpc10_decoder_state *st);\r
-extern int rcchk_(integer *order, real *rc1f, real *rc2f);\r
-extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);\r
-extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);\r
-extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);\r
-extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);\r
-\r
-#endif\r
-\r
-\r
-#endif /* ! defined F2C_INCLUDE */\r
index a340a96b27896501343687f7336f4988059576a2..22a966fe0864e1b898148daefd2feb493d0a3f56 100644 (file)
@@ -1,14 +1,20 @@
 /*\r
 \r
-$Log$\r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+$Log: f2clib.c,v $\r
+Revision 1.2  2004/05/05 13:25:38  rjongbloed\r
+Fixed clearly incorrect code (dived by zero) found with an MSVC warning\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.3  2004/02/17 09:21:45  csoutheren\r
+Fix for GM bug 134591\r
+\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
+\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:32:10  jaf\r
  * Initial revision\r
@@ -40,7 +46,7 @@ integer pow_ii(integer *ap, integer *bp)
                if (n == 0 || x == 1)\r
                        return 1;\r
                if (x != -1)\r
-                       return x == 0 ? 0 : 1/x;\r
+                       return x != 0 ? 1/x : 0;\r
                n = -n;\r
                }\r
        u = n;\r
@@ -80,6 +86,6 @@ integer i_nint(x) real *x;
 integer i_nint(real *x)\r
 #endif\r
 {\r
-return( (integer)((*x)>=0 ?\r
-       floor(*x + .5) : -floor(.5 - *x)) );\r
+return (integer)( (*x)>=0 ?\r
+       floor(*x + .5) : -(floor(.5 - *x)) );\r
 }\r
index d6a1351c5c55ac1a30c9016b8fd2a7008aece43b..e9537f1a2d1c326bbaaa0960b49898c3e6cf568a 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: ham84.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:32:07  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int ham84_(integer *input, integer *output, integer *errcnt);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int ham84_(integer *input, integer *output, integer *errcnt);\r
-#endif\r
-\r
 /* ***************************************************************** */\r
 \r
 /*     HAM84 Version 45G */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: ham84.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:07  jaf\r
  * Initial revision\r
index 7c2798e26f3f9ba61698c7af8c941d8aa5cd82e3..e2320b31dd2550f7bc62192103333bd5180b06f2 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: hp100.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:28:05  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -27,6 +21,12 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int hp100_(real *speech, integer *start, integer *end,\r
+                 struct lpc10_encoder_state *st);\r
+extern int inithp100_(void);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -34,28 +34,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int hp100_(real *speech, integer *start, integer *end,\r
-                 struct lpc10_encoder_state *st);\r
-extern int inithp100_(void);\r
-#endif\r
-\r
 /* ********************************************************************* */\r
 \r
 /*      HP100 Version 55 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: hp100.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:28:05  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 8891d1ce869f8d03ce8c62da87ba067c0b3a81d4..0f2a1254fbc38818c648f875c587d3057b652d8d 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: invert.c,v $\r
+Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:32:00  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int invert_(integer *order, real *phi, real *psi, real *rc);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int invert_(integer *order, real *phi, real *psi, real *rc);\r
-#endif\r
-\r
 /* **************************************************************** */\r
 \r
 /*     INVERT Version 45G */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: invert.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:00  jaf\r
  * Initial revision\r
@@ -102,18 +90,12 @@ extern int invert_(integer *order, real *phi, real *psi, real *rc);
     real v[100]        /* was [10][10] */;\r
 \r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: invert.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:42  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:32:00  jaf\r
  * Initial revision\r
index 983432f987f367f35f187c0358ce85dd25e00c24..623f71873c3ad5604f3221abb1a98dda8cf19384 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: irc2pc.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:56  jaf\r
  * Initial revision\r
@@ -19,6 +16,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +27,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass);\r
-#endif\r
-\r
 /* ***************************************************************** */\r
 \r
 /*     IRC2PC Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: irc2pc.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:56  jaf\r
  * Initial revision\r
@@ -93,18 +87,15 @@ extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pas
     integer i__, j;\r
 \r
 /*     Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: irc2pc.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:56  jaf\r
  * Initial revision\r
@@ -132,7 +123,7 @@ extern int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pas
     for (i__ = 1; i__ <= i__1; ++i__) {\r
        *g2pass *= 1.f - rc[i__] * rc[i__];\r
     }\r
-    *g2pass = *gprime * (real)sqrt(*g2pass);\r
+    *g2pass = (real)(*gprime * sqrt(*g2pass));\r
     pc[1] = rc[1];\r
     i__1 = *order;\r
     for (i__ = 2; i__ <= i__1; ++i__) {\r
index 625dd3e3277e5449a662d3b9867bd368339cd77e..dedde0fbd2e63455cb413aa03c39f1e9f976a96f 100644 (file)
@@ -1,20 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: ivfilt.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.2  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:53  jaf\r
  * Initial revision\r
@@ -22,6 +16,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -29,29 +27,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);\r
-#endif\r
-\r
 /* ********************************************************************* */\r
 \r
 /*     IVFILT Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
+/* $Log: ivfilt.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:53  jaf\r
  * Initial revision\r
@@ -109,7 +97,7 @@ extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real
     /* Function Body */\r
     for (i__ = 1; i__ <= 3; ++i__) {\r
        r__[i__ - 1] = 0.f;\r
-       k = (i__ - 1) << 2;\r
+       k = i__ - (1 << 2);\r
        i__1 = *len;\r
        for (j = (i__ << 2) + *len - *nsamp; j <= i__1; j += 2) {\r
            r__[i__ - 1] += lpbuf[j] * lpbuf[j - k];\r
index 56bb2ea188affa6ffbfaffaf20a982f85d96e39b..f20136ae405f54437898bed3cc07394aa7e59bf1 100644 (file)
@@ -4,6 +4,7 @@
        Version="8.00"\r
        Name="liblpc10"\r
        ProjectGUID="{FF1D238A-9D59-4850-838E-78182E05736B}"\r
+       RootNamespace="liblpc10"\r
        Keyword="Win32Proj"\r
        >\r
        <Platforms>\r
@@ -38,7 +39,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_LIB;P_R_O_T_O_T_Y_P_E_S"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                                RuntimeLibrary="3"\r
@@ -98,7 +99,7 @@
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_LIB;P_R_O_T_O_T_Y_P_E_S"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
index de6e11c281a6aa32a10615e461197f34e8d379ab..e921b6136a47326710c89c606606e31b5289df29 100644 (file)
@@ -1,26 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.18  2004/08/31 13:32:11  markster\r
-Merge NetBSD and Courtesty tone with modifications (bug #2329)\r
+$Log: lpc10.h,v $\r
+Revision 1.1  2004/05/04 11:30:49  csoutheren\r
+Initial version\r
 \r
-Revision 1.17  2003/10/26 18:50:49  markster\r
-Make it build and run on MacOS X\r
-\r
-Revision 1.3  2003/10/26 18:50:49  markster\r
-Make it build and run on MacOS X\r
-\r
-Revision 1.2  2003/04/23 19:13:35  markster\r
-More OpenBSD patches\r
-\r
-Revision 1.1.1.2  2003/03/16 22:37:30  matteo\r
-dom mar 16 23:37:23 CET 2003\r
-\r
-Revision 1.2  2003/03/16 16:09:48  markster\r
-Mere James's cleanups for fewer build warnings\r
-\r
-Revision 1.1  2000/01/05 00:20:06  markster\r
-Add broken lpc10 code...  It's not too far from working I don't think...\r
+Revision 1.1  2000/06/05 04:45:11  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:47:31  jaf\r
  * Initial revision\r
@@ -35,36 +20,8 @@ Add broken lpc10 code...  It's not too far from working I don't think...
 #define LPC10_BITS_IN_COMPRESSED_FRAME 54\r
 \r
 \r
-/*\r
-\r
-  The "#if defined"'s in this file are by no means intended to be\r
-  complete.  They are what Nautilus uses, which has been successfully\r
-  compiled under DOS with the Microsoft C compiler, and under a few\r
-  versions of Unix with the GNU C compiler.\r
-\r
- */\r
-\r
-#if defined(unix) || defined(__unix__) || defined(__NetBSD__)\r
 typedef short          INT16;\r
-typedef int                    INT32;\r
-#endif\r
-\r
-\r
-#if defined(__MSDOS__) || defined(MSDOS)\r
-typedef int                    INT16;\r
-typedef long           INT32;\r
-#endif\r
-\r
-#if defined(__APPLE__)\r
-typedef short          INT16;\r
-typedef int                    INT32;\r
-#endif\r
-\r
-#if defined(WIN32) && defined(_MSC_VER)\r
-typedef __int16                INT16;\r
-typedef __int32                INT32;\r
-#pragma warning(disable: 4005)\r
-#endif\r
+typedef int            INT32;\r
 \r
 \r
 /* The initial values for every member of this structure is 0, except\r
@@ -243,11 +200,11 @@ struct lpc10_decoder_state {
   \r
   */\r
 \r
-struct lpc10_encoder_state * create_lpc10_encoder_state (void);\r
+struct lpc10_encoder_state * create_lpc10_encoder_state ();\r
 void init_lpc10_encoder_state (struct lpc10_encoder_state *st);\r
 int lpc10_encode (real *speech, INT32 *bits, struct lpc10_encoder_state *st);\r
 \r
-struct lpc10_decoder_state * create_lpc10_decoder_state (void);\r
+struct lpc10_decoder_state * create_lpc10_decoder_state ();\r
 void init_lpc10_decoder_state (struct lpc10_decoder_state *st);\r
 int lpc10_decode (INT32 *bits, real *speech, struct lpc10_decoder_state *st);\r
 \r
index 095f6f7d5122ac6c9c44392d1a0b718b155a091d..4e4509e4191cccf6ecaf823a43a4ac725e496c1b 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: lpcdec.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:30:11  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,13 +24,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
-/*  -- translated by f2c (version 19951025).\r
-   You must link the resulting object file with the libraries:\r
-       -lf2c -lm   (in that order)\r
-*/\r
-\r
-#include "f2c.h"\r
-\r
 #ifdef P_R_O_T_O_T_Y_P_E_S\r
 extern int lpcdec_(integer *bits, real *speech);\r
 extern int initlpcdec_(void);\r
@@ -48,6 +35,13 @@ extern int initlpcdec_(void);
 /*:ref: initsynths_ 14 0 */\r
 #endif\r
 \r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -63,18 +57,12 @@ static integer c__10 = 10;
 \r
 /* ***************************************************************** */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: lpcdec.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:30:11  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -124,18 +112,12 @@ static integer c__10 = 10;
     integer irc[10], len;\r
     real rms;\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: lpcdec.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:30:11  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -164,18 +146,12 @@ static integer c__10 = 10;
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: lpcdec.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:30:11  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index cb90d21cea0c1762f497c058383bfce6a2739e52..8be7070a0a524c7bd469e0f61700028e43c75c5e 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: lpcenc.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:31:21  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,13 +24,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
-/*  -- translated by f2c (version 19951025).\r
-   You must link the resulting object file with the libraries:\r
-       -lf2c -lm   (in that order)\r
-*/\r
-\r
-#include "f2c.h"\r
-\r
 #ifdef P_R_O_T_O_T_Y_P_E_S\r
 extern int lpcenc_(real *speech, integer *bits);\r
 extern int initlpcenc_(void);\r
@@ -48,6 +35,13 @@ extern int initlpcenc_(void);
 /*:ref: initanalys_ 14 0 */\r
 #endif\r
 \r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
 /* Table of constant values */\r
 \r
 static integer c__180 = 180;\r
@@ -55,18 +49,12 @@ static integer c__10 = 10;
 \r
 /* ***************************************************************** */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: lpcenc.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:31:21  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -120,18 +108,12 @@ static integer c__10 = 10;
     real rms;\r
 \r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: lpcenc.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:31:21  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index fbaf2f628ff80842795bd0bf438287b51ff9a2dc..1cc2b3bb0a794c041f928a638c5adcad2fb689a7 100644 (file)
@@ -1,23 +1,17 @@
 /*\r
 \r
-$Log$\r
-Revision 1.18  2003/10/21 18:08:11  markster\r
-Fix include order\r
+$Log: lpcini.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.5  2003/10/21 18:08:11  markster\r
-Fix include order\r
+Revision 1.3  2002/10/10 05:29:04  robertj\r
+Removed non-ansi-C comments to maximise portability, thanks Martijn Roest\r
 \r
-Revision 1.4  2003/10/21 02:57:29  markster\r
-FreeBSD patch, take 2\r
+Revision 1.2  2001/02/24 14:00:10  rogerh\r
+Select the correct header file for malloc (stdlib.h or malloc.h)\r
 \r
-Revision 1.3  2003/10/16 21:11:30  martinp\r
-Revert the previous patch since it's braking compilation\r
-\r
-Revision 1.1  2003/02/12 13:59:15  matteo\r
-Initial revision\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:35:41  jaf\r
  * Added functions for allocating and initializing lpc10_encoder_state\r
@@ -41,9 +35,19 @@ extern int lpcini_(void);
        -lf2c -lm   (in that order)\r
 */\r
 \r
-#include <stdlib.h>\r
 #include "f2c.h"\r
 \r
+/* malloc is now defined in stdlib.h in serveral systems */\r
+#ifdef  HAS_STDLIB_H\r
+#       include <stdlib.h>\r
+#else\r
+#       ifdef   HAS_MALLOC_H\r
+#               include         <malloc.h>\r
+#       else\r
+                extern char * malloc();\r
+#       endif\r
+#endif\r
+\r
 /* Common Block Declarations */\r
 \r
 struct {\r
@@ -55,24 +59,18 @@ struct {
 \r
 /* ***************************************************************** */\r
 \r
-/* $Log$\r
- * Revision 1.18  2003/10/21 18:08:11  markster\r
- * Fix include order\r
- *\r
-/* Revision 1.5  2003/10/21 18:08:11  markster\r
-/* Fix include order\r
+/* $Log: lpcini.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.4  2003/10/21 02:57:29  markster\r
-/* FreeBSD patch, take 2\r
+/* Revision 1.3  2002/10/10 05:29:04  robertj\r
+/* Removed non-ansi-C comments to maximise portability, thanks Martijn Roest\r
 /*\r
-/* Revision 1.3  2003/10/16 21:11:30  martinp\r
-/* Revert the previous patch since it's braking compilation\r
+/* Revision 1.2  2001/02/24 14:00:10  rogerh\r
+/* Select the correct header file for malloc (stdlib.h or malloc.h)\r
 /*\r
-/* Revision 1.1  2003/02/12 13:59:15  matteo\r
-/* Initial revision\r
-/*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:35:41  jaf\r
  * Added functions for allocating and initializing lpc10_encoder_state\r
@@ -93,24 +91,18 @@ struct {
 /* Subroutine */ int lpcini_(void)\r
 {\r
 \r
-/* $Log$\r
- * Revision 1.18  2003/10/21 18:08:11  markster\r
- * Fix include order\r
- *\r
-/* Revision 1.5  2003/10/21 18:08:11  markster\r
-/* Fix include order\r
-/*\r
-/* Revision 1.4  2003/10/21 02:57:29  markster\r
-/* FreeBSD patch, take 2\r
+/* $Log: lpcini.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.3  2003/10/16 21:11:30  martinp\r
-/* Revert the previous patch since it's braking compilation\r
+/* Revision 1.3  2002/10/10 05:29:04  robertj\r
+/* Removed non-ansi-C comments to maximise portability, thanks Martijn Roest\r
 /*\r
-/* Revision 1.1  2003/02/12 13:59:15  matteo\r
-/* Initial revision\r
+/* Revision 1.2  2001/02/24 14:00:10  rogerh\r
+/* Select the correct header file for malloc (stdlib.h or malloc.h)\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:35:41  jaf\r
  * Added functions for allocating and initializing lpc10_encoder_state\r
@@ -131,24 +123,18 @@ struct {
 \r
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
-/* $Log$\r
- * Revision 1.18  2003/10/21 18:08:11  markster\r
- * Fix include order\r
- *\r
-/* Revision 1.5  2003/10/21 18:08:11  markster\r
-/* Fix include order\r
-/*\r
-/* Revision 1.4  2003/10/21 02:57:29  markster\r
-/* FreeBSD patch, take 2\r
+/* $Log: lpcini.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.3  2003/10/16 21:11:30  martinp\r
-/* Revert the previous patch since it's braking compilation\r
+/* Revision 1.3  2002/10/10 05:29:04  robertj\r
+/* Removed non-ansi-C comments to maximise portability, thanks Martijn Roest\r
 /*\r
-/* Revision 1.1  2003/02/12 13:59:15  matteo\r
-/* Initial revision\r
+/* Revision 1.2  2001/02/24 14:00:10  rogerh\r
+/* Select the correct header file for malloc (stdlib.h or malloc.h)\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:35:41  jaf\r
  * Added functions for allocating and initializing lpc10_encoder_state\r
index 35ff5a408e54ff87a444589a4a4a2e913a656eeb..a3f4f3c9ae99735881bdf658c14291663c408b37 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: lpfilt.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:35  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int lpfilt_(real *inbuf, real *lpbuf, integer *len, integer *nsamp);\r
-#endif\r
-\r
 /* *********************************************************************** */\r
 \r
 /*     LPFILT Version 55 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: lpfilt.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:35  jaf\r
  * Initial revision\r
index a40dd1e81375e0544c415f8356c798d923ac189c..66836d5185bc7d1a360cc834e7f6a3acb64882f7 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: median.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:31  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern integer median_(integer *d1, integer *d2, integer *d3);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern integer median_(integer *d1, integer *d2, integer *d3);\r
-#endif\r
-\r
 /* ********************************************************************* */\r
 \r
 /*     MEDIAN Version 45G */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: median.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:31  jaf\r
  * Initial revision\r
index 084737420d711a401ca33957249d4c18787b2852..ae1275565d11ca6e15b9a0dd9b07e4045fa4bb36 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: mload.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:25  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int mload_(integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi);\r
-#endif\r
-\r
 /* ***************************************************************** */\r
 \r
 /*     MLOAD Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: mload.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:25  jaf\r
  * Initial revision\r
index 2281cd14bbe47141ed445e8b40858c8db82b9ffc..f9e654fb76c83529929a8bdfda6e98908911ae06 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: onset.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:37:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -27,6 +24,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -34,10 +35,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int onset_(real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st);\r
-#endif\r
-\r
 /* Table of constant values */\r
 \r
 static real c_b2 = 1.f;\r
@@ -46,18 +43,15 @@ static real c_b2 = 1.f;
 \r
 /*     ONSET Version 49 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: onset.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:37:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -154,18 +148,15 @@ static real c_b2 = 1.f;
     real *fpc;\r
 \r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: onset.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:37:55  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 7378c0bd93e3f0cf97e0cb6b96eda48a9d4b43d4..a76200b37e8df37a61d844039cfe43fd394e3e2d 100644 (file)
@@ -1,20 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: pitsyn.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/11/23 22:14:32  markster\r
-Various warning cleanups\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:40:12  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,6 +24,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -37,29 +35,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st);\r
-#endif\r
-\r
 /* ***************************************************************** */\r
 \r
 /*     PITSYN Version 53 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/11/23 22:14:32  markster\r
-/* Various warning cleanups\r
+/* $Log: pitsyn.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:40:12  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -140,7 +128,7 @@ extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, re
     logical *first;\r
 \r
     /* System generated locals */\r
-    integer rci_dim1 = 0, rci_offset, i__1, i__2;\r
+    integer rci_dim1, rci_offset, i__1, i__2;\r
     real r__1;\r
 \r
     /* Builtin functions */\r
@@ -160,21 +148,15 @@ extern int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, re
     real xxy;\r
 \r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/11/23 22:14:32  markster\r
-/* Various warning cleanups\r
-/*\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: pitsyn.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:40:12  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index c0c7fa00cb516a2f91f604045066eeccbae52960..63985abb45e641389ec1edba882b1a5c5fec3016 100644 (file)
@@ -1,23 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: placea.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
+Revision 1.2  2001/10/16 21:21:14  yurik\r
+Removed warnings on Windows CE. Submitted by Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.2  2003/09/19 01:20:22  markster\r
-Code cleanups (bug #66)\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.3  2001/04/12 21:27:53  markh\r
-app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:07  jaf\r
  * Initial revision\r
@@ -25,6 +16,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -32,32 +27,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);\r
-#endif\r
-\r
 /* *********************************************************************** */\r
 \r
 /*     PLACEA Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.2  2003/09/19 01:20:22  markster\r
-/* Code cleanups (bug #66)\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: placea.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.3  2001/04/12 21:27:53  markh\r
-/* app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
+/* Revision 1.2  2001/10/16 21:21:14  yurik\r
+/* Removed warnings on Windows CE. Submitted by Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:07  jaf\r
  * Initial revision\r
@@ -170,7 +152,7 @@ extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *a
     allv = allv && voibuf[(*af << 1) + 1] == 1;\r
     allv = allv && voibuf[(*af << 1) + 2] == 1;\r
     winv = voibuf[(*af << 1) + 1] == 1 || voibuf[(*af << 1) + 2] == 1;\r
-    if (allv || (winv && *obound == 0)) {\r
+    if (allv || winv && *obound == 0) {\r
 /* APHASE:  Phase synchronous window placement. */\r
 /* Get minimum lower index of the window. */\r
        i__ = (lrange + *ipitch - 1 - awin[((*af - 1) << 1) + 1]) / *ipitch;\r
index 11fadb4e4288859a57a932c50257b2718d82d6ac..823ce0d4ffa1cb9339cbd4f41d55b57dbef7297e 100644 (file)
@@ -1,20 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: placev.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2001/10/16 21:21:14  yurik\r
+Removed warnings on Windows CE. Submitted by Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.3  2001/04/12 21:27:53  markh\r
-app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:31:02  jaf\r
  * Initial revision\r
@@ -22,6 +16,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -29,29 +27,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);\r
-#endif\r
-\r
 /* ****************************************************************** */\r
 \r
 /*     PLACEV Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: placev.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.3  2001/04/12 21:27:53  markh\r
-/* app_record now supports wildcards of sort so your output file is not overwritten every time it's run.  File.h got a documentation update on the ast_fileexists to include the return call.  Watch out for the placea.c placev.c code, it's updates have not been tested yet.  Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.\r
+/* Revision 1.2  2001/10/16 21:21:14  yurik\r
+/* Removed warnings on Windows CE. Submitted by Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:31:02  jaf\r
  * Initial revision\r
index a1dfb306f2e0077817afb281ecd5d98733796442..90a5c6fb14f34f3c318486b0ba27387a146a32a4 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: preemp.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:30:58  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int preemp_(real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__);\r
-#endif\r
-\r
 /* ******************************************************************* */\r
 \r
 /*     PREEMP Version 55 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: preemp.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:30:58  jaf\r
  * Initial revision\r
index d535a0bad702ada113eb71c7813153b06377f240..d0cc5be029860b768207c4642fb1b10487e9a5de 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: prepro.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:40:51  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -24,22 +18,23 @@ Some OSS fixes and a few lpc changes to make it actually work
  * Revision 1.1  1996/08/19  22:30:54  jaf\r
  * Initial revision\r
  *\r
- */\r
 \r
-/*  -- translated by f2c (version 19951025).\r
-   You must link the resulting object file with the libraries:\r
-       -lf2c -lm   (in that order)\r
 */\r
 \r
-#include "f2c.h"\r
-\r
 #ifdef P_R_O_T_O_T_Y_P_E_S\r
 extern int prepro_(real *speech, integer *length,\r
-                  struct lpc10_encoder_state *st);\r
+                  struct lpc10_encoder_state *st)\r
 /*:ref: hp100_ 14 3 6 4 4 */\r
 /*:ref: inithp100_ 14 0 */\r
 #endif\r
 \r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
 /* Table of constant values */\r
 \r
 static integer c__1 = 1;\r
@@ -48,18 +43,12 @@ static integer c__1 = 1;
 \r
 /*     PREPRO Version 48 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: prepro.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:40:51  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 4b8b3fc38d0d69dcc10d26737d7b62c4612bba7a..7345f6b692646c9c71239a15dca767c52917d01e 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: random.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:41:32  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -27,6 +21,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern integer random_(struct lpc10_decoder_state *st);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -34,26 +32,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern integer random_(struct lpc10_decoder_state *st);\r
-#endif\r
-\r
 /* ********************************************************************** */\r
 \r
 /*     RANDOM Version 49 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: random.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:41:32  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 00ae8e4da871438a37ef3f2c679aae3a0796c33b..abd353fcb301f5ae24626e77df28b8c0eb9250c3 100644 (file)
@@ -1,17 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: rcchk.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:30:41  jaf\r
  * Initial revision\r
@@ -19,6 +13,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int rcchk_(integer *order, real *rc1f, real *rc2f);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,26 +24,16 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int rcchk_(integer *order, real *rc1f, real *rc2f);\r
-#endif\r
-\r
 /* ********************************************************************* */\r
 \r
 /*     RCCHK Version 45G */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: rcchk.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:30:41  jaf\r
  * Initial revision\r
index 722ceb592fba4330bad4f8d98c5550ae78f8a7b8..a8379c3d200abcf9213564307ee114e8e658ec4e 100644 (file)
@@ -1,20 +1,11 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: synths.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/09/27 02:45:37  markster\r
-Fix various compiler warnings (bug #322)\r
-\r
-Revision 1.2  2003/09/27 02:45:37  markster\r
-Fix various compiler warnings (bug #322)\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:39  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:42:59  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,13 +21,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
-/*  -- translated by f2c (version 19951025).\r
-   You must link the resulting object file with the libraries:\r
-       -lf2c -lm   (in that order)\r
-*/\r
-\r
-#include "f2c.h"\r
-\r
 #ifdef P_R_O_T_O_T_Y_P_E_S\r
 extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);\r
 /* comlen contrl_ 12 */\r
@@ -49,6 +33,13 @@ extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *sp
 /*:ref: initdeemp_ 14 0 */\r
 #endif\r
 \r
+/*  -- translated by f2c (version 19951025).\r
+   You must link the resulting object file with the libraries:\r
+       -lf2c -lm   (in that order)\r
+*/\r
+\r
+#include "f2c.h"\r
+\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -66,21 +57,12 @@ static real c_b2 = .7f;
 \r
 /*     SYNTHS Version 54 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/27 02:45:37  markster\r
-/* Fix various compiler warnings (bug #322)\r
-/*\r
-/* Revision 1.2  2003/09/27 02:45:37  markster\r
-/* Fix various compiler warnings (bug #322)\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: synths.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:42:59  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -185,6 +167,9 @@ static real c_b2 = .7f;
     extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);\r
     real ratio;\r
     integer ipiti[16];\r
+    extern /* Subroutine */ bsynz_(real *, integer *, \r
+           integer *, real *, real *, real *, real *, struct lpc10_decoder_state *), irc2pc_(real *, real *\r
+           , integer *, real *, real *);\r
     real g2pass;\r
     real pc[10];\r
     extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real \r
@@ -192,21 +177,12 @@ static real c_b2 = .7f;
            integer *, real *, struct lpc10_decoder_state *);\r
     real rci[160]      /* was [10][16] */;\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/27 02:45:37  markster\r
-/* Fix various compiler warnings (bug #322)\r
-/*\r
-/* Revision 1.2  2003/09/27 02:45:37  markster\r
-/* Fix various compiler warnings (bug #322)\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: synths.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:42:59  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -232,21 +208,12 @@ static real c_b2 = .7f;
 /*   LPC Configuration parameters: */\r
 /* Frame size, Prediction order, Pitch period */\r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/09/27 02:45:37  markster\r
-/* Fix various compiler warnings (bug #322)\r
-/*\r
-/* Revision 1.2  2003/09/27 02:45:37  markster\r
-/* Fix various compiler warnings (bug #322)\r
-/*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: synths.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:39  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:42:59  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 5071dfb0c831a2466c7a533bcce2a8f5125eed69..bd9ebf1778b4917e6025535f5ebee2962b4a1bff 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: tbdm.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:40  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:30:26  jaf\r
  * Initial revision\r
@@ -19,6 +16,11 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);\r
+/*:ref: difmag_ 14 8 6 4 4 4 4 6 4 4 */\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,27 +28,19 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);\r
-/*:ref: difmag_ 14 8 6 4 4 4 4 6 4 4 */\r
-#endif\r
-\r
 /* ********************************************************************** */\r
 \r
 /*     TBDM Version 49 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: tbdm.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:40  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:30:26  jaf\r
  * Initial revision\r
index f72bee9c0e766c2687a5dc457ed1eabbfb5bccc7..492bee0bac3d39a43d6fce6c5ebfca731bb38a70 100644 (file)
@@ -1,20 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.16  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: voicin.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.15  2003/11/23 22:14:32  markster\r
-Various warning cleanups\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:40  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.2  1996/08/20  20:45:00  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -30,6 +24,12 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);\r
+/* comlen contrl_ 12 */\r
+/*:ref: vparms_ 14 14 4 6 6 4 4 6 4 4 4 4 6 6 6 6 */\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -37,12 +37,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int voicin_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st);\r
-/* comlen contrl_ 12 */\r
-/*:ref: vparms_ 14 14 4 6 6 4 4 6 4 4 4 4 6 6 6 6 */\r
-#endif\r
-\r
 /* Common Block Declarations */\r
 \r
 extern struct {\r
@@ -56,21 +50,15 @@ extern struct {
 \r
 /*     VOICIN Version 52 */\r
 \r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/11/23 22:14:32  markster\r
-/* Various warning cleanups\r
-/*\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: voicin.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:40  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:45:00  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
@@ -277,7 +265,7 @@ s*/
            ;\r
 \r
     /* System generated locals */\r
-    integer inbuf_offset = 0, lpbuf_offset = 0, i__1, i__2;\r
+    integer inbuf_offset, lpbuf_offset, i__1, i__2;\r
     real r__1, r__2;\r
 \r
     /* Builtin functions */\r
@@ -307,21 +295,15 @@ s*/
 \r
 /*     Global Variables: */\r
 /*       Arguments */\r
-/* $Log$\r
- * Revision 1.16  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.15  2003/11/23 22:14:32  markster\r
-/* Various warning cleanups\r
-/*\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: voicin.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:40  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.2  1996/08/20  20:45:00  jaf\r
  * Removed all static local variables that were SAVE'd in the Fortran\r
index 0bb1f117de1921ee13b8a634d1640ac38db8c76b..25f5fb58ae05caa5ae773d5b4573d140f73ce30f 100644 (file)
@@ -1,17 +1,14 @@
 /*\r
 \r
-$Log$\r
-Revision 1.15  2004/06/26 03:50:14  markster\r
-Merge source cleanups (bug #1911)\r
+$Log: vparms.c,v $\r
+Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+Initial version\r
 \r
-Revision 1.14  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
+Revision 1.2  2002/02/15 03:57:55  yurik\r
+Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 \r
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-mer feb 12 14:56:57 CET 2003\r
-\r
-Revision 1.2  2000/01/05 08:20:40  markster\r
-Some OSS fixes and a few lpc changes to make it actually work\r
+Revision 1.1  2000/06/05 04:45:12  robertj\r
+Added LPC-10 2400bps codec\r
 \r
  * Revision 1.1  1996/08/19  22:30:04  jaf\r
  * Initial revision\r
@@ -19,6 +16,10 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 */\r
 \r
+#ifdef P_R_O_T_O_T_Y_P_E_S\r
+extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);\r
+#endif\r
+\r
 /*  -- translated by f2c (version 19951025).\r
    You must link the resulting object file with the libraries:\r
        -lf2c -lm   (in that order)\r
@@ -26,10 +27,6 @@ Some OSS fixes and a few lpc changes to make it actually work
 \r
 #include "f2c.h"\r
 \r
-#ifdef P_R_O_T_O_T_Y_P_E_S\r
-extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);\r
-#endif\r
-\r
 /* Table of constant values */\r
 \r
 static real c_b2 = 1.f;\r
@@ -38,18 +35,15 @@ static real c_b2 = 1.f;
 \r
 /*     VPARMS Version 50 */\r
 \r
-/* $Log$\r
- * Revision 1.15  2004/06/26 03:50:14  markster\r
- * Merge source cleanups (bug #1911)\r
- *\r
-/* Revision 1.14  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* $Log: vparms.c,v $\r
+/* Revision 1.1  2004/05/04 11:16:43  csoutheren\r
+/* Initial version\r
 /*\r
-/* Revision 1.1.1.1  2003/02/12 13:59:15  matteo\r
-/* mer feb 12 14:56:57 CET 2003\r
+/* Revision 1.2  2002/02/15 03:57:55  yurik\r
+/* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com\r
 /*\r
-/* Revision 1.2  2000/01/05 08:20:40  markster\r
-/* Some OSS fixes and a few lpc changes to make it actually work\r
+/* Revision 1.1  2000/06/05 04:45:12  robertj\r
+/* Added LPC-10 2400bps codec\r
 /*\r
  * Revision 1.1  1996/08/19  22:30:04  jaf\r
  * Initial revision\r