1 /***************************************************/ 2 /*! \class Delay 3 \brief STK non-interpolating delay line class. 4 5 This protected Filter subclass implements 6 a non-interpolating digital delay-line. 7 A fixed maximum length of 4095 and a delay 8 of zero is set using the default constructor. 9 Alternatively, the delay and maximum length 10 can be set during instantiation with an 11 overloaded constructor. 12 13 A non-interpolating delay line is typically 14 used in fixed delay-length applications, such 15 as for reverberation. 16 17 by Perry R. Cook and Gary P. Scavone, 1995 - 2005. 18 */ 19 /***************************************************/ 20 21 #ifndef STK_DELAY_H 22 #define STK_DELAY_H 23 24 #include "Filter.h" 25 26 namespace Nyq 27 { 28 29 class Delay : protected Filter 30 { 31 public: 32 33 //! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay. 34 Delay(); 35 36 //! Overloaded constructor which specifies the current and maximum delay-line lengths. 37 /*! 38 An StkError will be thrown if the delay parameter is less than 39 zero, the maximum delay parameter is less than one, or the delay 40 parameter is greater than the maxDelay value. 41 */ 42 Delay(unsigned long delay, unsigned long maxDelay); 43 44 //! Class destructor. 45 virtual ~Delay(); 46 47 //! Clears the internal state of the delay line. 48 void clear(); 49 50 //! Set the maximum delay-line length. 51 /*! 52 This method should generally only be used during initial setup 53 of the delay line. If it is used between calls to the tick() 54 function, without a call to clear(), a signal discontinuity will 55 likely occur. If the current maximum length is greater than the 56 new length, no change will be made. 57 */ 58 void setMaximumDelay(unsigned long delay); 59 60 //! Set the delay-line length. 61 /*! 62 The valid range for \e theDelay is from 0 to the maximum delay-line length. 63 */ 64 void setDelay(unsigned long delay); 65 66 //! Return the current delay-line length. 67 unsigned long getDelay(void) const; 68 69 //! Calculate and return the signal energy in the delay-line. 70 StkFloat energy(void) const; 71 72 //! Return the value at \e tapDelay samples from the delay-line input. 73 /*! 74 The tap point is determined modulo the delay-line length and is 75 relative to the last input value (i.e., a tapDelay of zero returns 76 the last input value). 77 */ 78 StkFloat contentsAt(unsigned long tapDelay); 79 80 //! Return the last computed output value. 81 StkFloat lastOut(void) const; 82 83 //! Return the value which will be output by the next call to tick(). 84 /*! 85 This method is valid only for delay settings greater than zero! 86 */ 87 virtual StkFloat nextOut(void); 88 89 //! Input one sample to the filter and return one output. 90 virtual StkFloat tick(StkFloat sample); 91 92 //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs. 93 /*! 94 The \c channel argument should be zero or greater (the first 95 channel is specified by 0). An StkError will be thrown if the \c 96 channel argument is equal to or greater than the number of 97 channels in the StkFrames object. 98 */ 99 virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 100 101 protected: 102 103 // This function must be implemented in all subclasses. It is used 104 // to get around a C++ problem with overloaded virtual functions. 105 virtual StkFloat computeSample( StkFloat input ); 106 107 unsigned long inPoint_; 108 unsigned long outPoint_; 109 StkFloat delay_; 110 }; 111 112 } // namespace Nyq 113 114 #endif 115 116