📄 calc_05.cc
字号:
return true;}// method: computeCross//// 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::computeCross(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"computeCross", 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"computeCross", ERR_INSUFD, __FILE__, __LINE__); } else if ((offset_d + num_elements_d - 1) > input_a.getNumForward()) { return Error::handle(name(), L"computeCross", 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); long number_frame = (long)(Integral::round(signal_duration_d / frame_dur_d)); // loop over the number of coefficients // for (long i = 0; i < num_coeffs; i++) { long j = offset_d; // copy data onto the data buffer // for (long k = 0; k < num_elements_d; k++) { // fetch the data backward in time // if ((k + frame_index_d + offset_d) < 0) { data(k) = (input_a(0 - frame_index_d).getVectorFloat())(i); j++; } else if ((k + frame_index_d + offset_d) > number_frame - 1) { data(k) = (input_a(number_frame - 1 - frame_index_d ).getVectorFloat())(i); } else { data(k) = (input_a(j++).getVectorFloat())(i); } } // 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"computeCross", 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 // return true;}// method: computeDifCentral//// arguments:// VectorFloat& output: (output) output data// const VectorFloat& input: (input) input data//// return: a boolean value indicating status//// this method computes a temporal derivative using a central difference.// two pertinent references are://// J.G. Proakis and D.G. Manolakis, Digital Signal Processing (Third Edition)// Prentice-Hall, Upper Saddle River, New Jersey, USA, 1996.//// and://// J. Picone, "Signal Processing in Speech Recognition," Proceedings// of the Speech Recognition System Training Workshop, Institute// for Signal and Information Processing, Mississippi State University,// May 2000 (see http://www.isip.msstate.edu/conferences/srstw00/program/// session_04/signal_processing/index.html).//boolean Calculus::computeDifCentral(VectorFloat& output_a, const VectorFloat& input_a) { // check the order: we currently only support a first-order difference // if (order_d != (long)1) { return Error::handle(name(), L"computeDifCentral", ERR_ORDER, __FILE__, __LINE__); } // check the length // else if (input_a.length() != (2 * delta_win_d + 1)) { return Error::handle(name(), L"computeDifCentral", ERR_INSUFD, __FILE__, __LINE__); } // compute the numerator of the difference // long N = (long)delta_win_d; double num = input_a(N + delta_win_d) - input_a(N - delta_win_d); // exit gracefully: return the value // output_a.setLength(1); if (denom_d != (double)0.0) { output_a(0) = num * denom_d; return true; } else { return Error::handle(name(), L"computeDifCentral", ERR_ZERODENOM, __FILE__, __LINE__, Error::WARNING); }}// method: computeDifBackward//// arguments:// VectorFloat& output: (output) output data// const VectorFloat& input: (input) input data//// return: a boolean value indicating status//// this method computes a temporal derivative using a simple// backward difference. two pertinent references are://// J.G. Proakis and D.G. Manolakis, Digital Signal Processing (Third Edition)// Prentice-Hall, Upper Saddle River, New Jersey, USA, 1996.//// and://// J. Picone, "Signal Processing in Speech Recognition," Proceedings// of the Speech Recognition System Training Workshop, Institute// for Signal and Information Processing, Mississippi State University,// May 2000 (see http://www.isip.msstate.edu/conferences/srstw00/program/// session_04/signal_processing/index.html).//boolean Calculus::computeDifBackward(VectorFloat& output_a, const VectorFloat& input_a) { // check the order: we currently only support a first-order difference // if (order_d != (long)1) { return Error::handle(name(), L"computeDifBackward", ERR_ORDER, __FILE__, __LINE__); } // check the length // else if (input_a.length() != (delta_win_d + (long)1)) { return Error::handle(name(), L"computeDifBackward", ERR_INSUFD, __FILE__, __LINE__); } // compute the numerator of the difference // long N = (long)delta_win_d; double num = input_a(N) - input_a(0); // exit gracefully: return the value // output_a.setLength(1); if (denom_d != (double)0.0) { output_a(0) = num * denom_d; return true; } else { return Error::handle(name(), L"computeDifBackward", ERR_ZERODENOM, __FILE__, __LINE__, Error::WARNING); }}// method: computeDifRegression//// arguments:// VectorFloat& output: (output) output data// const VectorFloat& input: (input) input data//// return: a boolean value indicating status//// this method computes a temporal derivative using a regression// approximation. Two pertinent references are://// F.K. Soong and A.E. Rosenburg, "On the Use of Instantaneous and// Transitional Spectral Information in Speaker Recognition," Proceedings// of the International Conference on Acoustics, Speech, and Signal// Processing, Tokyo, Japan, pp. 877-880, April 1986.//// and://// J. Picone, "Signal Processing in Speech Recognition," Proceedings// of the Speech Recognition System Training Workshop, Institute// for Signal and Information Processing, Mississippi State University,// May 2000 (see http://www.isip.msstate.edu/conferences/srstw00/program/// session_04/signal_processing/index.html).//boolean Calculus::computeDifRegression(VectorFloat& output_a, const VectorFloat& input_a) { // check the order: we currently only support a first-order regression // if (order_d != (long)1) { return Error::handle(name(), L"computeDifRegression", ERR_ORDER, __FILE__, __LINE__); } // check the length // else if (input_a.length() != (2 * delta_win_d + 1)) { return Error::handle(name(), L"computeDifRegression", ERR_INSUFD, __FILE__, __LINE__); } // compute the numerator of the regression formula // double num = 0.0; long N = (long)delta_win_d; for (long i = 1; i <= N; i++) { num += (double)i * (input_a(N + i) - input_a(N - i)); } // exit gracefully: return the value // output_a.setLength(1); if (denom_d != (double)0.0) { output_a(0) = num * denom_d; return true; } else { return Error::handle(name(), L"computeDifRegression", ERR_ZERODENOM, __FILE__, __LINE__, Error::WARNING); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -