// file: $isip/class/algo/LogAreaRatio/lar_05.cc // version: $Id: lar_05.cc 8165 2002-05-31 21:57:33Z picone $ // // isip include files // #include "LogAreaRatio.h" // method: apply // // arguments: // Vector& output: (output) output data // const Vector< CircularBuffer >& input: (input) input data // // return: a bool8 value indicating status // // this method calls the appropriate computation methods // bool8 LogAreaRatio::apply(Vector& output_a, const Vector< CircularBuffer >& input_a) { // check the compute mode // if (cmode_d != FRAME_INTERNAL) { return Error::handle(name(), L"apply", ERR_UNSUPM, __FILE__, __LINE__); } // determine the number of input channels and force the output to be // that number // int32 len = input_a.length(); output_a.setLength(len); bool8 res = true; // start the debugging output // displayStart(this); // loop over the channels and call the compute method // for (int32 c = 0; c < len; c++) { // display the channel number // displayChannel(c); // 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::LOG_AREA_RATIO); } // 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 // int32 index: (input) channel number // // return: a bool8 value indicating status // // this method computes the log-area-ratio of single-channel // reflection or prediction coefficients input using the specified // algorithm and implementation // bool8 LogAreaRatio::compute(VectorFloat& output_a, const VectorFloat& input_a, AlgorithmData::COEF_TYPE input_coef_type_a, int32 index_a) { // declare local variables // bool8 status = false; // branch on algorithm and implementation types // if (algorithm_d == LATTICE) { if (implementation_d == KELLY_LOCHBAUM) { status = computeLatticeKellyLochbaum(output_a, input_a, input_coef_type_a); } } // possibly display the data // display(output_a, input_a, name()); // exit gracefully // return status; } // method: computeLatticeKellyLochbaum // // arguments: // VectorFloat& output: (output) output data // const VectorFloat& input: (input) input data // AlgorithmData::COEF_TYPE input_coef_type: (input) type of input // // return: a bool8 value indicating status // // this method computes the log-area-ratio of the input signal. // log-area-ratio can be computed from reflection and prediction // coefficients. this method is called by the public compute method. // bool8 LogAreaRatio::computeLatticeKellyLochbaum(VectorFloat& output_a, const VectorFloat& input_a, AlgorithmData::COEF_TYPE input_coef_type_a) { // check algorithm and implementation // if ((algorithm_d != LATTICE) || (implementation_d != KELLY_LOCHBAUM)) { return Error::handle(name(), L"computeLatticeKellyLochbaum", ERR, __FILE__, __LINE__); } // declare local variables // int32 order = input_a.length(); // branch on input coefficient type // Coefficient = REFLECTION // if (input_coef_type_a == AlgorithmData::REFLECTION) { // declare local variables // float64 g; output_a.setLength(order); // compute log area ratio using: // 1 - refl_coef(i) // log_area_ratio(i) = ------------------- // 1 + refl_coef(i) // for (int32 i = 0; i < order; i++) { if (input_a(i) <= (float32)-1.0 || input_a(i) >= (float32)1.0) { return Error::handle(name(), L"computeLatticeKellyLochbaum", Error::ARG, __FILE__, __LINE__); } g = log((float64)((1 - input_a(i)) / (1 + input_a(i)))); output_a(i) = (float32)g; } } // Coefficient = PREDICTION // else if (input_coef_type_a == AlgorithmData::PREDICTION) { // compute the reflection coefficient from prediction coefficient // Reflection refl; refl.set(Reflection::PREDICTION, Reflection::STEP_UP, order, Reflection::DEF_DYN_RANGE); VectorFloat refl_const; refl.compute(refl_const, input_a, AlgorithmData::PREDICTION); // call compute method for reflection coefficient // computeLatticeKellyLochbaum(output_a, refl_const, AlgorithmData::REFLECTION); } // else: error unsupported coefficient type // else { return Error::handle(name(), L"computeLatticeKellyLochbaum", ERR_UNCTYP, __FILE__, __LINE__); } // exit gracefully // return true; }