for (i=0; i<nsf; i++) exc[es+i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][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]);
for (i = 0; i < nsf; i++) exc[es + i] = gain[0] * e[2][i] + gain[1] * e[1][i] + gain[2] * e[0][i];
  private float pitch_gain_search_3tap(final float[] target,                                       final float[] ak,                                       final float[] awk1,                                       final float[] awk2,                                       final float[] exc,                                       final int     es,                                       final int     pitch,                                       final int     p,                                       final int     nsf,                                       final Bits    bits,                                       final float[] exc2,                                       final int     e2s,                                       final float[] r,                                       final int[]   cdbk_index                                       )  {    int i,j;    float[][] x;    //      float[][] e;    float[] corr = new float[3];    float[][] A = new float[3][3];    int   gain_cdbk_size;    float err1,err2;    gain_cdbk_size=1<<gain_bits;    x = new float[3][nsf];    e = new float[3][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[e2s+j-pp];        else if (j-pp-pitch<0)          e[i][j]=exc2[e2s+j-pp-pitch];        else          e[i][j]=0;      }      if (i==2)        Filters.syn_percep_zero(e[i], 0, ak, awk1, awk2, x[i], nsf, p);      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]+=e[i][0]*r[j];      }    }    for (i=0; i<3; i++)      corr[i] = inner_prod(x[i], 0, target, 0, nsf);    for (i=0; i<3; i++)      for (j=0; j<=i; j++)        A[i][j] = A[j][i] = inner_prod(x[i], 0, x[j], 0, nsf);    {      float[] C = new float[9];      int ptr=0;      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;        float g0,g1,g2;        ptr = 3*i;        g0=0.015625f*gain_cdbk[ptr]+.5f;        g1=0.015625f*gain_cdbk[ptr+1]+.5f;        g2=0.015625f*gain_cdbk[ptr+2]+.5f;        sum += C[0]*g0;        sum += C[1]*g1;        sum += C[2]*g2;        sum -= C[3]*g0*g1;        sum -= C[4]*g2*g1;        sum -= C[5]*g2*g0;        sum -= .5f*C[6]*g0*g0;        sum -= .5f*C[7]*g1*g1;        sum -= .5f*C[8]*g2*g2;        /* If true, force "safe" pitch values to handle packet loss better */        if (false) {          float tot = Math.abs(gain_cdbk[ptr+1]);          if (gain_cdbk[ptr]>0)            tot+=gain_cdbk[ptr];          if (gain_cdbk[ptr+2]>0)            tot+=gain_cdbk[ptr+2];          if (tot>1)            continue;        }        if (sum>best_sum || i==0)        {          best_sum=sum;          best_cdbk=i;        }      }      gain[0] = 0.015625f*gain_cdbk[best_cdbk*3]  + .5f;      gain[1] = 0.015625f*gain_cdbk[best_cdbk*3+1]+ .5f;      gain[2] = 0.015625f*gain_cdbk[best_cdbk*3+2]+ .5f;      cdbk_index[0]=best_cdbk;    }        for (i=0; i<nsf; i++)      exc[es+i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][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]);    return err2;  }