⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pred_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/algo/Prediction/pred_05.cc// version: $Id: pred_05.cc,v 1.21 2002/04/01 20:04:19 gao Exp $//// isip include files//#include "Prediction.h"// method: apply//// arguments://  Vector<AlgorithmData>& output: (output) output data//  const Vector< CircularBuffer<AlgorithmData> >& input: (input) input data//// return: a boolean value indicating status//// this method computes the predictor coefficients for input data//boolean Prediction::apply(Vector<AlgorithmData>& output_a,			  const Vector< CircularBuffer<AlgorithmData> >&			  input_a) {  // determine the number of input channels and force the output to be  // that number  //  long len = input_a.length();  output_a.setLength(len);  boolean res = true;  // start the debugging output  //  displayStart(this);    // loop over the channels and call the compute method  //  for (long c = 0; c < len; c++) {        // display the channel number    //    displayChannel(c);        // branch on input type - covariance takes matrix as input    //    if (input_a(c)(0).getCoefType() == AlgorithmData::COVARIANCE) {            // call AlgorithmData::makeVectorFloat to force the output vector for      // this channel to be a VectorFloat.      // call AlgorithmData::getMatrixFloat on the input for this channel to      // check that the input is already a MatrixFloat and return that      // vector.      //            res &= compute(output_a(c).makeVectorFloat(),		     input_a(c)(0).getMatrixFloat(),		     AlgorithmData::COVARIANCE, c);    }      else {      // call AlgorithmData::makeVectorFloat to force the output vector for      // this channel to be a VectorFloat.      // call AlgorithmData::getVectorFloat on the input for this channel to      // check that the input is already a VectorFloat and return that      // vector.      //       res &= compute(output_a(c).makeVectorFloat(),		     input_a(c)(0).getVectorFloat(),		     input_a(c)(0).getCoefType(), c);    }    // set the coefficient type for the output    //        output_a(c).setCoefType(AlgorithmData::PREDICTION);      }  // finish the debugging output  //  displayFinish(this);  // exit gracefully  //  return res;  }// method: compute//// arguments://  VectorFloat& output: (output) predictor or reflection coefficents//  const VectorFloat& input: (input) input data//  AlgorithmData::COEF_TYPE input_coef_type: (input) type of input//  long channel_index: (input) channel number//// return: a boolean value indicating status//// this method computes the predictor coefficents for the given input data//boolean Prediction::compute(VectorFloat& output_a,			    const VectorFloat& input_a,			    AlgorithmData::COEF_TYPE input_coef_type_a,			    long channel_index_a) {    // declare local variables  //  float err_energy;  boolean status = false;  // check order  //  if (order_d < (long)1) {    output_a.setLength(0);    return Error::handle(name(), L"compute", ERR_ORDER,			 __FILE__, __LINE__, Error::WARNING);  }  // branch on algorithm  //  Algorithm: AUTOCORRELATION  //  if (algorithm_d == AUTOCORRELATION) {    if (implementation_d == DURBIN) {      if (input_coef_type_a == AlgorithmData::CORRELATION) {	status = computeAutoDurbin(output_a, err_energy, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }  // Algorithm: LATTICE  //  else if (algorithm_d == LATTICE) {    if (implementation_d == BURG) {      if (input_coef_type_a == AlgorithmData::SIGNAL) {	status = computeLatticeBurg(output_a, err_energy, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }    // Algorithm: STEP_DOWN  //  else if (algorithm_d == REFLECTION) {    if (implementation_d == STEP_DOWN) {      if (input_coef_type_a == AlgorithmData::REFLECTION) {	status = computeReflectionStepDown(output_a, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }  // Algorithm: LATTICE  //  else if (algorithm_d == LOG_AREA_RATIO) {    if (implementation_d == KELLY_LOCHBAUM) {      if (input_coef_type_a == AlgorithmData::LOG_AREA_RATIO) {	status = computeLogAreaKellyLochbaum(output_a, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }    // else: error unknown algorithm  //  else {    return Error::handle(name(), L"compute", ERR_UNKALG,			 __FILE__, __LINE__);  }            // possibly display the data  //  display(output_a, input_a, name());    // exit gracefully  //  return status;}// method: compute//// arguments://  VectorFloat& output: (output) predictor or reflection coefficents//  const MatrixFloat& input: (input) input data (covariance matrix)//  AlgorithmData::COEF_TYPE input_coef_type: (input) type of input//  long channel_index: (input) channel number//// return: a boolean value indicating status//// this method computes the predictor coefficents from Covariance// input type//boolean Prediction::compute(VectorFloat& output_a,			    const MatrixFloat& input_a,			    AlgorithmData::COEF_TYPE input_coef_type_a,			    long channel_index_a) {  // declare local variables  //  float err_energy;  boolean status = false;    // check the order  //  if (order_d < (long)1) {    output_a.setLength(0);    return Error::handle(name(), L"compute", ERR_ORDER,			 __FILE__, __LINE__, Error::WARNING);  }  // branch on algorithm  //  if (algorithm_d == COVARIANCE) {    if (implementation_d == CHOLESKY) {      if (input_coef_type_a == AlgorithmData::COVARIANCE) {	status = computeCovarCholesky(output_a, err_energy, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }  // else: error unknown algorithm  //  else {    return Error::handle(name(), L"compute", ERR_UNKALG,			 __FILE__, __LINE__);  }        // possibly display the data  //  display(output_a, input_a, name());    // exit gracefully  //    return status;}// method: compute//// arguments://  VectorFloat& output: (output) predictor or reflection coefficents//  float& err_energy: (output) error energy//  const VectorFloat& input: (input) input data//  AlgorithmData::COEF_TYPE input_coef_type: (input) type of input//  long channel_index: (input) channel number//// return: a boolean value indicating status//// this method computes the predictor coefficents. it also outputs the// error energy.//boolean Prediction::compute(VectorFloat& output_a, float& err_energy_a,			    const VectorFloat& input_a,			    AlgorithmData::COEF_TYPE input_coef_type_a,			    long channel_index_a) {  // initialize err_energy a value since in some mode there is no  // err_energy output  //  err_energy_a = 0.0;  boolean status = false;    // check the order  //    if (order_d < (long)1) {    output_a.setLength(0);    return Error::handle(name(), L"compute", ERR_ORDER,			 __FILE__, __LINE__, Error::WARNING);  }  // branch on algorithm  //  Algorithm: AUTOCORRELATION  //  if (algorithm_d == AUTOCORRELATION) {    if (implementation_d == DURBIN) {      if (input_coef_type_a == AlgorithmData::CORRELATION) {	status = computeAutoDurbin(output_a, err_energy_a, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }  // Algorithm: LATTICE  //  else if (algorithm_d == LATTICE) {    if (implementation_d == BURG) {      if (input_coef_type_a == AlgorithmData::SIGNAL) {	status = computeLatticeBurg(output_a, err_energy_a, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }    // Algorithm: STEP_DOWN  //  else if (algorithm_d == REFLECTION) {    if (implementation_d == STEP_DOWN) {      if (input_coef_type_a == AlgorithmData::REFLECTION) {	status = computeReflectionStepDown(output_a, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }  // else: error unknown algorithm  //  else {    return Error::handle(name(), L"compute", ERR_UNKALG,			 __FILE__, __LINE__);  }        // possibly display the data  //  display(output_a, input_a, name());      // exit gracefully  //    return status;}// method: compute//// arguments://  VectorFloat& output: (output) predictor or reflection coefficents//  float& err_energy: (output) error energy//  const MatrixFloat& input: (input) input data (covariance matrix)//  AlgorithmData::COEF_TYPE input_coef_type: (input) type of input//  long channel_index: (input) channel number//// return: a boolean value indicating status//// this method computes the prediction coefficents from Covariance// input type. it also outputs the error energy.//boolean Prediction::compute(VectorFloat& output_a, float& err_energy_a,			    const MatrixFloat& input_a,			    AlgorithmData::COEF_TYPE input_coef_type_a,			    long channel_index_a) {  // initialize a value for err_energy since in some mode there is no  // err_energy output  //  err_energy_a = 0.0;  boolean status = false;    // check the order  //     if (order_d < (long)1) {    output_a.setLength(0);    return Error::handle(name(), L"compute", ERR_ORDER,			 __FILE__, __LINE__, Error::WARNING);  }  // branch on algorithm  //  if (algorithm_d == COVARIANCE) {    if (implementation_d == CHOLESKY) {      if (input_coef_type_a == AlgorithmData::COVARIANCE) {	status = computeCovarCholesky(output_a, err_energy_a, input_a);      }      // else: error unknown coefficient type      //      else {	return Error::handle(name(), L"compute", ERR_UNCTYP,			     __FILE__, __LINE__);      }    }    // else: error unknown implementation    //        else {      return Error::handle(name(), L"compute", ERR_UNKIMP,			   __FILE__, __LINE__);    }        }  // else: error unknown algorithm  //  else {    return Error::handle(name(), L"compute", ERR_UNKALG,			 __FILE__, __LINE__);  }        // possibly display the data  //  display(output_a, input_a, name());  // exit gracefully  //    return status;}// method: computeAutoDurbin//// arguments://  VectorFloat& pred_coef: (output) prediction coefficients//  float& err_energy: (output) error energy  //  const VectorFloat& auto: (input) autocorrelation coefficients//// return: a boolean value indicating status//// this method computes the prediction coefficients from the// autocorrelation coefficents. it also outputs the error energy.//// Reference://  J.D. Markel and A.H. Gray, "Linear Prediction of Speech,"//  Springer-Verlag Berlin Heidelberg, New York, USA, pp. 217-219,//  1980.//boolean Prediction::computeAutoDurbin(VectorFloat& pred_coef_a,				      float& err_energy_a,				      const VectorFloat& auto_a) {  // apply dynamic range threshold  //  float old_auto_0 = auto_a(0);  if (dyn_range_d < (float)0) {    double scale_factor =      pow(10.0, (float)dyn_range_d / Integral::DB_POW_SCALE_FACTOR);    const_cast<VectorFloat&>(auto_a)(0) *= (1 + scale_factor);  }    else {    return Error::handle(name(), L"computeAutoDurbin", ERR_DYNRANGE,			 __FILE__, __LINE__);  }      // declare local variables  //  long i, j;                                 // loop counters  long lp_order = auto_a.length() - 1;       // analysis order  long j_bckwd;                              // a backwards index  long middle_index;                         // inner loop limit  double sum;                                // accumulator  double rc_reg;                             // register  float tmp;    // create space  //  if (!pred_coef_a.setLength(lp_order + 1)) {    return Error::handle(name(), L"computeAutoDurbin", ERR,			 __FILE__, __LINE__, Error::WARNING);  }    // initialization  //  pred_coef_a(0) = 1.0;  err_energy_a = auto_a(0);  // if the energy of the signal is zero we set all the predictor  // coefficients to zero and exit  //  if (err_energy_a == (float)0) {    for (int i = 0; i < pred_coef_a.length(); i++) {      pred_coef_a(i) = 0;    }    pred_coef_a(0) = 1;    return true;  }    // do the first step manually  //  if (err_energy_a == (float)0) {    return Error::handle(name(), L"computeAutoDurbin", Error::ARG, __FILE__, __LINE__);  }    sum = -(double)auto_a(1) / err_energy_a;  pred_coef_a(1) = sum;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -