t[i] = SHR(target[i],sig_shift);
t[i] = EXTRACT16(SHR32(target[i],sig_shift));
static spx_word64_t pitch_gain_search_3tap(const spx_sig_t target[],       /* Target vector */const spx_coef_t ak[],          /* LPCs for this subframe */const spx_coef_t awk1[],        /* Weighted LPCs #1 for this subframe */const spx_coef_t awk2[],        /* Weighted LPCs #2 for this subframe */spx_sig_t exc[],                /* Excitation */const void *par,int   pitch,                    /* Pitch value */int   p,                        /* Number of LPC coeffs */int   nsf,                      /* Number of samples in subframe */SpeexBits *bits,char *stack,const spx_sig_t *exc2,const spx_word16_t *r,spx_sig_t *new_target,int  *cdbk_index,int cdbk_offset){   int i,j;   VARDECL(spx_sig_t *tmp1);   VARDECL(spx_sig_t *tmp2);   spx_sig_t *x[3];   spx_sig_t *e[3];   spx_word32_t corr[3];   spx_word32_t A[3][3];   int   gain_cdbk_size;   const signed char *gain_cdbk;   spx_word16_t gain[3];   spx_word64_t err;   const ltp_params *params;   params = (const ltp_params*) par;   gain_cdbk_size = 1<<params->gain_bits;   gain_cdbk = params->gain_cdbk + 3*gain_cdbk_size*cdbk_offset;   ALLOC(tmp1, 3*nsf, spx_sig_t);   ALLOC(tmp2, 3*nsf, spx_sig_t);   x[0]=tmp1;   x[1]=tmp1+nsf;   x[2]=tmp1+2*nsf;      e[0]=tmp2;   e[1]=tmp2+nsf;   e[2]=tmp2+2*nsf;   for (i=2;i>=0;i--)   {      int pp=pitch+1-i;      for (j=0;j<nsf;j++)      {         if (j-pp<0)            e[i][j]=exc2[j-pp];         else if (j-pp-pitch<0)            e[i][j]=exc2[j-pp-pitch];         else            e[i][j]=0;      }      if (i==2)         syn_percep_zero(e[i], ak, awk1, awk2, x[i], nsf, p, stack);      else {         for (j=0;j<nsf-1;j++)            x[i][j+1]=x[i+1][j];         x[i][0]=0;         for (j=0;j<nsf;j++)         {            x[i][j]=ADD32(x[i][j],SHL(MULT16_32_Q15(r[j], e[i][0]),1));         }      }   }#ifdef FIXED_POINT   {      /* If using fixed-point, we need to normalize the signals first */      spx_word16_t *y[3];      VARDECL(spx_word16_t *ytmp);      VARDECL(spx_word16_t *t);      spx_sig_t max_val=1;      int sig_shift;            ALLOC(ytmp, 3*nsf, spx_word16_t);#if 0      ALLOC(y[0], nsf, spx_word16_t);      ALLOC(y[1], nsf, spx_word16_t);      ALLOC(y[2], nsf, spx_word16_t);#else      y[0] = ytmp;      y[1] = ytmp+nsf;      y[2] = ytmp+2*nsf;#endif      ALLOC(t, nsf, spx_word16_t);      for (j=0;j<3;j++)      {         for (i=0;i<nsf;i++)         {            spx_sig_t tmp = x[j][i];            if (tmp<0)               tmp = -tmp;            if (tmp > max_val)               max_val = tmp;         }      }      for (i=0;i<nsf;i++)      {         spx_sig_t tmp = target[i];         if (tmp<0)            tmp = -tmp;         if (tmp > max_val)            max_val = tmp;      }      sig_shift=0;      while (max_val>16384)      {         sig_shift++;         max_val >>= 1;      }      for (j=0;j<3;j++)      {         for (i=0;i<nsf;i++)         {            y[j][i] = SHR(x[j][i],sig_shift);         }      }           for (i=0;i<nsf;i++)      {         t[i] = SHR(target[i],sig_shift);      }      for (i=0;i<3;i++)         corr[i]=inner_prod(y[i],t,nsf);            for (i=0;i<3;i++)         for (j=0;j<=i;j++)            A[i][j]=A[j][i]=inner_prod(y[i],y[j],nsf);   }#else   {      for (i=0;i<3;i++)         corr[i]=inner_prod(x[i],target,nsf);            for (i=0;i<3;i++)         for (j=0;j<=i;j++)            A[i][j]=A[j][i]=inner_prod(x[i],x[j],nsf);   }#endif   {      spx_word32_t C[9];      const signed char *ptr=gain_cdbk;      int best_cdbk=0;      spx_word32_t best_sum=0;      C[0]=corr[2];      C[1]=corr[1];      C[2]=corr[0];      C[3]=A[1][2];      C[4]=A[0][1];      C[5]=A[0][2];      C[6]=A[2][2];      C[7]=A[1][1];      C[8]=A[0][0];#ifndef FIXED_POINT      C[6]*=.5;      C[7]*=.5;      C[8]*=.5;#endif      for (i=0;i<gain_cdbk_size;i++)      {         spx_word32_t sum=0;         spx_word16_t g0,g1,g2;         ptr = gain_cdbk+3*i;         g0=ptr[0]+32;         g1=ptr[1]+32;         g2=ptr[2]+32;         sum = ADD32(sum,MULT16_32_Q14(MULT16_16_16(g0,64),C[0]));         sum = ADD32(sum,MULT16_32_Q14(MULT16_16_16(g1,64),C[1]));         sum = ADD32(sum,MULT16_32_Q14(MULT16_16_16(g2,64),C[2]));         sum = SUB32(sum,MULT16_32_Q14(MULT16_16_16(g0,g1),C[3]));         sum = SUB32(sum,MULT16_32_Q14(MULT16_16_16(g2,g1),C[4]));         sum = SUB32(sum,MULT16_32_Q14(MULT16_16_16(g2,g0),C[5]));         sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g0,g0),C[6]));         sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g1,g1),C[7]));         sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g2,g2),C[8]));         /* We could force "safe" pitch values to handle packet loss better */         if (sum>best_sum || i==0)         {            best_sum=sum;            best_cdbk=i;         }      }#ifdef FIXED_POINT      gain[0] = 32+(spx_word16_t)gain_cdbk[best_cdbk*3];      gain[1] = 32+(spx_word16_t)gain_cdbk[best_cdbk*3+1];      gain[2] = 32+(spx_word16_t)gain_cdbk[best_cdbk*3+2];#else      gain[0] = 0.015625*gain_cdbk[best_cdbk*3]  + .5;      gain[1] = 0.015625*gain_cdbk[best_cdbk*3+1]+ .5;      gain[2] = 0.015625*gain_cdbk[best_cdbk*3+2]+ .5;#endif      *cdbk_index=best_cdbk;   }#ifdef FIXED_POINT   for (i=0;i<nsf;i++)     exc[i]=SHL(MULT16_32_Q15(SHL(gain[0],7),e[2][i])+MULT16_32_Q15(SHL(gain[1],7),e[1][i])+MULT16_32_Q15(SHL(gain[2],7),e[0][i]),2);      err=0;   for (i=0;i<nsf;i++)   {      spx_word16_t perr2;      spx_sig_t tmp = SHL((MULT16_32_Q15(SHL(gain[0],7),x[2][i])+MULT16_32_Q15(SHL(gain[1],7),x[1][i])+MULT16_32_Q15(SHL(gain[2],7),x[0][i])),2);      spx_sig_t perr=SUB32(target[i],tmp);      new_target[i] = SUB32(target[i], tmp);      perr2 = PSHR(perr,15);      err = ADD64(err,MULT16_16(perr2,perr2));         }#else   for (i=0;i<nsf;i++)      exc[i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][i];      err=0;   for (i=0;i<nsf;i++)   {      spx_sig_t tmp = gain[2]*x[0][i]+gain[1]*x[1][i]+gain[0]*x[2][i];      new_target[i] = target[i] - tmp;      err+=new_target[i]*new_target[i];   }#endif   return err;}