Arduino STK  4.6.2
NRev.h
1 #ifndef STK_NREV_H
2 #define STK_NREV_H
3 
4 #include "Effect.h"
5 #include "Delay.h"
6 
7 namespace stk {
8 
9 /***************************************************/
23 /***************************************************/
24 
25 class NRev : public Effect
26 {
27  public:
29  NRev( StkFloat T60 = 1.0 );
30 
32  void clear( void );
33 
35  void setT60( StkFloat T60 );
36 
38 
46  StkFloat lastOut( unsigned int channel = 0 );
47 
49 
56  StkFloat tick( StkFloat input, unsigned int channel = 0 );
57 
59 
68  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
69 
71 
80  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
81 
82  protected:
83 
84  Delay allpassDelays_[8];
85  Delay combDelays_[6];
86  StkFloat allpassCoefficient_;
87  StkFloat combCoefficient_[6];
88  StkFloat lowpassState_;
89 
90 };
91 
92 inline StkFloat NRev :: lastOut( unsigned int channel )
93 {
94 #if defined(_STK_DEBUG_)
95  if ( channel > 1 ) {
96  oStream_ << "NRev::lastOut(): channel argument must be less than 2!";
97  handleError( StkError::FUNCTION_ARGUMENT );
98  }
99 #endif
100 
101  return lastFrame_[channel];
102 }
103 
104 inline StkFloat NRev :: tick( StkFloat input, unsigned int channel )
105 {
106 #if defined(_STK_DEBUG_)
107  if ( channel > 1 ) {
108  oStream_ << "NRev::tick(): channel argument must be less than 2!";
109  handleError( StkError::FUNCTION_ARGUMENT );
110  }
111 #endif
112 
113  StkFloat temp, temp0, temp1, temp2, temp3;
114  int i;
115 
116  temp0 = 0.0;
117  for ( i=0; i<6; i++ ) {
118  temp = input + (combCoefficient_[i] * combDelays_[i].lastOut());
119  temp0 += combDelays_[i].tick(temp);
120  }
121 
122  for ( i=0; i<3; i++ ) {
123  temp = allpassDelays_[i].lastOut();
124  temp1 = allpassCoefficient_ * temp;
125  temp1 += temp0;
126  allpassDelays_[i].tick(temp1);
127  temp0 = -(allpassCoefficient_ * temp1) + temp;
128  }
129 
130  // One-pole lowpass filter.
131  lowpassState_ = 0.7 * lowpassState_ + 0.3 * temp0;
132  temp = allpassDelays_[3].lastOut();
133  temp1 = allpassCoefficient_ * temp;
134  temp1 += lowpassState_;
135  allpassDelays_[3].tick( temp1 );
136  temp1 = -( allpassCoefficient_ * temp1 ) + temp;
137 
138  temp = allpassDelays_[4].lastOut();
139  temp2 = allpassCoefficient_ * temp;
140  temp2 += temp1;
141  allpassDelays_[4].tick( temp2 );
142  lastFrame_[0] = effectMix_*( -( allpassCoefficient_ * temp2 ) + temp );
143 
144  temp = allpassDelays_[5].lastOut();
145  temp3 = allpassCoefficient_ * temp;
146  temp3 += temp1;
147  allpassDelays_[5].tick( temp3 );
148  lastFrame_[1] = effectMix_*( - ( allpassCoefficient_ * temp3 ) + temp );
149 
150  temp = ( 1.0 - effectMix_ ) * input;
151  lastFrame_[0] += temp;
152  lastFrame_[1] += temp;
153 
154  return lastFrame_[channel];
155 }
156 
157 } // stk namespace
158 
159 #endif
160 
STK non-interpolating delay line class.
Definition: Delay.h:25
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: Delay.h:124
StkFloat lastOut(void) const
Return the last computed output value.
Definition: Delay.h:81
STK abstract effects parent class.
Definition: Effect.h:22
CCRMA's NRev reverberator class.
Definition: NRev.h:26
StkFrames & tick(StkFrames &iFrames, StkFrames &oFrames, unsigned int iChannel=0, unsigned int oChannel=0)
Take a channel of the iFrames object as inputs to the effect and write stereo outputs to the oFrames ...
StkFrames & tick(StkFrames &frames, unsigned int channel=0)
Take a channel of the StkFrames object as inputs to the effect and replace with stereo outputs.
void clear(void)
Reset and clear all internal state.
NRev(StkFloat T60=1.0)
Class constructor taking a T60 decay time argument (one second default value).
void setT60(StkFloat T60)
Set the reverberation T60 decay time.
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed stereo frame.
Definition: NRev.h:92
StkFloat tick(StkFloat input, unsigned int channel=0)
Input one sample to the effect and return the specified channel value of the computed stereo frame.
Definition: NRev.h:104
An STK class to handle vectorized audio data.
Definition: Stk.h:287
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
The STK namespace.
Definition: ADSR.h:8