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.

88 lines
2.6KB

  1. /***************************************************/
  2. /*! \class TapDelay
  3. \brief STK non-interpolating tapped delay line class.
  4. This class implements a non-interpolating digital delay-line with
  5. an arbitrary number of output "taps". If the maximum length and
  6. tap delays are not specified during instantiation, a fixed maximum
  7. length of 4095 and a single tap delay of zero is set.
  8. A non-interpolating delay line is typically used in fixed
  9. delay-length applications, such as for reverberation.
  10. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  11. */
  12. /***************************************************/
  13. #include "TapDelay.h"
  14. namespace stk {
  15. TapDelay :: TapDelay( std::vector<unsigned long> taps, unsigned long maxDelay )
  16. {
  17. // Writing before reading allows delays from 0 to length-1.
  18. // If we want to allow a delay of maxDelay, we need a
  19. // delayline of length = maxDelay+1.
  20. if ( maxDelay < 1 ) {
  21. oStream_ << "TapDelay::TapDelay: maxDelay must be > 0!\n";
  22. handleError( StkError::FUNCTION_ARGUMENT );
  23. }
  24. for ( unsigned int i=0; i<taps.size(); i++ ) {
  25. if ( taps[i] > maxDelay ) {
  26. oStream_ << "TapDelay::TapDelay: maxDelay must be > than all tap delay values!\n";
  27. handleError( StkError::FUNCTION_ARGUMENT );
  28. }
  29. }
  30. if ( ( maxDelay + 1 ) > inputs_.size() )
  31. inputs_.resize( maxDelay + 1, 1, 0.0 );
  32. inPoint_ = 0;
  33. this->setTapDelays( taps );
  34. }
  35. TapDelay :: ~TapDelay()
  36. {
  37. }
  38. void TapDelay :: setMaximumDelay( unsigned long delay )
  39. {
  40. if ( delay < inputs_.size() ) return;
  41. for ( unsigned int i=0; i<delays_.size(); i++ ) {
  42. if ( delay < delays_[i] ) {
  43. oStream_ << "TapDelay::setMaximumDelay: argument (" << delay << ") less than a current tap delay setting (" << delays_[i] << ")!\n";
  44. handleError( StkError::WARNING ); return;
  45. }
  46. }
  47. inputs_.resize( delay + 1 );
  48. }
  49. void TapDelay :: setTapDelays( std::vector<unsigned long> taps )
  50. {
  51. for ( unsigned int i=0; i<taps.size(); i++ ) {
  52. if ( taps[i] > inputs_.size() - 1 ) { // The value is too big.
  53. oStream_ << "TapDelay::setTapDelay: argument (" << taps[i] << ") greater than maximum!\n";
  54. handleError( StkError::WARNING ); return;
  55. }
  56. }
  57. if ( taps.size() != outPoint_.size() ) {
  58. outPoint_.resize( taps.size() );
  59. delays_.resize( taps.size() );
  60. lastFrame_.resize( 1, (unsigned int)taps.size(), 0.0 );
  61. }
  62. for ( unsigned int i=0; i<taps.size(); i++ ) {
  63. // read chases write
  64. if ( inPoint_ >= taps[i] ) outPoint_[i] = inPoint_ - taps[i];
  65. else outPoint_[i] = inputs_.size() + inPoint_ - taps[i];
  66. delays_[i] = taps[i];
  67. }
  68. }
  69. } // stk namespace