1 #ifndef STK_LENTPITSHIFT_H
2 #define STK_LENTPITSHIFT_H
24 LentPitShift( StkFloat periodRatio = 1.0,
int tMax = RT_BUFFER_SIZE );
40 StkFloat
tick( StkFloat input );
92 unsigned long lastPeriod_;
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 ( 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(STK_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_;
210 inputFrames[ptrFrames] = input;
212 sample = outputFrames[ptrFrames++];
215 if ( ptrFrames == (
int) inputFrames.
size() ){
225 #if defined(_STK_DEBUG_)
226 if ( channel >= frames.
channels() ) {
227 oStream_ <<
"LentPitShift::tick(): channel and StkFrames arguments are incompatible!";
232 StkFloat *samples = &frames[channel];
233 unsigned int hop = frames.
channels();
234 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop ) {
235 *samples =
tick( *samples );
243 #if defined(_STK_DEBUG_)
245 oStream_ <<
"LentPitShift::tick(): channel and StkFrames arguments are incompatible!";
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 );
STK non-interpolating delay line class.
Definition: Delay.h:25
StkFloat tapOut(unsigned long tapDelay)
Return the value at tapDelay samples from the delay-line input.
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: Delay.h:124
STK abstract effects parent class.
Definition: Effect.h:22
Pitch shifter effect class based on the Lent algorithm.
Definition: LentPitShift.h:21
LentPitShift(StkFloat periodRatio=1.0, int tMax=RT_BUFFER_SIZE)
Class constructor.
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: LentPitShift.h:206
void clear(void)
Reset and clear all internal state.
void process()
Apply the effect on the input samples and store it.
Definition: LentPitShift.h:109
void setShift(StkFloat shift)
Set the pitch shift factor (1.0 produces no shift).
An STK class to handle vectorized audio data.
Definition: Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:415
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:418
size_t size() const
Returns the total number of audio samples represented by the object.
Definition: Stk.h:373
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
The STK namespace.
Definition: ADSR.h:8