energy[i-start+1] = energy[i-start] + sw[swIdx-i-1]*sw[swIdx-i-1] - sw[swIdx-i+len-1]*sw[swIdx-i+len-1]; if (energy[i-start+1] < 1) energy[i-start+1]=1;
energy[i - start + 1] = energy[i - start] + sw[swIdx - i - 1] * sw[swIdx - i - 1] - sw[swIdx - i + len - 1] * sw[swIdx - i + len - 1]; if (energy[i - start + 1] < 1.0f) energy[i - start + 1] = 1.0f;
  protected static void open_loop_nbest_pitch(final float[] sw,                                              final int swIdx,                                              final int start,                                              final int end,                                              final int len,                                              final int[] pitch,                                              final float[] gain,                                              final int N)  {    int i, j, k;    /*float corr=0;*/    /*float energy;*/    float[] best_score;    float e0;    float[] corr, energy, score;    best_score = new float[N];    corr = new float[end-start+1];    energy = new float[end-start+2];    score = new float[end-start+1];    for (i=0; i<N; i++) {      best_score[i]=-1;      gain[i]=0;      pitch[i]=start;    }    energy[0]=inner_prod(sw, swIdx-start, sw, swIdx-start, len);    e0=inner_prod(sw, swIdx, sw, swIdx, len);    for (i=start; i<=end; i++) {      /* Update energy for next pitch*/      energy[i-start+1] = energy[i-start] + sw[swIdx-i-1]*sw[swIdx-i-1] - sw[swIdx-i+len-1]*sw[swIdx-i+len-1];      if (energy[i-start+1] < 1)        energy[i-start+1]=1;     }    for (i=start; i<=end; i++) {      corr[i-start]=0;      score[i-start]=0;    }    for (i=start; i<=end; i++) {      /* Compute correlation*/      corr[i-start]=inner_prod(sw, swIdx, sw, swIdx-i, len);      score[i-start]=corr[i-start]*corr[i-start]/(energy[i-start]+1);    }    for (i=start; i<=end; i++) {      if (score[i-start] > best_score[N-1]) {        float g1, g;        g1 = corr[i-start]/(energy[i-start]+10);        g = (float) Math.sqrt(g1*corr[i-start]/(e0+10));        if (g>g1)          g=g1;        if (g<0)          g=0;        for (j=0; j<N; j++) {          if (score[i-start] > best_score[j]) {            for (k=N-1; k>j; k--) {              best_score[k]=best_score[k-1];              pitch[k]=pitch[k-1];              gain[k] = gain[k-1];            }            best_score[j]=score[i-start];            pitch[j]=i;            gain[j]=g;            break;          }        }      }    }  }