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
6namespace stk {
7
8/***************************************************/
26/***************************************************/
27
28 class DelayA : public Filter
29{
30public:
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
113protected:
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
stk::DelayA::nextOut
StkFloat nextOut(void)
Return the value which will be output by the next call to tick().
Definition DelayA.h:125
stk::DelayA::getMaximumDelay
unsigned long getMaximumDelay(void)
Get the maximum delay-line length.
Definition DelayA.h:47
stk::DelayA::setDelay
void setDelay(StkFloat delay)
Set the delay-line length.
stk::DelayA::getDelay
StkFloat getDelay(void) const
Return the current delay-line length.
Definition DelayA.h:66
stk::DelayA::DelayA
DelayA(StkFloat delay=0.5, unsigned long maxDelay=4095)
Default constructor creates a delay-line with maximum length of 4095 samples and delay = 0....
stk::DelayA::tapOut
StkFloat tapOut(unsigned long tapDelay)
Return the value at tapDelay samples from the delay-line input.
stk::DelayA::setMaximumDelay
void setMaximumDelay(unsigned long delay)
Set the maximum delay-line length.
stk::DelayA::~DelayA
~DelayA()
Class destructor.
stk::DelayA::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition DelayA.h:80
stk::DelayA::tapIn
void tapIn(StkFloat value, unsigned long tapDelay)
Set the value at tapDelay samples from the delay-line input.
stk::DelayA::clear
void clear(void)
Clears all internal states of the delay line.
stk::DelayA::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition DelayA.h:137
stk::Filter::Filter
Filter(void)
Class constructor.
Definition Filter.h:26
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk
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.