The Synthesis ToolKit in C++ (STK)

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
7namespace stk {
8
9/***************************************************/
18/***************************************************/
19
20const 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
stk::DelayL
STK linear interpolating delay line class.
Definition: DelayL.h:28
stk::DelayL::setDelay
void setDelay(StkFloat delay)
Set the delay-line length.
Definition: DelayL.h:136
stk::Effect
STK abstract effects parent class.
Definition: Effect.h:22
stk::PitShift
STK simple pitch shifter effect class.
Definition: PitShift.h:23
stk::PitShift::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: PitShift.h:35
stk::PitShift::setShift
void setShift(StkFloat shift)
Set the pitch shift factor (1.0 produces no shift).
stk::PitShift::tick
StkFloat tick(StkFloat input)
Input one sample to the effect and return one output.
Definition: PitShift.h:73
stk::PitShift::tick
StkFrames & tick(StkFrames &iFrames, StkFrames &oFrames, unsigned int iChannel=0, unsigned int oChannel=0)
Take a channel of the iFrames object as inputs to the effect and write outputs to the oFrames object.
stk::PitShift::tick
StkFrames & tick(StkFrames &frames, unsigned int channel=0)
Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs...
stk::PitShift::PitShift
PitShift(void)
Class constructor.
stk::PitShift::clear
void clear(void)
Reset and clear all internal state.
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:279
stk
The STK namespace.
Definition: ADSR.h:6

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