Audio plugin host https://kx.studio/carla
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.

167 lines
5.6KB

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