📄 calc_05.cc
字号:
// file: $isip/class/algo/Calculus/calc_05.cc// version: $Id: calc_05.cc,v 1.28 2002/06/25 01:42:41 picone Exp $//// isip include files//#include "Calculus.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 calls the appropriate computation method//boolean Calculus::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; frame_index_d++; // 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); if (input_a(c)(0).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"apply", ERR_UNSUPA, __FILE__, __LINE__); } // cmode_d: FRAME_INTERNAL // if (cmode_d == FRAME_INTERNAL) { // call AlgorithmData::makeVectorFloat to force the output vector for // this channel to be a VectorFloat, use the // CircularBuffer<AlgorithmData> directly on the input for this // channel // res &= computeInternal(output_a(c).makeVectorFloat(), input_a(c)); } // cmode_d: CROSS_FRAME // else if (cmode_d == CROSS_FRAME) { // call AlgorithmData::makeVector to force the output vector for // this channel to be a VectorFloat, use the // CircularBuffer<AlgorithmData> directly on the input for this // channel // res &= computeCross(output_a(c).makeVectorFloat(), input_a(c)); } // mode_d: ACCUMULATE // else { return Error::handle(name(), L"apply", ERR_UNSUPM, __FILE__, __LINE__); } // set the coefficient type for the output // output_a(c).setCoefType(input_a(c)(0).getCoefType()); } // finish the debugging output // displayFinish(this); // exit gracefully // return res;}// method: compute//// arguments:// VectorFloat& output: (output) output data// const VectorFloat& input: (input) input data// AlgorithmData::COEF_TYPE input_coef_type: (input) type of input// long channel_index: (input) channel index//// return: a boolean value indicating status//// this method performs appropriate calculus operation on input vector.// note that none of the algorithms or implementations currently// require memory to be maintained between calls, so channel_index is// not used.// boolean Calculus::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; // check valid flag // if (!is_valid_d) { init(); } // branch on algorithm: // Algorithm: DIFFERENTIATION // if (algorithm_d == DIFFERENTIATION) { // branch on implementation: // // Implementation: REGRESSION // if (implementation_d == REGRESSION) { status = computeDifRegression(output_a, input_a); } // Implementation: CENTRAL_DEFFERENCE // else if (implementation_d == CENTRAL_DIFFERENCE) { status = computeDifCentral(output_a, input_a); } // Implementation: BACKWARD_DIFFERENCE // else if (implementation_d == BACKWARD_DIFFERENCE) { status = computeDifBackward(output_a, input_a); } // else: unknown condition // else { return Error::handle(name(), L"compute", ERR_UNKIMP, __FILE__, __LINE__); } } // Algorithm: INTEGRATION // else if (algorithm_d == INTEGRATION) { return Error::handle(name(), L"compute", ERR_UNSUPA, __FILE__, __LINE__); } // check algorithm: unknown // else { return Error::handle(name(), L"compute", ERR_UNKALG, __FILE__, __LINE__); } // exit gracefully // return status;}// method: compute//// arguments:// VectorComplexFloat& output: (output) output data// const VectorComplexFloat& input: (input) input data// AlgorithmData::COEF_TYPE input_coef_type: (input) type of input// long index: (input) channel index//// return: a boolean value indicating status//// this method performs the appropriate calculus operation on the input vector//boolean Calculus::compute(VectorComplexFloat& output_a, const VectorComplexFloat& input_a, AlgorithmData::COEF_TYPE input_coef_type_a, long index_a) { return Error::handle(name(), L"compute", ERR_UNSUPA, __FILE__, __LINE__);} // method: computeInternal//// arguments:// VectorFloat& output: (output) output vector// const CircularBuffer<AlgorithmData>& input: (input) input vectors// AlgorithmData::COEF_TYPE input_coef_type: (input) type of input// long channel_index: (input) channel index//// return: a boolean value indicating status//// this method transfers data from the circular buffer to the// lower level compute method//boolean Calculus::computeInternal(VectorFloat& output_a, const CircularBuffer<AlgorithmData>& input_a, AlgorithmData::COEF_TYPE input_coef_type_a, long channel_index_a) { // check that the type of data is correct // if (input_a(0).getDataType() != AlgorithmData::VECTOR_FLOAT) { return Error::handle(name(), L"computeInternal", ERR_UNKTYP, __FILE__, __LINE__); } // create space for the output // long num_coeffs = input_a(0).getVectorFloat().length(); output_a.setLength(num_coeffs); // check how much past and future data is in the buffer, and whether // this is adequate. note that the data must span from the interval: // // [offset_d, offset_d+num_elements-1] // // getNumBackward and getNumForward retrieve this information from // the circular buffer. the calling class, typically Algorithm, // has the responsibility of guaranteeing there is enough data in // the circular buffer // if (offset_d < (-1 * input_a.getNumBackward())) { return Error::handle(name(), L"computeInternal", ERR_INSUFD, __FILE__, __LINE__); } else if ((offset_d + num_elements_d - 1) > input_a.getNumForward()) { return Error::handle(name(), L"computeInternal", ERR_INSUFD, __FILE__, __LINE__); } // declare some scratch buffers: // a vector to hold frame-spanning data // a vector to accept output from compute() // VectorFloat data(num_elements_d); VectorFloat result(1); // loop over the number of coefficients // for (long i = 0; i < num_coeffs; i++) { // copy data onto the data buffer // for (long k = 0; k < num_elements_d; k++) { // fetch the data backward in time // if (i + k < delta_win_d) { data(k) = (input_a(-1).getVectorFloat())(num_coeffs - delta_win_d + i + k); } else if ( (i > num_coeffs - 1 - delta_win_d) && (i + k - delta_win_d > num_coeffs - 1) && (k > delta_win_d)) { data(k) = (input_a(1).getVectorFloat())(i + k - num_coeffs - delta_win_d); } else { data(k) = (input_a(0).getVectorFloat())(i + k - delta_win_d); } } // compute the algorithm: we now have the temporal data in a vector // and can process it // if (!compute(result, data, input_coef_type_a)) { return Error::handle(name(), L"computeInternal", ERR_COMPF, __FILE__, __LINE__, Error::WARNING); } // save the result into the output buffer and move to the next element // output_a(i) = result(0); } // possibly display the data // display(output_a, input_a, name()); // exit gracefully //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -