Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


TapDelay.h
1#ifndef STK_TAPDELAY_H
2#define STK_TAPDELAY_H
3
4#include "Filter.h"
5
6namespace stk {
7
8/***************************************************/
22/***************************************************/
23
24class TapDelay : public Filter
25{
26 public:
27
29
34 TapDelay( std::vector<unsigned long> taps = std::vector<unsigned long>( 1, 0 ), unsigned long maxDelay = 4095 );
35
38
40
47 void setMaximumDelay( unsigned long delay );
48
50
53 void setTapDelays( std::vector<unsigned long> taps );
54
56 std::vector<unsigned long> getTapDelays( void ) const { return delays_; };
57
59
67 StkFloat lastOut( unsigned int tap = 0 ) const;
68
70
79 StkFrames& tick( StkFloat input, StkFrames& outputs );
80
82
91 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
92
94
105 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0 );
106
107 protected:
108
109 unsigned long inPoint_;
110 std::vector<unsigned long> outPoint_;
111 std::vector<unsigned long> delays_;
112
113};
114
115inline StkFloat TapDelay :: lastOut( unsigned int tap ) const
116{
117#if defined(_STK_DEBUG_)
118 if ( tap >= lastFrame_.size() ) {
119 oStream_ << "TapDelay::lastOut(): tap argument and number of taps are incompatible!";
120 handleError( StkError::FUNCTION_ARGUMENT );
121 }
122#endif
123
124 return lastFrame_[tap];
125}
126
127inline StkFrames& TapDelay :: tick( StkFloat input, StkFrames& outputs )
128{
129#if defined(_STK_DEBUG_)
130 if ( outputs.channels() < outPoint_.size() ) {
131 oStream_ << "TapDelay::tick(): number of taps > channels in StkFrames argument!";
132 handleError( StkError::FUNCTION_ARGUMENT );
133 }
134#endif
135
136 inputs_[inPoint_++] = input * gain_;
137
138 // Check for end condition
139 if ( inPoint_ == inputs_.size() )
140 inPoint_ = 0;
141
142 // Read out next values
143 StkFloat *outs = &outputs[0];
144 for ( unsigned int i=0; i<outPoint_.size(); i++ ) {
145 *outs++ = inputs_[outPoint_[i]];
146 lastFrame_[i] = *outs;
147 if ( ++outPoint_[i] == inputs_.size() )
148 outPoint_[i] = 0;
149 }
150
151 return outputs;
152}
153
154inline StkFrames& TapDelay :: tick( StkFrames& frames, unsigned int channel )
155{
156#if defined(_STK_DEBUG_)
157 if ( channel >= frames.channels() ) {
158 oStream_ << "TapDelay::tick(): channel and StkFrames arguments are incompatible!";
159 handleError( StkError::FUNCTION_ARGUMENT );
160 }
161 if ( frames.channels() < outPoint_.size() ) {
162 oStream_ << "TapDelay::tick(): number of taps > channels in StkFrames argument!";
163 handleError( StkError::FUNCTION_ARGUMENT );
164 }
165#endif
166
167 StkFloat *iSamples = &frames[channel];
168 StkFloat *oSamples = &frames[0];
169 std::size_t j;
170 unsigned int iHop = frames.channels();
171 std::size_t oHop = frames.channels() - outPoint_.size();
172 for ( unsigned long i=0; i<frames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
173 inputs_[inPoint_++] = *iSamples * gain_;
174 if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
175 for ( j=0; j<outPoint_.size(); j++ ) {
176 *oSamples++ = inputs_[outPoint_[j]];
177 if ( ++outPoint_[j] == inputs_.size() ) outPoint_[j] = 0;
178 }
179 }
180
181 oSamples -= frames.channels();
182 for ( j=0; j<outPoint_.size(); j++ ) lastFrame_[j] = *oSamples++;
183 return frames;
184}
185
186inline StkFrames& TapDelay :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel )
187{
188#if defined(_STK_DEBUG_)
189 if ( iChannel >= iFrames.channels() ) {
190 oStream_ << "TapDelay::tick(): channel and StkFrames arguments are incompatible!";
191 handleError( StkError::FUNCTION_ARGUMENT );
192 }
193 if ( oFrames.channels() < outPoint_.size() ) {
194 oStream_ << "TapDelay::tick(): number of taps > channels in output StkFrames argument!";
195 handleError( StkError::FUNCTION_ARGUMENT );
196 }
197#endif
198
199 StkFloat *iSamples = &iFrames[iChannel];
200 StkFloat *oSamples = &oFrames[0];
201 std::size_t j;
202 unsigned int iHop = iFrames.channels();
203 std::size_t oHop = oFrames.channels() - outPoint_.size();
204 for ( unsigned long i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
205 inputs_[inPoint_++] = *iSamples * gain_;
206 if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
207 for ( j=0; j<outPoint_.size(); j++ ) {
208 *oSamples++ = inputs_[outPoint_[j]];
209 if ( ++outPoint_[j] == inputs_.size() ) outPoint_[j] = 0;
210 }
211 }
212
213 oSamples -= oFrames.channels();
214 for ( j=0; j<outPoint_.size(); j++ ) lastFrame_[j] = *oSamples++;
215 return iFrames;
216}
217
218} // stk namespace
219
220#endif
STK abstract filter class.
Definition Filter.h:23
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
STK non-interpolating tapped delay line class.
Definition TapDelay.h:25
void setMaximumDelay(unsigned long delay)
Set the maximum delay-line length.
TapDelay(std::vector< unsigned long > taps=std::vector< unsigned long >(1, 0), unsigned long maxDelay=4095)
The default constructor creates a delay-line with maximum length of 4095 samples and a single tap at ...
StkFloat lastOut(unsigned int tap=0) const
Return the specified tap value of the last computed frame.
Definition TapDelay.h:115
std::vector< unsigned long > getTapDelays(void) const
Return the current delay-line length.
Definition TapDelay.h:56
~TapDelay()
Class destructor.
void setTapDelays(std::vector< unsigned long > taps)
Set the delay-line tap lengths.
StkFrames & tick(StkFloat input, StkFrames &outputs)
Input one sample to the delayline and return outputs at all tap positions.
Definition TapDelay.h:127
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.