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

📄 ft_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
    if (debug_level_d >= Integral::ALL) {      debug(PARAM_DBGL);    }        if (debug_level_d >= Integral::DETAILED) {      input_a.debug(CLASS_NAME);    }    if (debug_level_d >= Integral::BRIEF) {      output_a.debug(CLASS_NAME);    }  }  // exit gracefully  //  return status;}// method: computeForward//// arguments://  VectorComplexFloat& output: (output) output data vector//  const VectorFloat& input: (input) input data vector//// return: a boolean value indicating status//// this method calls the fft algorithm chosen by the user in the// forward algorithm. if the input data length is not compatible with// the chosen algorithm then the dft is used//boolean FourierTransform::computeForward(VectorComplexFloat& output_a,					 const VectorFloat& input_a) {  // variables abour length  //  input data length: L  //  user specified input length: N  //  user specified output length: M  //  FFT order: order  //  long L = input_a.length();  long N = (ilen_d == DEF_LENGTH) ? L : (long)ilen_d;  order_d = ((algorithm_d != FFT) || (resolution_d == AUTO)) ?    (Long)N : order_d;  // for other fast fourier transform implementation, check the order of the  // implementation and assign a default implementation if necessary  //  if (!validateImplementation()) {        // if the input order is not a valid value for the given implementation    //    return Error::handle(name(), L"computeForward", ERR_ORDER,			 __FILE__, __LINE__);  }  // save the current implementation since the internal implementation  // may change during this method  //  IMPLEMENTATION backup_impl = implementation_d;  // create a vector for use when we have to truncate  //  VectorFloat tmp_input;  // check the required order - when fixed order is not required, if  // the required order is greater than the length of the input vector  // then we need to zero-pad the input vector (with a trick).  if it  // is less than the length of the input vector then we need to  // truncate, else use the given input vector  //  const VectorFloat* algo_input = &input_a;  // if N < L, truncate input data to N length  //  if (N < L) {    tmp_input.setLength(N);    tmp_input.move(input_a, N, 0, 0);    // set the pointer    //    algo_input = &tmp_input;  }  // if order > L, pad zeros to input data to order length  //  here is a trick, we set order_d for DFT and DCT to required  //  input length N  //  if (order_d > L) {    if (N >= L) {      tmp_input.assign(input_a);    }    tmp_input.setLength(order_d, true);    algo_input = &tmp_input;  }  // create a temporary output vector  //  VectorFloat tmp_output;  // Algorithm: DFT  //  if (algorithm_d == DFT) {    // Implementation: CONVENSIONAL    //    if (implementation_d == CONVENTIONAL) {      if (!dfReal(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }    // Implementation: TRIGONOMETRIC    //    else if (implementation_d == TRIGONOMETRIC) {      if (!triReal(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }    // else: not implemented yet    //    else {      return Error::handle(name(), L"computeForward", Error::NOT_IMPLEM,			   __FILE__, __LINE__);    }  }  // Algorithm: FFT  //  else if (algorithm_d == FFT) {      // Implementation: SPLIT_RADIX    //    if (implementation_d == SPLIT_RADIX) {      if (!srReal(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }      // Implementation: RADIX_2    //    else if (implementation_d == RADIX_2) {      if (!rad2Real(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }        // Implementation: RADIX_4    //    else if (implementation_d == RADIX_4) {    if (!rad4Real(tmp_output, *algo_input)) {      return Error::handle(name(), L"computeForward", ERR_COMPF,			   __FILE__, __LINE__, Error::WARNING);    }    }      // Implementation: FAST_HARLEY    //    else if (implementation_d == FAST_HARTLEY) {      if (!fhReal(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }         // Implementation: QF    //  for quick fourier transform implementation    //    else if (implementation_d == QF) {      if (!qfReal(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }    // Implementation: DITF    //  for decimation in time frequency implementation    //    else if (implementation_d == DITF) {      if (!ditfReal(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }    // else: not implemented yet    //    else {      return Error::handle(name(), L"computeForward", Error::NOT_IMPLEM,			   __FILE__, __LINE__);    }  }  // Algorithm: DCT  //  for discrete cosine transform algorithm  //  else if (algorithm_d == DCT) {    // Implementation: DCT_I    //    if (implementation_d == TYPE_I) {      if (!dct1Real(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }    // Implementation: DCT_II    //    else if (implementation_d == TYPE_II) {      if (!dct3Real(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }    // Implementation: DCT_III    //    else if (implementation_d == TYPE_III) {      if (!dct3Real(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }    // Implementation: DCT_IV    //    else if (implementation_d == TYPE_IV) {      if (!dct4Real(tmp_output, *algo_input)) {	return Error::handle(name(), L"computeForward", ERR_COMPF,			     __FILE__, __LINE__, Error::WARNING);      }    }        // else: not implemented yet    //    else {      return Error::handle(name(), L"computeForward", Error::NOT_IMPLEM,			   __FILE__, __LINE__);    }  }  // else: not implemented yet  //  else {    return Error::handle(name(), L"computeForward", Error::NOT_IMPLEM,			 __FILE__, __LINE__);  }  if (algorithm_d == DCT) {    // convert the temporary output vector to complex output vector    //    output_a.setLength(tmp_output.length());    for (long i = 0; i < tmp_output.length(); i++) {      output_a(i).assign(complexfloat(tmp_output(i), 0));    }  }  else {    // convert the temporary output vector to complex output vector    //    output_a.setLength(tmp_output.length() / 2);    for (long i = 0, j = 0; i < output_a.length(); i++) {      output_a(i).assign(complexfloat(tmp_output(j), tmp_output(j + 1)));      j += 2;    }  }  // restore the implementation  //  implementation_d = backup_impl;  // exit gracefully  //  return true;}// method: computeForward//// arguments://  VectorComplexFloat& output: (output) output data vector//  const VectorComplexFloat& input: (input) input data vector//// return: a boolean value indicating status//// this method calls the fft algorithm chosen by the user in the// forward algorithm. if the input data length is not compatible with// the chosen algorithm then the dft is used//boolean FourierTransform::computeForward(VectorComplexFloat& output_a,					 const VectorComplexFloat& input_a) {  // variables abour length  //  input data length: L  //  user specified input length: N  //  user specified output length: M  //  FFT order: order  //  long L = input_a.length();  long N = (ilen_d == DEF_LENGTH) ? L : (long)ilen_d;  order_d = ((algorithm_d != FFT) || (resolution_d == AUTO)) ? (Long)N : order_d;  // for other fast fourier transform implementation, check the order of the  // implementation and assign a default implementation if necessary  //  if (!validateImplementation()) {        // if the input order is not a valid value for the given implementation    //    return Error::handle(name(), L"computeForward",			 ERR_ORDER, __FILE__, __LINE__);  }  // save the current implementation since the internal implementation  // may change during this method  //  IMPLEMENTATION backup_impl = implementation_d;  // create a vector for use when we have to truncate  //  VectorFloat tmp_input(L * 2);  // expand complex vector to the temporay vectors  //    for (long i = 0, j = 0; i < L; i++) {    tmp_input(j++) = input_a(i).real();    tmp_input(j++) = input_a(i).imag();  }  // if N < L, truncate input data to N length  //  if (N < L) {    tmp_input.setLength(N * (long)2);  }  // if order > L, pad zeros to input data to order length  //  here is a trick, we set order_d for DFT and DCT to required  //  input length N  //  if (order_d > L) {    tmp_input.setLength((long)order_d * 2, true);  }  // create a temporary output vector  //  VectorFloat tmp_output;  // Algorithm: DFT  //  if (algorithm_d == DFT) {    // Implementation: CONVENSIONAL    //    if (implementation_d == CONVENTIONAL) {      if (!dfComplex(tmp_output, tmp_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }    // Implementation: TRIGONOMETRIC    //    else if (implementation_d == TRIGONOMETRIC) {      if (!triComplex(tmp_output, tmp_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }    // else: not implemented yet    //    else {      return Error::handle(name(), L"computeForward", Error::NOT_IMPLEM,			   __FILE__, __LINE__);    }  }  // Algorithm: FFT  //  else if (algorithm_d == FFT) {      // Implementation: SPLIT_RADIX    //    if (implementation_d == SPLIT_RADIX) {      if (!srComplex(tmp_output, tmp_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }      // Implementation: RADIX_2    //    else if (implementation_d == RADIX_2) {      if (!rad2Complex(tmp_output, tmp_input)) {	return Error::handle(name(), L"computeForward",			     ERR_COMPF, __FILE__, __LINE__, Error::WARNING);      }    }        // Implementation: RADIX_4    //    else if (implementation_d == RADIX_4) {    if (!rad4Complex(tmp_output, tmp_input)) {      return Error::handle(name(), L"computeForward",			   ERR_COMPF, __FILE__, __LINE__, Error::WARNING);    }    }

⌨️ 快捷键说明

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