void AimVQ::myProcess(realvec& in, realvec& out) { // cout << "AimVQ::myProcess" << endl; (void) in; // avoid unused parameter warning when MARSYAS_ANN is not enabled // Zero out the output first for (int i = 0; i < onObservations_; ++i) { out(i,0) = 0.0; } #ifdef MARSYAS_ANN mrs_natural _num_codewords_to_return = ctrl_num_codewords_to_return_->to<mrs_natural>(); mrs_real _kd_tree_error_bound = ctrl_kd_tree_error_bound_->to<mrs_real>(); vector<int> sparse_code; int offset = 0; realvec obsRow; for (int i = 0; i < codebooks_count_; ++i) { in.getRow(i,obsRow); ANNidxArray indices = new ANNidx[_num_codewords_to_return]; ANNdistArray distances = new ANNdist[_num_codewords_to_return]; sparse_coder_trees_[i]->annkSearch(obsRow.getData(), _num_codewords_to_return, indices, distances, _kd_tree_error_bound); for (int j = 0; j < _num_codewords_to_return; ++j) { sparse_code.push_back(indices[j] + offset); } offset += codeword_count_; delete indices; delete distances; } for (unsigned int j = 0; j < sparse_code.size(); ++j) { out(sparse_code[j],0) = 1.0; } #endif }
void Peaker::myProcess(realvec& in, realvec& out) { mrs_natural t,o; const mrs_natural peakSpacing = (mrs_natural)(inSamples_ *getctrl("mrs_real/peakSpacing")->to<mrs_real>() + .5); mrs_real peakStrengthRelRms, peakStrengthRelMax, peakStrengthRelThresh, peakStrengthAbs; //mrs_real peakGain; mrs_bool peakHarmonics; mrs_bool rmsNormalize; mrs_natural peakStart; mrs_natural peakEnd; mrs_natural interpolationMode; mrs_natural peakNeighbors; peakStrengthRelRms = getctrl("mrs_real/peakStrength")->to<mrs_real>(); peakStrengthRelMax = getctrl("mrs_real/peakStrengthRelMax")->to<mrs_real>(); peakStrengthRelThresh = getctrl("mrs_real/peakStrengthRelThresh")->to<mrs_real>(); lpCoeff_ = getctrl("mrs_real/peakStrengthThreshLpParam")->to<mrs_real>(); peakStrengthAbs = getctrl("mrs_real/peakStrengthAbs")->to<mrs_real>(); peakStart = getctrl("mrs_natural/peakStart")->to<mrs_natural>(); peakEnd = getctrl("mrs_natural/peakEnd")->to<mrs_natural>(); interpolationMode = getctrl("mrs_natural/interpolation")->to<mrs_natural>(); //peakGain = getctrl("mrs_real/peakGain")->to<mrs_real>(); peakHarmonics = getctrl("mrs_bool/peakHarmonics")->to<mrs_bool>(); rmsNormalize = getctrl("mrs_bool/rmsNormalize")->to<mrs_bool>(); peakNeighbors = getctrl("mrs_natural/peakNeighbors")->to<mrs_natural>(); if (peakEnd == 0) peakEnd = inSamples_; // FIXME This line defines an unused variable // mrs_real srate = getctrl("mrs_real/israte")->to<mrs_real>(); out.setval(0.0); //peakStrengthRelRms = 0.0; for (o = 0; o < inObservations_; o++) { rms_ = 0.0; max_ = -1e37; for (t=peakStart; t < peakEnd; t++) { rms_ += in(o,t) * in(o,t); if (max_ < in(o,t)) max_ = in(o,t); } if (rms_ != 0.0) rms_ /= (peakEnd - peakStart); rms_ = sqrt(rms_); mrs_real max; mrs_natural maxIndex; bool peakFound = false; if (peakStrengthRelThresh > .0) { in.getRow (o,lpThresh_); compLpThresh (lpThresh_, lpThresh_); // do it inplace to avoid another copy... } for (t=peakStart; t < peakEnd; t++) { peakFound = true; // peak has to be larger than neighbors for (int j = 1; j < peakNeighbors; j++) { mrs_natural index=t-j; if (index<0) index=0; if (in(o,index) >= in(o,t)) { peakFound = false; break; } index=t+j; if (index>=inSamples_) index=inSamples_-1; if (in(o,index) >= in(o,t)) { peakFound = false; break; } } if (peakFound) { currThresh_ = lpThresh_(t); peakFound = doThresholding (in(o,t), peakStrengthRelRms, peakStrengthRelMax, peakStrengthRelThresh, peakStrengthAbs); } if (peakFound) { // check for another peak in the peakSpacing area max = in(o,t); maxIndex = t; for (int j=0; j < peakSpacing; j++) { if (t+j < peakEnd-1) if (in(o,t+j) > max) { max = in(o,t+j); maxIndex = t+j; } } t += peakSpacing; if (rmsNormalize) { out(o,maxIndex) = in(o,maxIndex) / rms_; if(interpolationMode && maxIndex > 0 && maxIndex < inSamples_) { out(o,maxIndex-1) = in(o,maxIndex-1) /rms_; out(o,maxIndex+1) = in(o,maxIndex+1) / rms_; } } else { out(o,maxIndex) = in(o,maxIndex); if(interpolationMode && maxIndex > 0 && maxIndex < inSamples_) { out(o,maxIndex-1) = in(o,maxIndex-1); out(o,maxIndex+1) = in(o,maxIndex+1); } } // peakNeighbors = 0; // rms_ = 1.0; if (peakHarmonics) { twice_ = 2 * maxIndex; half_ = (mrs_natural) (0.5 * maxIndex + 0.5); triple_ = 3 * maxIndex; third_ = (mrs_natural) (0.33 * maxIndex + 0.5); if (twice_ < (peakEnd - peakStart)) { peakFound = true; // peak has to be larger than neighbors for (int j = 1; j < peakNeighbors; j++) { if (in(o,twice_-j) >= in(o,twice_)) { peakFound = false; break; } if (in(o,twice_+j) >= in(o,twice_)) { peakFound = false; break; } } if (peakFound) { out(o, maxIndex) += (in(o, twice_)/rms_); out(o, twice_) = in(o,twice_)/rms_ + 0.5 * out(o, maxIndex); } } if (half_ < (peakEnd - peakStart)) { peakFound = true; // peak has to be larger than neighbors for (int j = 1; j < peakNeighbors; j++) { if (in(o,half_-j) >= in(o,half_)) { peakFound = false; break; } if (in(o,half_+j) >= in(o,half_)) { peakFound = false; break; } } if (peakFound) { out(o, maxIndex) += (in(o, half_)/rms_); out(o, half_) = in(o,half_)/rms_ + 0.5 * out(o, maxIndex); } } if (triple_ < (peakEnd - peakStart)) { peakFound = true; // peak has to be larger than neighbors for (int j = 1; j < peakNeighbors; j++) { if (in(o,triple_-j) >= in(o,triple_)) { peakFound = false; break; } if (in(o,triple_+j) >= in(o,triple_)) { peakFound = false; break; } } if (peakFound) { out(o, maxIndex) += (in(o, triple_)/rms_); out(o, triple_) = in(o,triple_)/rms_ + 0.5 * out(o, maxIndex); } } if (third_ < (peakEnd - peakStart)) { peakFound = true; // peak has to be larger than neighbors for (int j = 1; j < peakNeighbors; j++) { if (in(o,third_-j) >= in(o,third_)) { peakFound = false; break; } if (in(o,third_+j) >= in(o,triple_)) { peakFound = false; break; } } if (peakFound) { out(o, maxIndex) += (in(o, third_)/rms_); out(o, third_) = in(o,third_)/rms_ + 0.5 * out(o, maxIndex); } } } peakFound = true; } } } }