📄 cep_05.cc
字号:
// file: $isip/class/algo/Cepstrum/cep_05.cc// version: $Id: cep_05.cc,v 1.27 2002/07/17 21:59:45 parihar Exp $//// isip include files//#include "Cepstrum.h"#include <FourierTransform.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 cepstral coefficients for the given// input. this method selects the appropriate input and output data// types and calls compute method accordingly.//boolean Cepstrum::apply(Vector<AlgorithmData>& output_a, const Vector< CircularBuffer<AlgorithmData> >& input_a) { // check for an unsupported mode // if (cmode_d == ACCUMULATE) { Error::handle(name(), L"apply", ERR_UNSUPM, __FILE__, __LINE__); } // set the length to the number of input channels // long len = input_a.length(); output_a.setLength(len); // accumulate a result status -- if compute method returns false // this apply method should return false // 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 compute method type based on the input type and // algorithm type // if ((input_a(c)(0).getDataType() == AlgorithmData::VECTOR_FLOAT) && (algorithm_d == IDCT)) { // 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()); } else if ((input_a(c)(0).getDataType() == AlgorithmData::VECTOR_COMPLEX_FLOAT) && (algorithm_d == IDCT)) { // call AlgorithmData::makeVectorFloat to force the output // vector for this channel to be a VectorFloat, call // AlgorithmData::getVectorComplexFloat on the input for this // channel to check that the input is already a // VectorComplexFloat and return that vector. // res &= compute(output_a(c).makeVectorFloat(), input_a(c)(0).getVectorComplexFloat(), input_a(c)(0).getCoefType()); } else if ((input_a(c)(0).getDataType() == AlgorithmData::VECTOR_FLOAT) && (algorithm_d == IDFT)) { // call AlgorithmData::makeVectorComplexFloat to force the // output vector for this channel to be a VectorComplexFloat, // 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).makeVectorComplexFloat(), input_a(c)(0).getVectorFloat(), input_a(c)(0).getCoefType()); } else if ((input_a(c)(0).getDataType() == AlgorithmData::VECTOR_COMPLEX_FLOAT) && (algorithm_d == IDFT)) { // call AlgorithmData::makeVectorComplexFloat to force the // output vector for this channel to be a VectorComplexFloat, // call AlgorithmData::getVectorComplexFloat on the input for // this channel to check that the input is already a // VectorComplexFloat and return that vector. // res &= compute(output_a(c).makeVectorComplexFloat(), input_a(c)(0).getVectorComplexFloat(), input_a(c)(0).getCoefType()); } // error condition // else { return Error::handle(name(), L"apply", ERR_ORDER, __FILE__, __LINE__); } // set the coefficient type for the output // output_a(c).setCoefType(AlgorithmData::SIGNAL); } // finish the debugging output // displayFinish(this); // exit gracefully // return res;}// method: compute//// arguments:// VectorFloat& output: (output) cepstral coefficients// const VectorFloat& input: (input) input vector// AlgorithmData::COEF_TYPE input_coef_type: (input) type of input// long channel_index: (input) channel index//// return: a boolean value indicating status//// this method computes the cepstral coefficients for a given input vector//boolean Cepstrum::compute(VectorFloat& output_a, const VectorFloat& input_a, AlgorithmData::COEF_TYPE input_coef_type_a, long channel_index_a) { // declare local variables // boolean status = false; VectorFloat input(input_a); // check the input arguments // if (order_d < (long)0) { Error::handle(name(), L"compute", ERR_ORDER, __FILE__, __LINE__); } // compute the log spectrum from spectrum // VectorFloat logspectrum; // make sure that input amplitude doesn't fall below the minimum // amplitude if it is defined // if (flag_min_amp_d) { input.limitMin((float)min_amp_d); } // take log of the input vector // logspectrum.log(input); // branch on algorithm // Algorithm: IDCT // if (algorithm_d == IDCT) { // branch on implementation // Implementation: TYPE_I // if (implementation_d == TYPE_I) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT1Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // Implementation: TYPE_II // else if (implementation_d == TYPE_II) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT2Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // Implementation: TYPE_III // else if (implementation_d == TYPE_III) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT3Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // Implementation: TYPE_IV // else if (implementation_d == TYPE_IV) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT4Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // else: error unknown implementation type // else { return Error::handle(name(), L"compute", ERR_UNKIMP, __FILE__, __LINE__); } } // Algorithm: IDFT // else { // branch on implementation: // Implementation: CONVENTIONAL // if (implementation_d == CONVENTIONAL) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { return Error::handle(name(), L"compute", ERR, __FILE__, __LINE__); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // else: error unknown implementation type // else { return Error::handle(name(), L"compute", ERR_UNKIMP, __FILE__, __LINE__); } } // possibly display the data // display(output_a, input_a, name()); // exit gracefully // return status;}// method: compute//// arguments:// VectorFloat& output: (output) cepstral coefficients// const VectorComplexFloat& input: (input) input vector// AlgorithmData::COEF_TYPE input_coef_type: (input) type of input// long channel_index: (input) channel index//// return: a boolean value indicating status//// this method computes the cepstral coefficients for a given input vector//boolean Cepstrum::compute(VectorFloat& output_a, const VectorComplexFloat& input_a, AlgorithmData::COEF_TYPE input_coef_type_a, long channel_index_a) { // declare local variables // boolean status = false; // check the input arguments // if (order_d < (long)0) { Error::handle(name(), L"compute", ERR, __FILE__, __LINE__); } // extract magnitude from the complex spectrum // VectorFloat magspectrum; input_a.mag(magspectrum); // compute the log spectrum from spectrum // VectorFloat logspectrum; // make sure that input amplitude doesn't fall below the minimum // amplitude, if it is defined // if (flag_min_amp_d) { magspectrum.limitMin((float)min_amp_d); } // take log of the input vector // logspectrum.log(magspectrum); // branch on algorithm // Algorithm: IDCT // if (algorithm_d == IDCT) { // branch on implementation // Implementation: TYPE_I // if (implementation_d == TYPE_I) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT1Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // Implementation: TYPE_II // else if (implementation_d == TYPE_II) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT2Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // Implementation: TYPE_III // else if (implementation_d == TYPE_III) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT3Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // Implementation: TYPE_IV // else if (implementation_d == TYPE_IV) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdctT4Float(output_a, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // else: error unknown implementation type // else { return Error::handle(name(), L"compute", ERR_UNKIMP, __FILE__, __LINE__); } } // Algorithm: IDFT // else { // declare a local variable // VectorComplexFloat complex_output; // branch on implementation: // Implementation: CONVENTIONAL // if (implementation_d == CONVENTIONAL) { if (input_coef_type_a == AlgorithmData::SPECTRUM) { status = computeIdftConvRealFloat(complex_output, logspectrum); } // else: error unknown input type // else { return Error::handle(name(), L"compute", ERR_UNCTYP, __FILE__, __LINE__); } } // else: error unknown implementation type // else { return Error::handle(name(), L"compute",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -