mirror of
https://github.com/thestk/stk
synced 2026-01-14 13:31:53 +00:00
Version 4.4.0
This commit is contained in:
committed by
Stephen Sinclair
parent
d199342e86
commit
eccd8c9981
@@ -5,19 +5,19 @@
|
||||
This class implements a simple pitch shifter
|
||||
using delay lines.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#include "PitShift.h"
|
||||
#include <cmath>
|
||||
|
||||
const int maxDelay = 5024;
|
||||
namespace stk {
|
||||
|
||||
PitShift :: PitShift()
|
||||
PitShift :: PitShift( void )
|
||||
{
|
||||
delayLength = maxDelay - 24;
|
||||
halfLength = delayLength / 2;
|
||||
delayLength_ = maxDelay - 24;
|
||||
halfLength_ = delayLength_ / 2;
|
||||
delay_[0] = 12;
|
||||
delay_[1] = maxDelay / 2;
|
||||
|
||||
@@ -29,60 +29,60 @@ PitShift :: PitShift()
|
||||
rate_ = 1.0;
|
||||
}
|
||||
|
||||
PitShift :: ~PitShift()
|
||||
{
|
||||
}
|
||||
|
||||
void PitShift :: clear()
|
||||
{
|
||||
delayLine_[0].clear();
|
||||
delayLine_[1].clear();
|
||||
lastOutput_[0] = 0.0;
|
||||
lastOutput_[1] = 0.0;
|
||||
lastFrame_[0] = 0.0;
|
||||
}
|
||||
|
||||
void PitShift :: setShift(StkFloat shift)
|
||||
void PitShift :: setShift( StkFloat shift )
|
||||
{
|
||||
if (shift < 1.0) {
|
||||
if ( shift < 1.0 ) {
|
||||
rate_ = 1.0 - shift;
|
||||
}
|
||||
else if (shift > 1.0) {
|
||||
else if ( shift > 1.0 ) {
|
||||
rate_ = 1.0 - shift;
|
||||
}
|
||||
else {
|
||||
rate_ = 0.0;
|
||||
delay_[0] = halfLength+12;
|
||||
delay_[0] = halfLength_ + 12;
|
||||
}
|
||||
}
|
||||
|
||||
StkFloat PitShift :: computeSample(StkFloat input)
|
||||
StkFrames& PitShift :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
// Calculate the two delay length values, keeping them within the
|
||||
// range 12 to maxDelay-12.
|
||||
delay_[0] += rate_;
|
||||
while (delay_[0] > maxDelay-12) delay_[0] -= delayLength;
|
||||
while (delay_[0] < 12) delay_[0] += delayLength;
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( channel >= frames.channels() ) {
|
||||
errorString_ << "PitShift::tick(): channel and StkFrames arguments are incompatible!";
|
||||
handleError( StkError::FUNCTION_ARGUMENT );
|
||||
}
|
||||
#endif
|
||||
|
||||
delay_[1] = delay_[0] + halfLength;
|
||||
while (delay_[1] > maxDelay-12) delay_[1] -= delayLength;
|
||||
while (delay_[1] < 12) delay_[1] += delayLength;
|
||||
StkFloat *samples = &frames[channel];
|
||||
unsigned int hop = frames.channels();
|
||||
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
||||
*samples = tick( *samples );
|
||||
|
||||
// Set the new delay line lengths.
|
||||
delayLine_[0].setDelay((long)delay_[0]);
|
||||
delayLine_[1].setDelay((long)delay_[1]);
|
||||
|
||||
// Calculate a triangular envelope.
|
||||
env_[1] = fabs( (delay_[0] - halfLength + 12) * (1.0 / (halfLength+12) ) );
|
||||
env_[0] = 1.0 - env_[1];
|
||||
|
||||
// Delay input and apply envelope.
|
||||
lastOutput_[0] = env_[0] * delayLine_[0].tick(input);
|
||||
lastOutput_[0] += env_[1] * delayLine_[1].tick(input);
|
||||
|
||||
// Compute effect mix and output.
|
||||
lastOutput_[0] *= effectMix_;
|
||||
lastOutput_[0] += (1.0 - effectMix_) * input;
|
||||
lastOutput_[1] = lastOutput_[0];
|
||||
|
||||
return lastOutput_[0];
|
||||
return frames;
|
||||
}
|
||||
|
||||
StkFrames& PitShift :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
|
||||
errorString_ << "PitShift::tick(): channel and StkFrames arguments are incompatible!";
|
||||
handleError( StkError::FUNCTION_ARGUMENT );
|
||||
}
|
||||
#endif
|
||||
|
||||
StkFloat *iSamples = &iFrames[iChannel];
|
||||
StkFloat *oSamples = &oFrames[oChannel];
|
||||
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
|
||||
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
|
||||
*oSamples = tick( *iSamples );
|
||||
|
||||
return iFrames;
|
||||
}
|
||||
|
||||
} // stk namespace
|
||||
|
||||
Reference in New Issue
Block a user