private float Pitch_gain_search_3tap(float[] target, float[] ak, float[] awk1, float[] awk2, float[] exc, int es, int pitch, int p, int nsf, Bits bits, float[] exc2, int e2s, float[] r, int[] cdbk_index) { float[] array = new float[3]; float[][] array2 = this.CreateJaggedArray <float>(3, 3); int num = 1 << this.gain_bits; float[][] array3 = this.CreateJaggedArray <float>(3, nsf); this.e = this.CreateJaggedArray <float>(3, nsf); for (int i = 2; i >= 0; i--) { int num2 = pitch + 1 - i; for (int j = 0; j < nsf; j++) { if (j - num2 < 0) { this.e[i][j] = exc2[e2s + j - num2]; } else if (j - num2 - pitch < 0) { this.e[i][j] = exc2[e2s + j - num2 - pitch]; } else { this.e[i][j] = 0f; } } if (i == 2) { Filters.Syn_percep_zero(this.e[i], 0, ak, awk1, awk2, array3[i], nsf, p); } else { for (int j = 0; j < nsf - 1; j++) { array3[i][j + 1] = array3[i + 1][j]; } array3[i][0] = 0f; for (int j = 0; j < nsf; j++) { array3[i][j] += this.e[i][0] * r[j]; } } } for (int i = 0; i < 3; i++) { array[i] = Ltp.Inner_prod(array3[i], 0, target, 0, nsf); } for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++) { array2[i][j] = (array2[j][i] = Ltp.Inner_prod(array3[i], 0, array3[j], 0, nsf)); } } float[] array4 = new float[9]; int num3 = 0; float num4 = 0f; array4[0] = array[2]; array4[1] = array[1]; array4[2] = array[0]; array4[3] = array2[1][2]; array4[4] = array2[0][1]; array4[5] = array2[0][2]; array4[6] = array2[2][2]; array4[7] = array2[1][1]; array4[8] = array2[0][0]; for (int i = 0; i < num; i++) { float num5 = 0f; int num6 = 3 * i; float num7 = 0.015625f * (float)this.gain_cdbk[num6] + 0.5f; float num8 = 0.015625f * (float)this.gain_cdbk[num6 + 1] + 0.5f; float num9 = 0.015625f * (float)this.gain_cdbk[num6 + 2] + 0.5f; num5 += array4[0] * num7; num5 += array4[1] * num8; num5 += array4[2] * num9; num5 -= array4[3] * num7 * num8; num5 -= array4[4] * num9 * num8; num5 -= array4[5] * num9 * num7; num5 -= 0.5f * array4[6] * num7 * num7; num5 -= 0.5f * array4[7] * num8 * num8; num5 -= 0.5f * array4[8] * num9 * num9; if (num5 > num4 || i == 0) { num4 = num5; num3 = i; } } this.gain[0] = 0.015625f * (float)this.gain_cdbk[num3 * 3] + 0.5f; this.gain[1] = 0.015625f * (float)this.gain_cdbk[num3 * 3 + 1] + 0.5f; this.gain[2] = 0.015625f * (float)this.gain_cdbk[num3 * 3 + 2] + 0.5f; cdbk_index[0] = num3; for (int i = 0; i < nsf; i++) { exc[es + i] = this.gain[0] * this.e[2][i] + this.gain[1] * this.e[1][i] + this.gain[2] * this.e[0][i]; } float num10 = 0f; float num11 = 0f; for (int i = 0; i < nsf; i++) { num10 += target[i] * target[i]; } for (int i = 0; i < nsf; i++) { num11 += (target[i] - this.gain[2] * array3[0][i] - this.gain[1] * array3[1][i] - this.gain[0] * array3[2][i]) * (target[i] - this.gain[2] * array3[0][i] - this.gain[1] * array3[1][i] - this.gain[0] * array3[2][i]); } return(num11); }
protected internal static void Open_loop_nbest_pitch(float[] sw, int swIdx, int start, int end, int len, int[] pitch, float[] gain, int N) { float[] array = new float[N]; float[] array2 = new float[end - start + 1]; float[] array3 = new float[end - start + 2]; float[] array4 = new float[end - start + 1]; for (int i = 0; i < N; i++) { array[i] = -1f; gain[i] = 0f; pitch[i] = start; } array3[0] = Ltp.Inner_prod(sw, swIdx - start, sw, swIdx - start, len); float num = Ltp.Inner_prod(sw, swIdx, sw, swIdx, len); for (int i = start; i <= end; i++) { array3[i - start + 1] = array3[i - start] + sw[swIdx - i - 1] * sw[swIdx - i - 1] - sw[swIdx - i + len - 1] * sw[swIdx - i + len - 1]; if (array3[i - start + 1] < 1f) { array3[i - start + 1] = 1f; } } for (int i = start; i <= end; i++) { array2[i - start] = 0f; array4[i - start] = 0f; } for (int i = start; i <= end; i++) { array2[i - start] = Ltp.Inner_prod(sw, swIdx, sw, swIdx - i, len); array4[i - start] = array2[i - start] * array2[i - start] / (array3[i - start] + 1f); } for (int i = start; i <= end; i++) { if (array4[i - start] > array[N - 1]) { float num2 = array2[i - start] / (array3[i - start] + 10f); float num3 = (float)Math.Sqrt((double)(num2 * array2[i - start] / (num + 10f))); if (num3 > num2) { num3 = num2; } if (num3 < 0f) { num3 = 0f; } for (int j = 0; j < N; j++) { if (array4[i - start] > array[j]) { for (int k = N - 1; k > j; k--) { array[k] = array[k - 1]; pitch[k] = pitch[k - 1]; gain[k] = gain[k - 1]; } array[j] = array4[i - start]; pitch[j] = i; gain[j] = num3; break; } } } } }