public static float wld(final float[] lpc,
                          final float[] ac,
                          final float[] ref,
                          final int p)
  {
    int i, j;
    float r, error = ac[0];
    if (ac[0] == 0) {
      for (i=0; i<p; i++)
        ref[i] = 0;
      return 0;
    }
    for (i = 0; i < p; i++) {
      /* Sum up this iteration's reflection coefficient. */
      r = -ac[i + 1];
      for (j = 0; j < i; j++) r -= lpc[j] * ac[i - j];
      ref[i] = r /= error;
      /*  Update LPC coefficients and total error. */
      lpc[i] = r;
      for (j = 0; j < i/2; j++) {
        float tmp  = lpc[j];
        lpc[j]     += r * lpc[i-1-j];
        lpc[i-1-j] += r * tmp;
      }
      if ((i % 2) != 0)
        lpc[j] += lpc[j] * r;
      error *= 1.0 - r * r;
    }
    return error;
  }