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