Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


DelayL.h
1 #ifndef STK_DELAYL_H
2 #define STK_DELAYL_H
3 
4 #include "Filter.h"
5 
6 namespace stk {
7 
8 /***************************************************/
25 /***************************************************/
26 
27 class DelayL : public Filter
28 {
29 public:
30 
32 
37  DelayL( StkFloat delay = 0.0, unsigned long maxDelay = 4095 );
38 
40  ~DelayL();
41 
43  unsigned long getMaximumDelay( void ) { return inputs_.size() - 1; };
44 
46 
53  void setMaximumDelay( unsigned long delay );
54 
56 
59  void setDelay( StkFloat delay );
60 
62  StkFloat getDelay( void ) const { return delay_; };
63 
65 
70  StkFloat tapOut( unsigned long tapDelay );
71 
73  void tapIn( StkFloat value, unsigned long tapDelay );
74 
76  StkFloat lastOut( void ) const { return lastFrame_[0]; };
77 
79 
82  StkFloat nextOut( void );
83 
85  StkFloat tick( StkFloat input );
86 
88 
96  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
97 
99 
107  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
108 
109  protected:
110 
111  unsigned long inPoint_;
112  unsigned long outPoint_;
113  StkFloat delay_;
114  StkFloat alpha_;
115  StkFloat omAlpha_;
116  StkFloat nextOutput_;
117  bool doNextOut_;
118 };
119 
120 inline StkFloat DelayL :: nextOut( void )
121 {
122  if ( doNextOut_ ) {
123  // First 1/2 of interpolation
124  nextOutput_ = inputs_[outPoint_] * omAlpha_;
125  // Second 1/2 of interpolation
126  if (outPoint_+1 < inputs_.size())
127  nextOutput_ += inputs_[outPoint_+1] * alpha_;
128  else
129  nextOutput_ += inputs_[0] * alpha_;
130  doNextOut_ = false;
131  }
132 
133  return nextOutput_;
134 }
135 
136 inline StkFloat DelayL :: tick( StkFloat input )
137 {
138  inputs_[inPoint_++] = input * gain_;
139 
140  // Increment input pointer modulo length.
141  if ( inPoint_ == inputs_.size() )
142  inPoint_ = 0;
143 
144  lastFrame_[0] = nextOut();
145  doNextOut_ = true;
146 
147  // Increment output pointer modulo length.
148  if ( ++outPoint_ == inputs_.size() )
149  outPoint_ = 0;
150 
151  return lastFrame_[0];
152 }
153 
154 inline StkFrames& DelayL :: tick( StkFrames& frames, unsigned int channel )
155 {
156 #if defined(_STK_DEBUG_)
157  if ( channel >= frames.channels() ) {
158  oStream_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!";
159  handleError( StkError::FUNCTION_ARGUMENT );
160  }
161 #endif
162 
163  StkFloat *samples = &frames[channel];
164  unsigned int hop = frames.channels();
165  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
166  inputs_[inPoint_++] = *samples * gain_;
167  if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
168  *samples = nextOut();
169  doNextOut_ = true;
170  if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0;
171  }
172 
173  lastFrame_[0] = *(samples-hop);
174  return frames;
175 }
176 
177 inline StkFrames& DelayL :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
178 {
179 #if defined(_STK_DEBUG_)
180  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
181  oStream_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!";
182  handleError( StkError::FUNCTION_ARGUMENT );
183  }
184 #endif
185 
186  StkFloat *iSamples = &iFrames[iChannel];
187  StkFloat *oSamples = &oFrames[oChannel];
188  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
189  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
190  inputs_[inPoint_++] = *iSamples * gain_;
191  if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
192  *oSamples = nextOut();
193  doNextOut_ = true;
194  if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0;
195  }
196 
197  lastFrame_[0] = *(oSamples-oHop);
198  return iFrames;
199 }
200 
201 } // stk namespace
202 
203 #endif

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