You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0KB

  1. /***************************************************/
  2. /*! \class DelayL
  3. \brief STK linear interpolating delay line class.
  4. This class implements a fractional-length digital delay-line using
  5. first-order linear interpolation. If the delay and maximum length
  6. are not specified during instantiation, a fixed maximum length of
  7. 4095 and a delay of zero is set.
  8. Linear interpolation is an efficient technique for achieving
  9. fractional delay lengths, though it does introduce high-frequency
  10. signal attenuation to varying degrees depending on the fractional
  11. delay setting. The use of higher order Lagrange interpolators can
  12. typically improve (minimize) this attenuation characteristic.
  13. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  14. */
  15. /***************************************************/
  16. #include "DelayL.h"
  17. namespace stk {
  18. DelayL :: DelayL( StkFloat delay, unsigned long maxDelay )
  19. {
  20. if ( delay < 0.0 ) {
  21. oStream_ << "DelayL::DelayL: delay must be >= 0.0!";
  22. handleError( StkError::FUNCTION_ARGUMENT );
  23. }
  24. if ( delay > (StkFloat) maxDelay ) {
  25. oStream_ << "DelayL::DelayL: maxDelay must be > than delay argument!";
  26. handleError( StkError::FUNCTION_ARGUMENT );
  27. }
  28. // Writing before reading allows delays from 0 to length-1.
  29. if ( maxDelay + 1 > inputs_.size() )
  30. inputs_.resize( maxDelay + 1, 1, 0.0 );
  31. inPoint_ = 0;
  32. this->setDelay( delay );
  33. doNextOut_ = true;
  34. }
  35. DelayL :: ~DelayL()
  36. {
  37. }
  38. void DelayL :: setMaximumDelay( unsigned long delay )
  39. {
  40. if ( delay < inputs_.size() ) return;
  41. inputs_.resize(delay + 1, 1, 0.0);
  42. }
  43. StkFloat DelayL :: tapOut( unsigned long tapDelay )
  44. {
  45. long tap = inPoint_ - tapDelay - 1;
  46. while ( tap < 0 ) // Check for wraparound.
  47. tap += inputs_.size();
  48. return inputs_[tap];
  49. }
  50. void DelayL :: tapIn( StkFloat value, unsigned long tapDelay )
  51. {
  52. long tap = inPoint_ - tapDelay - 1;
  53. while ( tap < 0 ) // Check for wraparound.
  54. tap += inputs_.size();
  55. inputs_[tap] = value;
  56. }
  57. } // stk namespace