115 unsigned long alternativePitch = tMax_;
116 lastPeriod_ = tMax_+1;
119 unsigned long delay_;
126 for ( delay_=1; delay_<=tMax_; delay_++ )
130 for ( n=0; n<inputFrames.
size(); n++ ) {
131 x_t = inputLine_.
tick( inputFrames[ n ] );
132 for ( delay_=1; delay_<= tMax_; delay_++ ) {
133 x_t_T = inputLine_.
tapOut( delay_ );
135 dt[delay_] += coeff * coeff;
140 for ( delay_=1; delay_<=tMax_; delay_++ ) {
141 cumDt[delay_] = dt[delay_] + cumDt[delay_-1];
142 dpt[delay_] = dt[delay_] * delay_ / cumDt[delay_];
145 if ( delay_ > 1 && dpt[delay_-1]-dpt[delay_-2] < 0 && dpt[delay_]-dpt[delay_-1] > 0 ) {
147 if ( dpt[delay_-1] < threshold_ ){
148 lastPeriod_ = delay_-1;
152 else if ( dpt[alternativePitch] > dpt[delay_-1] )
154 alternativePitch = delay_-1;
159 if ( dpt[delay_]-dpt[delay_-1] < 0 ) {
160 if ( dpt[delay_] < threshold_ )
161 lastPeriod_ = delay_;
162 else if ( dpt[alternativePitch] > dpt[delay_] )
163 alternativePitch = delay_;
166 if ( lastPeriod_ == tMax_+1 )
168 lastPeriod_ = alternativePitch;
172 outputLine_.
tick( zeroFrame, outputFrames );
175 for (
int n=-(
int)lastPeriod_; n<(int)lastPeriod_; n++ )
176 window[n+lastPeriod_] = (1 + cos(PI*n/lastPeriod_)) / 2 ;
183 for ( ; inputPtr<(int)(tMax_-lastPeriod_); inputPtr+=lastPeriod_ ) {
185 while ( outputPtr < inputPtr ) {
187 env[1] = fmod( outputPtr + tMax_, 1.0 );
188 env[0] = 1.0 - env[1];
189 M = tMax_ - inputPtr + lastPeriod_ - 1;
190 N = 2*tMax_ - (
unsigned long)floor(outputPtr + tMax_) + lastPeriod_ - 1;
191 for (
unsigned int j=0; j<2*lastPeriod_; j++,M--,N-- ) {
192 sample = inputLine_.
tapOut(M) * window[j] / 2.;
194 outputLine_.
addTo(env[0] * sample, N);
195 outputLine_.
addTo(env[1] * sample, N-1);
197 outputPtr = outputPtr + lastPeriod_ * periodRatio_;
243#if defined(_STK_DEBUG_)
245 oStream_ <<
"LentPitShift::tick(): channel and StkFrames arguments are incompatible!";
246 handleError( StkError::FUNCTION_ARGUMENT );
250 StkFloat *iSamples = &iFrames[iChannel];
251 StkFloat *oSamples = &oFrames[oChannel];
253 for (
unsigned int i=0; i<iFrames.
frames(); i++, iSamples += iHop, oSamples += oHop ) {
254 *oSamples = tick( *iSamples );
StkFloat addTo(StkFloat value, unsigned long tapDelay)
Sum the provided value into the delay line at tapDelay samples from the input.
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition LentPitShift.h:206