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.

141 lines
4.7KB

  1. #ifndef STK_PRCREV_H
  2. #define STK_PRCREV_H
  3. #include "Effect.h"
  4. #include "Delay.h"
  5. namespace stk {
  6. /***************************************************/
  7. /*! \class PRCRev
  8. \brief Perry's simple reverberator class.
  9. This class takes a monophonic input signal and produces a stereo
  10. output signal. It is based on some of the famous Stanford/CCRMA
  11. reverbs (NRev, KipRev), which were based on the
  12. Chowning/Moorer/Schroeder reverberators using networks of simple
  13. allpass and comb delay filters. This class implements two series
  14. allpass units and two parallel comb filters.
  15. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  16. */
  17. /***************************************************/
  18. class PRCRev : public Effect
  19. {
  20. public:
  21. //! Class constructor taking a T60 decay time argument (one second default value).
  22. PRCRev( StkFloat T60 = 1.0 );
  23. //! Reset and clear all internal state.
  24. void clear( void );
  25. //! Set the reverberation T60 decay time.
  26. void setT60( StkFloat T60 );
  27. //! Return the specified channel value of the last computed stereo frame.
  28. /*!
  29. Use the lastFrame() function to get both values of the last
  30. computed stereo frame. The \c channel argument must be 0 or 1
  31. (the first channel is specified by 0). However, range checking is
  32. only performed if _STK_DEBUG_ is defined during compilation, in
  33. which case an out-of-range value will trigger an StkError
  34. exception.
  35. */
  36. StkFloat lastOut( unsigned int channel = 0 );
  37. //! Input one sample to the effect and return the specified \c channel value of the computed stereo frame.
  38. /*!
  39. Use the lastFrame() function to get both values of the computed
  40. stereo output frame. The \c channel argument must be 0 or 1 (the
  41. first channel is specified by 0). However, range checking is only
  42. performed if _STK_DEBUG_ is defined during compilation, in which
  43. case an out-of-range value will trigger an StkError exception.
  44. */
  45. StkFloat tick( StkFloat input, unsigned int channel = 0 );
  46. //! Take a channel of the StkFrames object as inputs to the effect and replace with stereo outputs.
  47. /*!
  48. The StkFrames argument reference is returned. The stereo
  49. outputs are written to the StkFrames argument starting at the
  50. specified \c channel. Therefore, the \c channel argument must be
  51. less than ( channels() - 1 ) of the StkFrames argument (the first
  52. channel is specified by 0). However, range checking is only
  53. performed if _STK_DEBUG_ is defined during compilation, in which
  54. case an out-of-range value will trigger an StkError exception.
  55. */
  56. StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
  57. //! Take a channel of the \c iFrames object as inputs to the effect and write stereo outputs to the \c oFrames object.
  58. /*!
  59. The \c iFrames object reference is returned. The \c iChannel
  60. argument must be less than the number of channels in the \c
  61. iFrames argument (the first channel is specified by 0). The \c
  62. oChannel argument must be less than ( channels() - 1 ) of the \c
  63. oFrames argument. However, range checking is only performed if
  64. _STK_DEBUG_ is defined during compilation, in which case an
  65. out-of-range value will trigger an StkError exception.
  66. */
  67. StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
  68. protected:
  69. Delay allpassDelays_[2];
  70. Delay combDelays_[2];
  71. StkFloat allpassCoefficient_;
  72. StkFloat combCoefficient_[2];
  73. };
  74. inline StkFloat PRCRev :: lastOut( unsigned int channel )
  75. {
  76. #if defined(_STK_DEBUG_)
  77. if ( channel > 1 ) {
  78. oStream_ << "PRCRev::lastOut(): channel argument must be less than 2!";
  79. handleError( StkError::FUNCTION_ARGUMENT );
  80. }
  81. #endif
  82. return lastFrame_[channel];
  83. }
  84. inline StkFloat PRCRev :: tick( StkFloat input, unsigned int channel )
  85. {
  86. #if defined(_STK_DEBUG_)
  87. if ( channel > 1 ) {
  88. oStream_ << "PRCRev::tick(): channel argument must be less than 2!";
  89. handleError( StkError::FUNCTION_ARGUMENT );
  90. }
  91. #endif
  92. StkFloat temp, temp0, temp1, temp2, temp3;
  93. temp = allpassDelays_[0].lastOut();
  94. temp0 = allpassCoefficient_ * temp;
  95. temp0 += input;
  96. allpassDelays_[0].tick(temp0);
  97. temp0 = -(allpassCoefficient_ * temp0) + temp;
  98. temp = allpassDelays_[1].lastOut();
  99. temp1 = allpassCoefficient_ * temp;
  100. temp1 += temp0;
  101. allpassDelays_[1].tick(temp1);
  102. temp1 = -(allpassCoefficient_ * temp1) + temp;
  103. temp2 = temp1 + ( combCoefficient_[0] * combDelays_[0].lastOut() );
  104. temp3 = temp1 + ( combCoefficient_[1] * combDelays_[1].lastOut() );
  105. lastFrame_[0] = effectMix_ * (combDelays_[0].tick(temp2));
  106. lastFrame_[1] = effectMix_ * (combDelays_[1].tick(temp3));
  107. temp = (1.0 - effectMix_) * input;
  108. lastFrame_[0] += temp;
  109. lastFrame_[1] += temp;
  110. return lastFrame_[channel];
  111. }
  112. } // stk namespace
  113. #endif