Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

PitShift.h
1 #ifndef STK_PITSHIFT_H
2 #define STK_PITSHIFT_H
3
4 #include "Effect.h"
5 #include "DelayL.h"
6
7 namespace stk {
8
9 /***************************************************/
18 /***************************************************/
19
20 const int maxDelay = 5024;
21
22 class PitShift : public Effect
23 {
24 public:
26 PitShift( void );
27
29 void clear( void );
30
32 void setShift( StkFloat shift );
33
35 StkFloat lastOut( void ) const { return lastFrame_[0]; };
36
38 StkFloat tick( StkFloat input );
39
41
49 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
50
52
60 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
61
62 protected:
63
64 DelayL delayLine_[2];
65 StkFloat delay_[2];
66 StkFloat env_[2];
67 StkFloat rate_;
68 unsigned long delayLength_;
69 unsigned long halfLength_;
70
71 };
72
73 inline StkFloat PitShift :: tick( StkFloat input )
74 {
75 // Calculate the two delay length values, keeping them within the
76 // range 12 to maxDelay-12.
77 delay_[0] += rate_;
78 while ( delay_[0] > maxDelay-12 ) delay_[0] -= delayLength_;
79 while ( delay_[0] < 12 ) delay_[0] += delayLength_;
80
81 delay_[1] = delay_[0] + halfLength_;
82 while ( delay_[1] > maxDelay-12 ) delay_[1] -= delayLength_;
83 while ( delay_[1] < 12 ) delay_[1] += delayLength_;
84
85 // Set the new delay line lengths.
86 delayLine_[0].setDelay( delay_[0] );
87 delayLine_[1].setDelay( delay_[1] );
88
89 // Calculate a triangular envelope.
90 env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
91 env_[0] = 1.0 - env_[1];
92
93 // Delay input and apply envelope.
94 lastFrame_[0] = env_[0] * delayLine_[0].tick( input );
95 lastFrame_[0] += env_[1] * delayLine_[1].tick( input );
96
97 // Compute effect mix and output.
98 lastFrame_[0] *= effectMix_;
99 lastFrame_[0] += ( 1.0 - effectMix_ ) * input;
100
101 return lastFrame_[0];
102 }
103
104 } // stk namespace
105
106 #endif
107

The Synthesis ToolKit in C++ (STK)
©1995--2017 Perry R. Cook and Gary P. Scavone. All Rights Reserved.