⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbsearch.c

📁 AMR-NB 的编码实现,纯C, VC下建立工程即可用.
💻 C
📖 第 1 页 / 共 5 页
字号:
    Word16 h[],         /* i : impulse response of weighted synthesis filter */                        /*     h[-L_subfr..-1] must be set to zero.          */    Word16 T0,          /* i : Pitch lag                                     */    Word16 pitch_sharp, /* i : Last quantized pitch gain                     */    Word16 code[],      /* o : Innovative codebook                           */    Word16 y[],         /* o : filtered fixed codebook excitation            */    Word16 * sign       /* o : Signs of 4 pulses                             */){
    Word16 codvec[NB_PULSE_4i40_17BITS];
    Word16 dn[L_CODE], dn2[L_CODE], dn_sign[L_CODE];    Word16 rr[L_CODE][L_CODE];    Word16 i, index, sharp;    sharp = (pitch_sharp<< 1);       if ( T0 <  L_CODE)    {       for (i = T0; i < L_CODE; i++)       {          h[i] +=  (h[i - T0]*sharp >> 15 );        }    }        cor_h_x2(h, x, dn, 1, NB_TRACK, STEP);
    set_sign(dn, dn_sign, dn2, 4);    cor_h(h, dn_sign, rr);    search_4i40_17BITS(dn, dn2, rr, codvec);
                                     index = build_code_4i40_17BITS(codvec, dn_sign, code, h, y, sign);
  /*-----------------------------------------------------------------*  * Compute innovation vector gain.                                 *  * Include fixed-gain pitch contribution into code[].              *  *-----------------------------------------------------------------*/      if (T0 < L_CODE )    {       for (i = T0; i < L_CODE; i++) 	{          code[i] +=  (code[i - T0]*sharp >> 15 );       }    }    return index;
}/**********************************************************************************                         PRIVATE PROGRAM CODE*********************************************************************************//************************************************************************* * *  FUNCTION  search_4i40() * *  PURPOSE: Search the best codevector; determine positions of the 4 pulses *           in the 40-sample frame. * *************************************************************************/
static void search_4i40_17BITS(
    Word16 dn[],         /* i : correlation between target and h[]  */    Word16 dn2[],        /* i : maximum of corr. in each track.     */    Word16 rr[][L_CODE], /* i : matrix of autocorrelation           */    Word16 codvec[]      /* o : algebraic codebook vector           */){
    Word16 i0, i1, i2, i3;    Word16 ix = 0; /* initialization only needed to keep gcc silent */    Word16 ps = 0; /* initialization only needed to keep gcc silent */    Word16 i, pos, track, ipos[NB_PULSE_4i40_17BITS];
    Word16 psk, ps0, ps1, sq, sq1;    Word16 alpk, alp, alp_16;    Word32 alp0, alp1;

    Word16 *pdn = dn, *pdn2 = dn2, *pcodvec = codvec;
  
        /* Default value */    psk = -1;               alpk = 1;          
    pcodvec[0] = 0;   pcodvec[1] = 1; pcodvec[2] = 2; pcodvec[3] = 3; 

    
    for (track = 3; track < 5; track++) {    /* fix starting position */       ipos[0] = 0;            ipos[1] = 1;           ipos[2] = 2;            ipos[3] = track;               /*------------------------------------------------------------------*        * main loop: try 4 tracks.                                         *        *------------------------------------------------------------------*/              for (i = 0; i < NB_PULSE_4i40_17BITS; i++)
       {          /*----------------------------------------------------------------*           * i0 loop: try 4 positions (use position with max of corr.).     *           *----------------------------------------------------------------*/                             for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP)          {                       if (pdn2[i0] >= 0)
             {                ps0 = pdn[i0]; 
                alp0 = (rr[i0][i0]<<14 );                             /*----------------------------------------------------------------*                 * i1 loop: 8 positions.                                          *                 *----------------------------------------------------------------*/                                sq = -1;                         alp = 1;                         ps = 0;                          ix = ipos[1];                                       /* initialize 4 index for next loop. */                /*-------------------------------------------------------------------*                 *  These index have low complexity address computation because      *                 *  they are, in fact, pointers with fixed increment.  For example,  *                 *  "rr[i0][i3]" is a pointer initialized to "&rr[i0][ipos[3]]"      *                 *  and incremented by "STEP".                                       *                 *-------------------------------------------------------------------*/                                               for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP)                {                   ps1 = ps0+ pdn[i1] ;   /* idx increment = STEP */
                                      /* alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1]; */                                      alp1 = alp0 + (rr[i1][i1]<<14); /* idx incr = STEP */                   alp1 = alp1 + (rr[i0][i1]<<15); /* idx incr = STEP */		  		     sq1 = (ps1* ps1>>15 );//;                                      alp_16 = (alp1+0x00008000)>>16 ;                                                        if (alp*sq1 > sq*alp_16)                   {                      sq = sq1;                             ps = ps1;                             alp = alp_16;                          ix = i1;                             }                }                i1 = ix;                                                /*----------------------------------------------------------------*                 * i2 loop: 8 positions.                                          *                 *----------------------------------------------------------------*/                                ps0 = ps;                                alp0 = alp<<14 ;               
                sq = -1;                                alp = 1;                                 ps = 0;                                   ix = ipos[2];                                                                /* initialize 4 index for next loop (see i1 loop) */                                               for (i2 = ipos[2]; i2 < L_CODE; i2 += STEP)                {                   ps1 = (ps0 + pdn[i2]); /* index increment = STEP */
                   alp1 = alp0 + (rr[i2][i2]<<12); 
                   alp1 = alp1 + (rr[i1][i2]<<13);                     alp1 = alp1 + (rr[i0][i2]<<13); 		                       sq1 =(ps1* ps1 >>15);                    alp_16 = (alp1 + 0x00008000)>>16;
                 
                   if (alp*sq1 > sq*alp_16)                   {                      sq = sq1;                            ps = ps1;                               alp = alp_16;                           ix = i2;                            }                }                i2 = ix;                                               /*----------------------------------------------------------------*                 * i3 loop: 8 positions.                                          *                 *----------------------------------------------------------------*/                                ps0 = ps;                               alp0 = alp<<16;             				                 sq = -1;                                alp = 1;                                 ps = 0;                                  ix = ipos[3];                                                               /* initialize 5 index for next loop (see i1 loop) */                                               for (i3 = ipos[3]; i3 < L_CODE; i3 += STEP)                {                   ps1 = ps0 + pdn[i3]; /* index increment = STEP */
                                      /* alp1 = alp0 + rr[i0][i3] + rr[i1][i3] + rr[i2][i3] + 1/2*rr[i3][i3]; */                                       alp1 = alp0+(rr[i3][i3]<<12);                   alp1 = alp1+(rr[i2][i3]<<13);                     alp1 = alp1+(rr[i1][i3]<<13);                     alp1 = alp1+(rr[i0][i3]<<13);                                     sq1 = (ps1*ps1 >>15) ;                  // alp_16 = round(alp1);				                      alp_16 =  (alp1+ 0x00008000)>>16 ;                                    //  s = (alp*sq1 - sq*alp_16)<<1 ;                                                       if (alp*sq1 > sq*alp_16)                   {                      sq = sq1;                             ps = ps1;                            alp = alp_16;                          ix = i3;                            }                }                                                /*----------------------------------------------------------------*                 * memorise codevector if this one is better than the last one.   *                 *----------------------------------------------------------------*/                //(alpk* sq -psk*alp)<<1 ;                                              if (alpk* sq  > psk*alp)                {                   psk = sq;                              alpk = alp;                            pcodvec[0] = i0;     
                   pcodvec[1] = i1;     
                   pcodvec[2] = i2;     
                   pcodvec[3] = ix;     
                }             }          }                    /*----------------------------------------------------------------*           * Cyclic permutation of i0,i1,i2 and i3.                         *           *----------------------------------------------------------------*/                    pos = ipos[3];                           ipos[3] = ipos[2];                        ipos[2] = ipos[1];                        ipos[1] = ipos[0];                       ipos[0] = pos;                    }    }
    return;}/************************************************************************* * *  FUNCTION:  build_code() * *  PURPOSE: Builds the codeword, the filtered codeword and index of the *           codevector, based on the signs and positions of 4 pulses. * *************************************************************************/static Word16build_code_4i40_17BITS(
    Word16 codvec[],  /* i : position of pulses                            */    Word16 dn_sign[], /* i : sign of pulses                                */    Word16 cod[],     /* o : innovative code vector                        */    Word16 h[],       /* i : impulse response of weighted synthesis filter */    Word16 y[],       /* o : filtered innovative code                      */    Word16 sign[]     /* o : index of 4 pulses (sign+position)             */){
    Word16 i, j, k, track, index, _sign[NB_PULSE_4i40_17BITS], indx, rsign;
    Word16 *p0, *p1, *p2, *p3;
	
    Word16 *pcodvec = codvec, *pdn_sign = dn_sign, *pcod = cod, *ph = h, *py = y, *psign = sign;
	const Word16 *pgray = gray;

    memset(pcod, 0 ,80);
    indx = 0;                                   rsign = 0;                                for (k = 0; k < NB_PULSE_4i40_17BITS; k++)
    {       i = pcodvec[k];           
       j = pdn_sign[i];           
              index = (i*6554 >> 15);    /* index = pos/5 */	          /* track = pos%5 */       track = i - (Word16)(index*5);                     index = pgray[index];                
                   if ( track ==1 )          index <<=  3 ;       else if (track==  2 )       {                   index <<= 6 ;       }       else if ( track ==  3)       {         	          index <<= 10 ;       }       else if (track ==  4)       {         			          track = 3;                             index = (index<<10)+512;       }                    if (j > 0)       {          pcod[i] = 8191;                  
          _sign[k] = 32767;                        rsign += (1<<track) ;		         } else       {          pcod[i] = -8192;                 
          _sign[k] = (Word16) - 32768L;          }              indx +=  index ;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -