enhancer.h File Reference

#include "iLBC_define.h"

Include dependency graph for enhancer.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int enhancerInterface (float *out, float *in, iLBC_Dec_Inst_t *iLBCdec_inst)
float xCorrCoef (float *target, float *regressor, int subl)


Function Documentation

int enhancerInterface ( float *  out,
float *  in,
iLBC_Dec_Inst_t iLBCdec_inst 
)

Definition at line 517 of file enhancer.c.

References iLBC_Dec_Inst_t_::blockl, DownSample(), ENH_ALPHA0, ENH_BLOCKL, ENH_BLOCKL_HALF, iLBC_Dec_Inst_t_::enh_buf, ENH_BUFL, ENH_NBLOCKS, ENH_NBLOCKS_EXTRA, ENH_NBLOCKS_TOT, iLBC_Dec_Inst_t_::enh_period, enh_plocsTbl, enhancer(), lpFilt_coefsTbl, iLBC_Dec_Inst_t_::mode, iLBC_Dec_Inst_t_::prev_enh_pl, and xCorrCoef().

Referenced by iLBC_decode().

00521     {
00522        float *enh_buf, *enh_period;
00523        int iblock, isample;
00524        int lag=0, ilag, i, ioffset;
00525        float cc, maxcc;
00526        float ftmp1, ftmp2;
00527        float *inPtr, *enh_bufPtr1, *enh_bufPtr2;
00528        float plc_pred[ENH_BLOCKL];
00529 
00530        float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];
00531        int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;
00532        int start, plc_blockl, inlag;
00533 
00534        enh_buf=iLBCdec_inst->enh_buf;
00535        enh_period=iLBCdec_inst->enh_period;
00536 
00537        memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl],
00538            (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));
00539 
00540        memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in,
00541            iLBCdec_inst->blockl*sizeof(float));
00542 
00543        if (iLBCdec_inst->mode==30)
00544            plc_blockl=ENH_BLOCKL;
00545        else
00546            plc_blockl=40;
00547 
00548        /* when 20 ms frame, move processing one block */
00549        ioffset=0;
00550        if (iLBCdec_inst->mode==20) ioffset=1;
00551 
00552        i=3-ioffset;
00553        memmove(enh_period, &enh_period[i],
00554            (ENH_NBLOCKS_TOT-i)*sizeof(float));
00555 
00556 
00557 
00558 
00559 
00560 
00561        /* Set state information to the 6 samples right before
00562           the samples to be downsampled. */
00563 
00564        memcpy(lpState,
00565            enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126,
00566            6*sizeof(float));
00567 
00568        /* Down sample a factor 2 to save computations */
00569 
00570        DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,
00571                    lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,
00572                    lpState, downsampled);
00573 
00574        /* Estimate the pitch in the down sampled domain. */
00575        for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {
00576 
00577            lag = 10;
00578            maxcc = xCorrCoef(downsampled+60+iblock*
00579                ENH_BLOCKL_HALF, downsampled+60+iblock*
00580                ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);
00581            for (ilag=11; ilag<60; ilag++) {
00582                cc = xCorrCoef(downsampled+60+iblock*
00583                    ENH_BLOCKL_HALF, downsampled+60+iblock*
00584                    ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);
00585 
00586                if (cc > maxcc) {
00587                    maxcc = cc;
00588                    lag = ilag;
00589                }
00590            }
00591 
00592            /* Store the estimated lag in the non-downsampled domain */
00593            enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;
00594 
00595 
00596        }
00597 
00598 
00599        /* PLC was performed on the previous packet */
00600        if (iLBCdec_inst->prev_enh_pl==1) {
00601 
00602            inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];
00603 
00604            lag = inlag-1;
00605            maxcc = xCorrCoef(in, in+lag, plc_blockl);
00606            for (ilag=inlag; ilag<=inlag+1; ilag++) {
00607                cc = xCorrCoef(in, in+ilag, plc_blockl);
00608 
00609 
00610 
00611 
00612 
00613 
00614                if (cc > maxcc) {
00615                    maxcc = cc;
00616                    lag = ilag;
00617                }
00618            }
00619 
00620            enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;
00621 
00622            /* compute new concealed residual for the old lookahead,
00623               mix the forward PLC with a backward PLC from
00624               the new frame */
00625 
00626            inPtr=&in[lag-1];
00627 
00628            enh_bufPtr1=&plc_pred[plc_blockl-1];
00629 
00630            if (lag>plc_blockl) {
00631                start=plc_blockl;
00632            } else {
00633                start=lag;
00634            }
00635 
00636            for (isample = start; isample>0; isample--) {
00637                *enh_bufPtr1-- = *inPtr--;
00638            }
00639 
00640            enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
00641            for (isample = (plc_blockl-1-lag); isample>=0; isample--) {
00642                *enh_bufPtr1-- = *enh_bufPtr2--;
00643            }
00644 
00645            /* limit energy change */
00646            ftmp2=0.0;
00647            ftmp1=0.0;
00648            for (i=0;i<plc_blockl;i++) {
00649                ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*
00650                    enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];
00651                ftmp1+=plc_pred[i]*plc_pred[i];
00652            }
00653            ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);
00654            ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);
00655            if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {
00656                for (i=0;i<plc_blockl-10;i++) {
00657                    plc_pred[i]*=(float)2.0*ftmp2/ftmp1;
00658                }
00659                for (i=plc_blockl-10;i<plc_blockl;i++) {
00660                    plc_pred[i]*=(float)(i-plc_blockl+10)*
00661                        ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+
00662 
00663 
00664 
00665 
00666 
00667                        (float)2.0*ftmp2/ftmp1;
00668                }
00669            }
00670 
00671            enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
00672            for (i=0; i<plc_blockl; i++) {
00673                ftmp1 = (float) (i+1) / (float) (plc_blockl+1);
00674                *enh_bufPtr1 *= ftmp1;
00675                *enh_bufPtr1 += ((float)1.0-ftmp1)*
00676                                    plc_pred[plc_blockl-1-i];
00677                enh_bufPtr1--;
00678            }
00679        }
00680 
00681        if (iLBCdec_inst->mode==20) {
00682            /* Enhancer with 40 samples delay */
00683            for (iblock = 0; iblock<2; iblock++) {
00684                enhancer(out+iblock*ENH_BLOCKL, enh_buf,
00685                    ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,
00686                    ENH_ALPHA0, enh_period, enh_plocsTbl,
00687                        ENH_NBLOCKS_TOT);
00688            }
00689        } else if (iLBCdec_inst->mode==30) {
00690            /* Enhancer with 80 samples delay */
00691            for (iblock = 0; iblock<3; iblock++) {
00692                enhancer(out+iblock*ENH_BLOCKL, enh_buf,
00693                    ENH_BUFL, (4+iblock)*ENH_BLOCKL,
00694                    ENH_ALPHA0, enh_period, enh_plocsTbl,
00695                        ENH_NBLOCKS_TOT);
00696            }
00697        }
00698 
00699        return (lag*2);
00700    }

float xCorrCoef ( float *  target,
float *  regressor,
int  subl 
)

Definition at line 485 of file enhancer.c.

Referenced by enhancerInterface(), and iLBC_decode().

00489     {
00490        int i;
00491        float ftmp1, ftmp2;
00492 
00493        ftmp1 = 0.0;
00494        ftmp2 = 0.0;
00495        for (i=0; i<subl; i++) {
00496            ftmp1 += target[i]*regressor[i];
00497            ftmp2 += regressor[i]*regressor[i];
00498        }
00499 
00500        if (ftmp1 > 0.0) {
00501            return (float)(ftmp1*ftmp1/ftmp2);
00502        }
00503 
00504 
00505 
00506 
00507 
00508        else {
00509            return (float)0.0;
00510        }
00511    }


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