Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Public Member Functions | List of all members
stk::TapDelay Class Reference

STK non-interpolating tapped delay line class. More...

#include <TapDelay.h>

Inheritance diagram for stk::TapDelay:
stk::Filter stk::Stk

Public Member Functions

 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 delay = 0. More...
 
 ~TapDelay ()
 Class destructor.
 
void setMaximumDelay (unsigned long delay)
 Set the maximum delay-line length. More...
 
void setTapDelays (std::vector< unsigned long > taps)
 Set the delay-line tap lengths. More...
 
std::vector< unsigned long > getTapDelays (void) const
 Return the current delay-line length.
 
StkFloat lastOut (unsigned int tap=0) const
 Return the specified tap value of the last computed frame. More...
 
StkFramestick (StkFloat input, StkFrames &outputs)
 Input one sample to the delayline and return outputs at all tap positions. More...
 
StkFramestick (StkFrames &frames, unsigned int channel=0)
 Take a channel of the StkFrames object as inputs to the filter and write outputs back to the same object. More...
 
StkFramestick (StkFrames &iFrames, StkFrames &oFrames, unsigned int iChannel=0)
 Take a channel of the iFrames object as inputs to the filter and write outputs to the oFrames object. More...
 
- Public Member Functions inherited from stk::Filter
 Filter (void)
 Class constructor.
 
unsigned int channelsIn (void) const
 Return the number of input channels for the class.
 
unsigned int channelsOut (void) const
 Return the number of output channels for the class.
 
virtual void clear (void)
 Clears all internal states of the filter.
 
void setGain (StkFloat gain)
 Set the filter gain. More...
 
StkFloat getGain (void) const
 Return the current filter gain.
 
StkFloat phaseDelay (StkFloat frequency)
 Return the filter phase delay at the specified frequency. More...
 
const StkFrameslastFrame (void) const
 Return an StkFrames reference to the last output sample frame.
 
- Public Member Functions inherited from stk::Stk
void ignoreSampleRateChange (bool ignore=true)
 A function to enable/disable the automatic updating of class data when the STK sample rate changes. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from stk::Stk
static StkFloat sampleRate (void)
 Static method that returns the current STK sample rate.
 
static void setSampleRate (StkFloat rate)
 Static method that sets the STK sample rate. More...
 
static std::string rawwavePath (void)
 Static method that returns the current rawwave path.
 
static void setRawwavePath (std::string path)
 Static method that sets the STK rawwave path.
 
static void swap16 (unsigned char *ptr)
 Static method that byte-swaps a 16-bit data type.
 
static void swap32 (unsigned char *ptr)
 Static method that byte-swaps a 32-bit data type.
 
static void swap64 (unsigned char *ptr)
 Static method that byte-swaps a 64-bit data type.
 
static void sleep (unsigned long milliseconds)
 Static cross-platform method to sleep for a number of milliseconds.
 
static bool inRange (StkFloat value, StkFloat min, StkFloat max)
 Static method to check whether a value is within a specified range.
 
static void handleError (const char *message, StkError::Type type)
 Static function for error reporting and handling using c-strings.
 
static void handleError (std::string message, StkError::Type type)
 Static function for error reporting and handling using c++ strings.
 
static void showWarnings (bool status)
 Toggle display of WARNING and STATUS messages.
 
static void printErrors (bool status)
 Toggle display of error messages before throwing exceptions.
 
- Static Public Attributes inherited from stk::Stk
static const StkFormat STK_SINT8
 
static const StkFormat STK_SINT16
 
static const StkFormat STK_SINT24
 
static const StkFormat STK_SINT32
 
static const StkFormat STK_FLOAT32
 
static const StkFormat STK_FLOAT64
 
- Protected Member Functions inherited from stk::Stk
 Stk (void)
 Default constructor.
 
virtual ~Stk (void)
 Class destructor.
 
virtual void sampleRateChanged (StkFloat newRate, StkFloat oldRate)
 This function should be implemented in subclasses that depend on the sample rate.
 
void addSampleRateAlert (Stk *ptr)
 Add class pointer to list for sample rate change notification.
 
void removeSampleRateAlert (Stk *ptr)
 Remove class pointer from list for sample rate change notification.
 
void handleError (StkError::Type type) const
 Internal function for error reporting that assumes message in oStream_ variable.
 

Detailed Description

STK non-interpolating tapped delay line class.

This class implements a non-interpolating digital delay-line with an arbitrary number of output "taps". If the maximum length and tap delays are not specified during instantiation, a fixed maximum length of 4095 and a single tap delay of zero is set.

A non-interpolating delay line is typically used in fixed delay-length applications, such as for reverberation.

by Perry R. Cook and Gary P. Scavone, 1995–2014.

Constructor & Destructor Documentation

stk::TapDelay::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 delay = 0.

An StkError will be thrown if any tap delay parameter is less than zero, the maximum delay parameter is less than one, or any tap delay parameter is greater than the maxDelay value.

Member Function Documentation

void stk::TapDelay::setMaximumDelay ( unsigned long  delay)

Set the maximum delay-line length.

This method should generally only be used during initial setup of the delay line. If it is used between calls to the tick() function, without a call to clear(), a signal discontinuity will likely occur. If the current maximum length is greater than the new length, no change will be made.

void stk::TapDelay::setTapDelays ( std::vector< unsigned long >  taps)

Set the delay-line tap lengths.

The valid range for each tap length is from 0 to the maximum delay-line length.

StkFloat stk::TapDelay::lastOut ( unsigned int  tap = 0) const
inline

Return the specified tap value of the last computed frame.

Use the lastFrame() function to get all tap values from the last computed frame. The tap argument must be less than the number of delayline taps (the first tap is specified by 0). However, range checking is only performed if STK_DEBUG is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

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 }
StkFrames & stk::TapDelay::tick ( StkFloat  input,
StkFrames outputs 
)
inline

Input one sample to the delayline and return outputs at all tap positions.

The StkFrames argument reference is returned. The output values are ordered according to the tap positions set using the setTapDelays() function (no sorting is performed). The StkFrames argument must contain at least as many channels as the number of taps. However, range checking is only performed if STK_DEBUG is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

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 }
StkFrames & stk::TapDelay::tick ( StkFrames frames,
unsigned int  channel = 0 
)
inlinevirtual

Take a channel of the StkFrames object as inputs to the filter and write outputs back to the same object.

The StkFrames argument reference is returned. The output values are ordered according to the tap positions set using the setTapDelays() function (no sorting is performed). The StkFrames argument must contain at least as many channels as the number of taps. However, range checking is only performed if STK_DEBUG is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

Implements stk::Filter.

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 }
StkFrames & stk::TapDelay::tick ( StkFrames iFrames,
StkFrames oFrames,
unsigned int  iChannel = 0 
)
inline

Take a channel of the iFrames object as inputs to the filter and write outputs to the oFrames object.

The iFrames object reference is returned. The output values are ordered according to the tap positions set using the setTapDelays() function (no sorting is performed). The iChannel argument must be less than the number of channels in the iFrames argument (the first channel is specified by 0). The oFrames argument must contain at least as many channels as the number of taps. However, range checking is only performed if STK_DEBUG is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

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 }

The documentation for this class was generated from the following file:

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