118 unsigned long alternativePitch = tMax_;
119 lastPeriod_ = tMax_+1;
122 unsigned long delay_;
129 for ( delay_=1; delay_<=tMax_; delay_++ )
133 for ( n=0; n<inputFrames.size(); n++ ) {
134 x_t = inputLine_.tick( inputFrames[ n ] );
135 for ( delay_=1; delay_<= tMax_; delay_++ ) {
136 x_t_T = inputLine_.tapOut( delay_ );
138 dt[delay_] += coeff * coeff;
143 for ( delay_=1; delay_<=tMax_; delay_++ ) {
144 cumDt[delay_] = dt[delay_] + cumDt[delay_-1];
145 dpt[delay_] = dt[delay_] * delay_ / cumDt[delay_];
148 if ( dpt[delay_-1]-dpt[delay_-2] < 0 && dpt[delay_]-dpt[delay_-1] > 0 ) {
150 if ( dpt[delay_-1] < threshold_ ){
151 lastPeriod_ = delay_-1;
155 else if ( dpt[alternativePitch] > dpt[delay_-1] )
157 alternativePitch = delay_-1;
162 if ( dpt[delay_]-dpt[delay_-1] < 0 ) {
163 if ( dpt[delay_] < threshold_ )
164 lastPeriod_ = delay_;
165 else if ( dpt[alternativePitch] > dpt[delay_] )
166 alternativePitch = delay_;
169 if ( lastPeriod_ == tMax_+1 )
171 lastPeriod_ = alternativePitch;
175 outputLine_.tick( zeroFrame, outputFrames );
178 for (
int n=-(
int)lastPeriod_; n<(int)lastPeriod_; n++ )
179 window[n+lastPeriod_] = (1 + std::cos(STK_PI*n/lastPeriod_)) / 2 ;
186 for ( ; inputPtr<(int)(tMax_-lastPeriod_); inputPtr+=lastPeriod_ ) {
188 while ( outputPtr < inputPtr ) {
190 env[1] = std::fmod( outputPtr + tMax_, 1.0 );
191 env[0] = 1.0f - env[1];
192 M = tMax_ - inputPtr + lastPeriod_ - 1;
193 N = 2*tMax_ - (
unsigned long)std::floor(outputPtr + tMax_) + lastPeriod_ - 1;
194 for (
unsigned int j=0; j<2*lastPeriod_; j++,M--,N-- ) {
195 sample = inputLine_.tapOut(M) * window[j] / 2.f;
197 outputLine_.addTo(env[0] * sample, N);
198 outputLine_.addTo(env[1] * sample, N-1);
200 outputPtr = outputPtr + lastPeriod_ * periodRatio_;
246#if defined(_STK_DEBUG_)
248 oStream_ <<
"LentPitShift::tick(): channel and StkFrames arguments are incompatible!";
253 StkFloat *iSamples = &iFrames[iChannel];
254 StkFloat *oSamples = &oFrames[oChannel];
256 for (
unsigned int i=0; i<iFrames.
frames(); i++, iSamples += iHop, oSamples += oHop ) {
257 *oSamples =
tick( *iSamples );
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition LentPitShift.h:209