The Synthesis ToolKit in C++ (STK)

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
6namespace stk {
7
8/***************************************************/
22/***************************************************/
23
24 class Delay : public Filter
25{
26public:
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
117protected:
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
stk::Delay
STK non-interpolating delay line class.
Definition Delay.h:25
stk::Delay::setMaximumDelay
void setMaximumDelay(unsigned long delay)
Set the maximum delay-line length.
stk::Delay::energy
StkFloat energy(void) const
Calculate and return the signal energy in the delay-line.
stk::Delay::nextOut
StkFloat nextOut(void)
Return the value that will be output by the next call to tick().
Definition Delay.h:87
stk::Delay::~Delay
~Delay()
Class destructor.
stk::Delay::getMaximumDelay
unsigned long getMaximumDelay(void)
Get the maximum delay-line length.
Definition Delay.h:40
stk::Delay::tapOut
StkFloat tapOut(unsigned long tapDelay)
Return the value at tapDelay samples from the delay-line input.
stk::Delay::setDelay
void setDelay(unsigned long delay)
Set the delay-line length.
stk::Delay::getDelay
unsigned long getDelay(void) const
Return the current delay-line length.
Definition Delay.h:59
stk::Delay::addTo
StkFloat addTo(StkFloat value, unsigned long tapDelay)
Sum the provided value into the delay line at tapDelay samples from the input.
stk::Delay::Delay
Delay(unsigned long delay=0, unsigned long maxDelay=4095)
The default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
stk::Delay::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition Delay.h:124
stk::Delay::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition Delay.h:81
stk::Delay::tapIn
void tapIn(StkFloat value, unsigned long tapDelay)
Set the value at tapDelay samples from the delay-line input.
stk::Filter
STK abstract filter class.
Definition Filter.h:23
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::StkFrames::size
size_t size() const
Returns the total number of audio samples represented by the object.
Definition Stk.h:374
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.