createCB.c File Reference

#include "iLBC_define.h"
#include "constants.h"
#include <string.h>
#include <math.h>

Include dependency graph for createCB.c:

Go to the source code of this file.

Functions

void createAugmentedVec (int index, float *buffer, float *cbVec)
void filteredCBvecs (float *cbvectors, float *mem, int lMem)
void searchAugmentedCB (int low, int high, int stage, int startIndex, float *target, float *buffer, float *max_measure, int *best_index, float *gain, float *energy, float *invenergy)


Function Documentation

void createAugmentedVec ( int  index,
float *  buffer,
float *  cbVec 
)

Definition at line 190 of file createCB.c.

References SUBL.

Referenced by iCBSearch().

00196      {
00197        int ilow, j;
00198        float *pp, *ppo, *ppi, alfa, alfa1, weighted;
00199 
00200        ilow = index-5;
00201 
00202        /* copy the first noninterpolated part */
00203 
00204        pp = buffer-index;
00205        memcpy(cbVec,pp,sizeof(float)*index);
00206 
00207        /* interpolation */
00208 
00209        alfa1 = (float)0.2;
00210        alfa = 0.0;
00211        ppo = buffer-5;
00212        ppi = buffer-index-5;
00213        for (j=ilow; j<index; j++) {
00214            weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
00215            ppo++;
00216            ppi++;
00217            cbVec[j] = weighted;
00218            alfa += alfa1;
00219        }
00220 
00221        /* copy the second noninterpolated part */
00222 
00223        pp = buffer - index;
00224        memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));
00225 
00226 
00227 
00228 
00229 
00230    }

void filteredCBvecs ( float *  cbvectors,
float *  mem,
int  lMem 
)

Definition at line 29 of file createCB.c.

References CB_FILTERLEN, CB_HALFFILTERLEN, CB_MEML, and cbfiltersTbl.

Referenced by iCBSearch().

00035     {
00036        int j, k;
00037        float *pp, *pp1;
00038        float tempbuff2[CB_MEML+CB_FILTERLEN];
00039        float *pos;
00040 
00041        memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));
00042        memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));
00043        memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0,
00044            (CB_HALFFILTERLEN+1)*sizeof(float));
00045 
00046        /* Create codebook vector for higher section by filtering */
00047 
00048        /* do filtering */
00049        pos=cbvectors;
00050        memset(pos, 0, lMem*sizeof(float));
00051        for (k=0; k<lMem; k++) {
00052            pp=&tempbuff2[k];
00053            pp1=&cbfiltersTbl[CB_FILTERLEN-1];
00054            for (j=0;j<CB_FILTERLEN;j++) {
00055                (*pos)+=(*pp++)*(*pp1--);
00056            }
00057            pos++;
00058        }
00059    }

void searchAugmentedCB ( int  low,
int  high,
int  stage,
int  startIndex,
float *  target,
float *  buffer,
float *  max_measure,
int *  best_index,
float *  gain,
float *  energy,
float *  invenergy 
)

Definition at line 71 of file createCB.c.

References CB_MAXGAIN, EPS, and SUBL.

Referenced by iCBSearch().

00087      {
00088        int icount, ilow, j, tmpIndex;
00089        float *pp, *ppo, *ppi, *ppe, crossDot, alfa;
00090        float weighted, measure, nrjRecursive;
00091        float ftmp;
00092 
00093        /* Compute the energy for the first (low-5)
00094           noninterpolated samples */
00095        nrjRecursive = (float) 0.0;
00096        pp = buffer - low + 1;
00097        for (j=0; j<(low-5); j++) {
00098            nrjRecursive += ( (*pp)*(*pp) );
00099            pp++;
00100        }
00101        ppe = buffer - low;
00102 
00103 
00104        for (icount=low; icount<=high; icount++) {
00105 
00106            /* Index of the codebook vector used for retrieving
00107               energy values */
00108            tmpIndex = startIndex+icount-20;
00109 
00110            ilow = icount-4;
00111 
00112            /* Update the energy recursively to save complexity */
00113            nrjRecursive = nrjRecursive + (*ppe)*(*ppe);
00114            ppe--;
00115            energy[tmpIndex] = nrjRecursive;
00116 
00117            /* Compute cross dot product for the first (low-5)
00118               samples */
00119 
00120 
00121 
00122 
00123 
00124            crossDot = (float) 0.0;
00125            pp = buffer-icount;
00126            for (j=0; j<ilow; j++) {
00127                crossDot += target[j]*(*pp++);
00128            }
00129 
00130            /* interpolation */
00131            alfa = (float) 0.2;
00132            ppo = buffer-4;
00133            ppi = buffer-icount-4;
00134            for (j=ilow; j<icount; j++) {
00135                weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
00136                ppo++;
00137                ppi++;
00138                energy[tmpIndex] += weighted*weighted;
00139                crossDot += target[j]*weighted;
00140                alfa += (float)0.2;
00141            }
00142 
00143            /* Compute energy and cross dot product for the
00144               remaining samples */
00145            pp = buffer - icount;
00146            for (j=icount; j<SUBL; j++) {
00147                energy[tmpIndex] += (*pp)*(*pp);
00148                crossDot += target[j]*(*pp++);
00149            }
00150 
00151            if (energy[tmpIndex]>0.0) {
00152                invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);
00153            } else {
00154                invenergy[tmpIndex] = (float) 0.0;
00155            }
00156 
00157            if (stage==0) {
00158                measure = (float)-10000000.0;
00159 
00160                if (crossDot > 0.0) {
00161                    measure = crossDot*crossDot*invenergy[tmpIndex];
00162                }
00163            }
00164            else {
00165                measure = crossDot*crossDot*invenergy[tmpIndex];
00166            }
00167 
00168            /* check if measure is better */
00169            ftmp = crossDot*invenergy[tmpIndex];
00170 
00171            if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
00172 
00173 
00174 
00175 
00176 
00177                *best_index = tmpIndex;
00178                *max_measure = measure;
00179                *gain = ftmp;
00180            }
00181        }
00182    }


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