// file: clpc_cal_8.cc // // this function computes the prediction coefficients of a signal // // system include file // #include #include // local include file // #include "global_constants.h" #include "calculate_lpc_constants.h" #include "calculate_lpc.h" // function: calculate_pred_coeff_cc // // arguments: // float**& pred_coeffs_a: (output) buffer contains the prediction // coefficients of the signal // float*& gain_a: (output) predictor gain // float** autocorr_coeffs_a: (input) buffer of autocorrelation coefficients // int num_chans_a: (input) number of channels // int lp_order_a: (input) type of window // int debug_mode_a: (input) debug level // // return: an int to indicate status // // this function calculates the predictor coefficients of a signal using // the Levinson-Durbin recursion (see speech note) // // int calculate_pred_coeff_cc (float**& pred_coeffs_a, float*& gain_a, float** autocorr_coeffs_a, int num_chans_a, int lp_order_a, int debug_mode_a) { // declare buffer for reflection and previous predictor coefficients // int num_coeffs = lp_order_a + 1; float* refl_coeffs = new float[num_coeffs]; float* prev_pred_coeffs = new float[num_coeffs]; float lp_error; for (int chan = 0; chan < num_chans_a; chan++) { // initialize buffer for reflection and previous predictor coefficients // memset(prev_pred_coeffs, 0, sizeof(float) * num_coeffs); memset(refl_coeffs, 0, sizeof(float) * num_coeffs); // initialize the error term // lp_error = autocorr_coeffs_a[chan][0]; // find the predictor coefficients using the Levinson-Durbin recursion // for (int index = 1; index <= lp_order_a; index++) { refl_coeffs[index] = 0; // calculate and update the reflection coefficients // for (int iter = 1; iter < index; iter++) { refl_coeffs[index] -= prev_pred_coeffs[iter] * autocorr_coeffs_a[chan][index - iter]; } refl_coeffs[index] -= autocorr_coeffs_a[chan][index]; refl_coeffs[index] /= lp_error; // calculate and update the predictor coefficients // pred_coeffs_a[chan][index] = refl_coeffs[index]; for (int iter = 1; iter < index; iter++) { pred_coeffs_a[chan][iter] = prev_pred_coeffs[iter] + refl_coeffs[index] * prev_pred_coeffs[index - iter]; } // calculate and update the error // lp_error *= 1.0 - refl_coeffs[index] * refl_coeffs[index]; // update the temporary predictor coeffs // for (int iter = 1; iter <= index; iter++) { prev_pred_coeffs[iter] = pred_coeffs_a[chan][iter]; } } // invert the prediction coefficients // for (int index = 1; index <= lp_order_a; index++) { pred_coeffs_a[chan][index] *= -1; } // set the gain value // gain_a[chan] = lp_error; } if (debug_mode_a > DEBUG_FULL) { for (int chan = 0; chan < num_chans_a; chan++) { for (int coeff = 0; coeff < num_coeffs; coeff++) { fprintf(stdout, "chan %d :: prediction coeff [%d] = %.6f\n", chan, coeff, pred_coeffs_a[chan][coeff]); } } fprintf(stdout, "\n"); } // exit gracefully // return TRUE; }