The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

DelayA.h
1 #ifndef STK_DELAYA_H
2 #define STK_DELAYA_H
3
4 #include "Filter.h"
5
6 namespace stk {
7
8 /***************************************************/
26 /***************************************************/
27
28 class DelayA : public Filter
29 {
30 public:
31
33
38 DelayA( StkFloat delay = 0.5, unsigned long maxDelay = 4095 );
39
41 ~DelayA();
42
44 void clear( void );
45
47 unsigned long getMaximumDelay( void ) { return inputs_.size() - 1; };
48
50
57 void setMaximumDelay( unsigned long delay );
58
60
63 void setDelay( StkFloat delay );
64
66 StkFloat getDelay( void ) const { return delay_; };
67
69
74 StkFloat tapOut( unsigned long tapDelay );
75
77 void tapIn( StkFloat value, unsigned long tapDelay );
78
80 StkFloat lastOut( void ) const { return lastFrame_[0]; };
81
83
86 StkFloat nextOut( void );
87
89 StkFloat tick( StkFloat input );
90
92
100 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
101
103
111 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
112
113 protected:
114
115 unsigned long inPoint_;
116 unsigned long outPoint_;
117 StkFloat delay_;
118 StkFloat alpha_;
119 StkFloat coeff_;
120 StkFloat apInput_;
121 StkFloat nextOutput_;
122 bool doNextOut_;
123 };
124
125 inline StkFloat DelayA :: nextOut( void )
126 {
127 if ( doNextOut_ ) {
128 // Do allpass interpolation delay.
129 nextOutput_ = -coeff_ * lastFrame_[0];
130 nextOutput_ += apInput_ + ( coeff_ * inputs_[outPoint_] );
131 doNextOut_ = false;
132 }
133
134 return nextOutput_;
135 }
136
137 inline StkFloat DelayA :: tick( StkFloat input )
138 {
139 inputs_[inPoint_++] = input * gain_;
140
141 // Increment input pointer modulo length.
142 if ( inPoint_ == inputs_.size() )
143 inPoint_ = 0;
144
145 lastFrame_[0] = nextOut();
146 doNextOut_ = true;
147
148 // Save the allpass input and increment modulo length.
149 apInput_ = inputs_[outPoint_++];
150 if ( outPoint_ == inputs_.size() )
151 outPoint_ = 0;
152
153 return lastFrame_[0];
154 }
155
156 inline StkFrames& DelayA :: tick( StkFrames& frames, unsigned int channel )
157 {
158 #if defined(_STK_DEBUG_)
159 if ( channel >= frames.channels() ) {
160 oStream_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!";
161 handleError( StkError::FUNCTION_ARGUMENT );
162 }
163 #endif
164
165 StkFloat *samples = &frames[channel];
166 unsigned int hop = frames.channels();
167 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
168 inputs_[inPoint_++] = *samples * gain_;
169 if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
170 *samples = nextOut();
171 lastFrame_[0] = *samples;
172 doNextOut_ = true;
173 apInput_ = inputs_[outPoint_++];
174 if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
175 }
176
177 return frames;
178 }
179
180 inline StkFrames& DelayA :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
181 {
182 #if defined(_STK_DEBUG_)
183 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
184 oStream_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!";
185 handleError( StkError::FUNCTION_ARGUMENT );
186 }
187 #endif
188
189 StkFloat *iSamples = &iFrames[iChannel];
190 StkFloat *oSamples = &oFrames[oChannel];
191 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
192 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
193 inputs_[inPoint_++] = *iSamples * gain_;
194 if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
195 *oSamples = nextOut();
196 lastFrame_[0] = *oSamples;
197 doNextOut_ = true;
198 apInput_ = inputs_[outPoint_++];
199 if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
200 }
201
202 return iFrames;
203 }
204
205 } // stk namespace
206
207 #endif

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