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_;
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_.setDelay( delay_[0] );
87
88 // Calculate a triangular envelope.
89 env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
90 env_[0] = 1.0 - env_[1];
91
92 // Delay input and apply envelope.
93 lastFrame_[0] = env_[1] * delayLine_.tapOut( delay_[1] );
94 lastFrame_[0] = +env_[0] * delayLine_.tick( input );
95
96 // Compute effect mix and output.
97 lastFrame_[0] *= effectMix_;
98 lastFrame_[0] += ( 1.0 - effectMix_ ) * input;
99
100 return lastFrame_[0];
101}
102
103} // stk namespace
104
105#endif
106
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--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.