void AutoCorrelation::myProcess(realvec& in, realvec& out) { mrs_natural t,o; k_ = ctrl_magcompress_->to<mrs_real>(); // Copy to output to perform inplace fft and zeropad to double size scratch_.create(fftSize_); //scratch_ needs to be reset every time for (o=0; o < inObservations_; o++) { for (t=lowSamples_; t < (lowSamples_+numSamples_); t++) { scratch_(t-(lowSamples_)) = in(o,t); } //zeropad for(t=(lowSamples_+numSamples_); t < fftSize_; t++) scratch_(t) = 0.0; //get pointer to data (THIS BREAKS ENCAPSULATION! FIXME [!]) mrs_real *tmp = scratch_.getData(); //compute forward FFT (of size fftSize_) myfft_->rfft(tmp, fftSize_/2, FFT_FORWARD); //rfft() takes as second argument half of the desired FFT size (see fft.cpp) // Special case for zero and Nyquist/2, // which only have real part if (k_ == 2.0) { re_ = tmp[0]; tmp[0] = re_ * re_; re_ = tmp[1]; tmp[1] = re_ * re_; } else { re_ = tmp[0]; re_ = sqrt(re_ * re_); tmp[0] = pow(re_, k_); re_ = tmp[1]; re_ = sqrt(re_ * re_); tmp[1] = pow(re_, k_); } // Compress the magnitude spectrum and zero // the imaginary part. for (t=1; t < fftSize_/2; t++) { re_ = tmp[2*t]; im_ = tmp[2*t+1]; if (k_ == 2.0) am_ = re_ * re_ + im_ * im_; else { am_ = sqrt(re_ * re_ + im_ * im_); am_ = pow(am_, k_); } tmp[2*t] = am_; tmp[2*t+1] = 0; } // Take the inverse Fourier Transform (of size fftSize_) myfft_->rfft(tmp, fftSize_/2, FFT_INVERSE); // Copy result to output if(normalize_) { for (t=0; t < onSamples_; t++) { out(o,t) = scratch_(t)*norm_(t); } } else for (t=0; t < onSamples_; t++) { // out(o,t) = 0.1 * scratch_(t) + 0.99 * out(o,t); out(o,t) = 1.0 * scratch_(t) + 0.0 * out(o,t); // out(o,t) = 0.5 * scratch_(t) + 0.5 * out(o,t); // out(o,t) += scratch_(t); } } if (ctrl_makePositive_->to<mrs_bool>()) { out -= out.minval(); } if(octaveCost_) //is there a reference for this octaveCost computation [?] { for (o=0; o < inObservations_; o++) { mrs_real maxOut = 0; for (t=1 ; t<onSamples_/2 ; t++) if (out(o, t)> out(o, t+1) && out(o, t) > out(o, t-1) && out(o, t)>maxOut) maxOut = out(o, t) ; cout << maxOut/out(o, 0)<< " " << 1+voicing_ << endl; if(maxOut && maxOut/out(o, 0) > 1-voicing_) for (t=1; t < onSamples_; t++) out(o, t) += octaveMax_-octaveCost_*log(36.0*t); else out.setval(0); } } if (ctrl_setr0to1_->to<mrs_bool>()) { // out -= out.minval(); /* for (o=0; o < onObservations_; o++) for (t=0; t< onSamples_-1; t++) { out(o,t) = out(o,t) / (onSamples_ - 1 - t); if (t > onSamples_-1-100) out(o,t) = 0.0; } */ // mrs_real myNorm = out(0,0); // if (myNorm > 0) // out /= myNorm; } if (ctrl_setr0to0_->to<mrs_bool>()) { for (o=0; o < onObservations_; o++) for (t=0; t < onSamples_; t++) { out(o,t) = out(o,t); } } }