getCBvec.c

Go to the documentation of this file.
00001 
00002    /******************************************************************
00003 
00004        iLBC Speech Coder ANSI-C Source Code
00005 
00006        getCBvec.c
00007 
00008        Copyright (C) The Internet Society (2004).
00009        All Rights Reserved.
00010 
00011    ******************************************************************/
00012 
00013    #include "iLBC_define.h"
00014    #include "constants.h"
00015    #include <string.h>
00016 
00017    /*----------------------------------------------------------------*
00018     *  Construct codebook vector for given index.
00019     *---------------------------------------------------------------*/
00020 
00021    void getCBvec(
00022 
00023 
00024 
00025 
00026 
00027        float *cbvec,   /* (o) Constructed codebook vector */
00028        float *mem,     /* (i) Codebook buffer */
00029        int index,      /* (i) Codebook index */
00030        int lMem,       /* (i) Length of codebook buffer */
00031        int cbveclen/* (i) Codebook vector length */
00032    ){
00033        int j, k, n, memInd, sFilt;
00034        float tmpbuf[CB_MEML];
00035        int base_size;
00036        int ilow, ihigh;
00037        float alfa, alfa1;
00038 
00039        /* Determine size of codebook sections */
00040 
00041        base_size=lMem-cbveclen+1;
00042 
00043        if (cbveclen==SUBL) {
00044            base_size+=cbveclen/2;
00045        }
00046 
00047        /* No filter -> First codebook section */
00048 
00049        if (index<lMem-cbveclen+1) {
00050 
00051            /* first non-interpolated vectors */
00052 
00053            k=index+cbveclen;
00054            /* get vector */
00055            memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));
00056 
00057        } else if (index < base_size) {
00058 
00059            k=2*(index-(lMem-cbveclen+1))+cbveclen;
00060 
00061            ihigh=k/2;
00062            ilow=ihigh-5;
00063 
00064            /* Copy first noninterpolated part */
00065 
00066            memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));
00067 
00068            /* interpolation */
00069 
00070            alfa1=(float)0.2;
00071            alfa=0.0;
00072            for (j=ilow; j<ihigh; j++) {
00073                cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+
00074                    alfa*mem[lMem-k+j];
00075 
00076 
00077 
00078 
00079 
00080                alfa+=alfa1;
00081            }
00082 
00083            /* Copy second noninterpolated part */
00084 
00085            memcpy(cbvec+ihigh, mem+lMem-k+ihigh,
00086                (cbveclen-ihigh)*sizeof(float));
00087 
00088        }
00089 
00090        /* Higher codebook section based on filtering */
00091 
00092        else {
00093 
00094            /* first non-interpolated vectors */
00095 
00096            if (index-base_size<lMem-cbveclen+1) {
00097                float tempbuff2[CB_MEML+CB_FILTERLEN+1];
00098                float *pos;
00099                float *pp, *pp1;
00100 
00101                memset(tempbuff2, 0,
00102                    CB_HALFFILTERLEN*sizeof(float));
00103                memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
00104                    lMem*sizeof(float));
00105                memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
00106                    (CB_HALFFILTERLEN+1)*sizeof(float));
00107 
00108                k=index-base_size+cbveclen;
00109                sFilt=lMem-k;
00110                memInd=sFilt+1-CB_HALFFILTERLEN;
00111 
00112                /* do filtering */
00113                pos=cbvec;
00114                memset(pos, 0, cbveclen*sizeof(float));
00115                for (n=0; n<cbveclen; n++) {
00116                    pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];
00117                    pp1=&cbfiltersTbl[CB_FILTERLEN-1];
00118                    for (j=0; j<CB_FILTERLEN; j++) {
00119                        (*pos)+=(*pp++)*(*pp1--);
00120                    }
00121                    pos++;
00122                }
00123            }
00124 
00125            /* interpolated vectors */
00126 
00127            else {
00128 
00129 
00130 
00131 
00132 
00133                float tempbuff2[CB_MEML+CB_FILTERLEN+1];
00134 
00135                float *pos;
00136                float *pp, *pp1;
00137                int i;
00138 
00139                memset(tempbuff2, 0,
00140                    CB_HALFFILTERLEN*sizeof(float));
00141                memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
00142                    lMem*sizeof(float));
00143                memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
00144                    (CB_HALFFILTERLEN+1)*sizeof(float));
00145 
00146                k=2*(index-base_size-
00147                    (lMem-cbveclen+1))+cbveclen;
00148                sFilt=lMem-k;
00149                memInd=sFilt+1-CB_HALFFILTERLEN;
00150 
00151                /* do filtering */
00152                pos=&tmpbuf[sFilt];
00153                memset(pos, 0, k*sizeof(float));
00154                for (i=0; i<k; i++) {
00155                    pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];
00156                    pp1=&cbfiltersTbl[CB_FILTERLEN-1];
00157                    for (j=0; j<CB_FILTERLEN; j++) {
00158                        (*pos)+=(*pp++)*(*pp1--);
00159                    }
00160                    pos++;
00161                }
00162 
00163                ihigh=k/2;
00164                ilow=ihigh-5;
00165 
00166                /* Copy first noninterpolated part */
00167 
00168                memcpy(cbvec, tmpbuf+lMem-k/2,
00169                    ilow*sizeof(float));
00170 
00171                /* interpolation */
00172 
00173                alfa1=(float)0.2;
00174                alfa=0.0;
00175                for (j=ilow; j<ihigh; j++) {
00176                    cbvec[j]=((float)1.0-alfa)*
00177                        tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];
00178                    alfa+=alfa1;
00179                }
00180 
00181 
00182 
00183 
00184 
00185 
00186                /* Copy second noninterpolated part */
00187 
00188                memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,
00189                    (cbveclen-ihigh)*sizeof(float));
00190            }
00191        }
00192    }
00193 

Generated on Thu Apr 16 06:27:36 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6