{ float tmp1=0,tmp2=0; for (i=0;i<nsf;i++) tmp1+=target[i]*target[i]; for (i=0;i<nsf;i++) tmp2+=(target[i]-gain[2]*x[0][i]-gain[1]*x[1][i]-gain[0]*x[2][i]) * (target[i]-gain[2]*x[0][i]-gain[1]*x[1][i]-gain[0]*x[2][i]);
err1=0; err2=0; for (i=0;i<nsf;i++) err1+=target[i]*target[i]; for (i=0;i<nsf;i++) err2+=(target[i]-gain[2]*x[0][i]-gain[1]*x[1][i]-gain[0]*x[2][i]) * (target[i]-gain[2]*x[0][i]-gain[1]*x[1][i]-gain[0]*x[2][i]);
float pitch_gain_search_3tap(float target[],                 /* Target vector */float ak[],                     /* LPCs for this subframe */float awk1[],                   /* Weighted LPCs #1 for this subframe */float awk2[],                   /* Weighted LPCs #2 for this subframe */float exc[],                    /* Excitation */void *par,int   pitch,                    /* Pitch value */int   p,                        /* Number of LPC coeffs */int   nsf,                      /* Number of samples in subframe */SpeexBits *bits,float *stack,float *exc2,int  *cdbk_index){   int i,j;   float *tmp, *tmp2;   float *x[3];   float *e[3];   float corr[3];   float A[3][3];   float gain[3];   int   gain_cdbk_size;   float *gain_cdbk;   ltp_params *params;   params = (ltp_params*) par;   gain_cdbk=params->gain_cdbk;   gain_cdbk_size=1<<params->gain_bits;   tmp = PUSH(stack, 3*nsf);   tmp2 = PUSH(stack, 3*nsf);   x[0]=tmp;   x[1]=tmp+nsf;   x[2]=tmp+2*nsf;   e[0]=tmp2;   e[1]=tmp2+nsf;   e[2]=tmp2+2*nsf;      for (i=0;i<3;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;      }      residue_zero(e[i],awk1,x[i],nsf,p);      syn_filt_zero(x[i],ak,x[i],nsf,p);      syn_filt_zero(x[i],awk2,x[i],nsf,p);   }   for (i=0;i<3;i++)      corr[i]=xcorr(x[i],target,nsf);      for (i=0;i<3;i++)      for (j=0;j<=i;j++)         A[i][j]=A[j][i]=xcorr(x[i],x[j],nsf);      {      int j;      float C[9];      float *ptr=gain_cdbk;      int best_cdbk=0;      float 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];            for (i=0;i<gain_cdbk_size;i++)      {         float sum=0;         ptr = gain_cdbk+12*i;         for (j=0;j<9;j++)            sum+=C[j]*ptr[j+3];         if (0) {            float tot=ptr[0]+ptr[1]+ptr[2];            if (tot < 1.1)               sum *= 1+.15*tot;         }         if (sum>best_sum || i==0)         {            best_sum=sum;            best_cdbk=i;         }      }      gain[0] = gain_cdbk[best_cdbk*12];      gain[1] = gain_cdbk[best_cdbk*12+1];      gain[2] = gain_cdbk[best_cdbk*12+2];      *cdbk_index=best_cdbk;   }      for (i=0;i<nsf;i++)      exc[i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][i];#ifdef DEBUG   printf ("3-tap pitch = %d, gains = [%f %f %f]\n",pitch, gain[0], gain[1], gain[2]);#endif   {      float tmp1=0,tmp2=0;      for (i=0;i<nsf;i++)         tmp1+=target[i]*target[i];      for (i=0;i<nsf;i++)         tmp2+=(target[i]-gain[2]*x[0][i]-gain[1]*x[1][i]-gain[0]*x[2][i])         * (target[i]-gain[2]*x[0][i]-gain[1]*x[1][i]-gain[0]*x[2][i]);#ifdef DEBUG      printf ("prediction gain = %f\n",tmp1/(tmp2+1));#endif      return tmp2;   }}