Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Delay.h
1 #ifndef STK_DELAY_H
2 #define STK_DELAY_H
3 
4 #include "Filter.h"
5 
6 namespace stk {
7 
8 /***************************************************/
22 /***************************************************/
23 
24 class Delay : public Filter
25 {
26 public:
27 
29 
34  Delay( unsigned long delay = 0, unsigned long maxDelay = 4095 );
35 
37  ~Delay();
38 
40  unsigned long getMaximumDelay( void ) { return inputs_.size() - 1; };
41 
43 
50  void setMaximumDelay( unsigned long delay );
51 
53 
56  void setDelay( unsigned long delay );
57 
59  unsigned long getDelay( void ) const { return delay_; };
60 
62 
67  StkFloat tapOut( unsigned long tapDelay );
68 
70  void tapIn( StkFloat value, unsigned long tapDelay );
71 
73 
78  StkFloat addTo( StkFloat value, unsigned long tapDelay );
79 
81  StkFloat lastOut( void ) const { return lastFrame_[0]; };
82 
84 
87  StkFloat nextOut( void ) { return inputs_[outPoint_]; };
88 
90  StkFloat energy( void ) const;
91 
93  StkFloat tick( StkFloat input );
94 
96 
104  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
105 
107 
115  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
116 
117 protected:
118 
119  unsigned long inPoint_;
120  unsigned long outPoint_;
121  unsigned long delay_;
122 };
123 
124 inline StkFloat Delay :: tick( StkFloat input )
125 {
126  inputs_[inPoint_++] = input * gain_;
127 
128  // Check for end condition
129  if ( inPoint_ == inputs_.size() )
130  inPoint_ = 0;
131 
132  // Read out next value
133  lastFrame_[0] = inputs_[outPoint_++];
134 
135  if ( outPoint_ == inputs_.size() )
136  outPoint_ = 0;
137 
138  return lastFrame_[0];
139 }
140 
141 inline StkFrames& Delay :: tick( StkFrames& frames, unsigned int channel )
142 {
143 #if defined(_STK_DEBUG_)
144  if ( channel >= frames.channels() ) {
145  oStream_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
146  handleError( StkError::FUNCTION_ARGUMENT );
147  }
148 #endif
149 
150  StkFloat *samples = &frames[channel];
151  unsigned int hop = frames.channels();
152  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
153  inputs_[inPoint_++] = *samples * gain_;
154  if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
155  *samples = inputs_[outPoint_++];
156  if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
157  }
158 
159  lastFrame_[0] = *(samples-hop);
160  return frames;
161 }
162 
163 inline StkFrames& Delay :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
164 {
165 #if defined(_STK_DEBUG_)
166  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
167  oStream_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
168  handleError( StkError::FUNCTION_ARGUMENT );
169  }
170 #endif
171 
172  StkFloat *iSamples = &iFrames[iChannel];
173  StkFloat *oSamples = &oFrames[oChannel];
174  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
175  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
176  inputs_[inPoint_++] = *iSamples * gain_;
177  if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
178  *oSamples = inputs_[outPoint_++];
179  if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
180  }
181 
182  lastFrame_[0] = *(oSamples-oHop);
183  return iFrames;
184 }
185 
186 } // stk namespace
187 
188 #endif

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