Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Echo.h
1 #ifndef STK_ECHO_H
2 #define STK_ECHO_H
3
4 #include "Effect.h"
5 #include "Delay.h"
6
7 namespace stk {
8
9 /***************************************************/
17 /***************************************************/
18
19 class Echo : public Effect
20 {
21 public:
23
26 Echo( unsigned long maximumDelay = (unsigned long) Stk::sampleRate() );
27
29 void clear();
30
32 void setMaximumDelay( unsigned long delay );
33
35 void setDelay( unsigned long delay );
36
38 StkFloat lastOut( void ) const { return lastFrame_[0]; };
39
41 StkFloat tick( StkFloat input );
42
44
52 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
53
55
63 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
64
65 protected:
66
67 Delay delayLine_;
68 unsigned long length_;
69
70 };
71
72 inline StkFloat Echo :: tick( StkFloat input )
73 {
74 lastFrame_[0] = effectMix_ * ( delayLine_.tick( input ) - input ) + input;
75 return lastFrame_[0];
76 }
77
78 inline StkFrames& Echo :: tick( StkFrames& frames, unsigned int channel )
79 {
80 #if defined(_STK_DEBUG_)
81 if ( channel >= frames.channels() ) {
82 oStream_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
83 handleError( StkError::FUNCTION_ARGUMENT );
84 }
85 #endif
86
87 StkFloat *samples = &frames[channel];
88 unsigned int hop = frames.channels();
89 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
90 *samples = effectMix_ * ( delayLine_.tick( *samples ) - *samples ) + *samples;
91 }
92
93 lastFrame_[0] = *(samples-hop);
94 return frames;
95 }
96
97 inline StkFrames& Echo :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
98 {
99 #if defined(_STK_DEBUG_)
100 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
101 oStream_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
102 handleError( StkError::FUNCTION_ARGUMENT );
103 }
104 #endif
105
106 StkFloat *iSamples = &iFrames[iChannel];
107 StkFloat *oSamples = &oFrames[oChannel];
108 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
109 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
110 *oSamples = effectMix_ * ( delayLine_.tick( *iSamples ) - *iSamples ) + *iSamples;
111 }
112
113 lastFrame_[0] = *(oSamples-oHop);
114 return iFrames;
115 }
116
117 } // stk namespace
118
119 #endif
120

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