| 1 |
/***************************************************/ |
| 2 |
/*! \class JCRev |
| 3 |
\brief John Chowning's reverberator class. |
| 4 |
|
| 5 |
This class is derived from the CLM JCRev |
| 6 |
function, which is based on the use of |
| 7 |
networks of simple allpass and comb delay |
| 8 |
filters. This class implements three series |
| 9 |
allpass units, followed by four parallel comb |
| 10 |
filters, and two decorrelation delay lines in |
| 11 |
parallel at the output. |
| 12 |
|
| 13 |
by Perry R. Cook and Gary P. Scavone, 1995 - 2005. |
| 14 |
*/ |
| 15 |
/***************************************************/ |
| 16 |
|
| 17 |
#include "JCRev.h" |
| 18 |
#include <math.h> |
| 19 |
|
| 20 |
using namespace Nyq; |
| 21 |
|
| 22 |
JCRev :: JCRev(StkFloat T60) |
| 23 |
{ |
| 24 |
// Delay lengths for 44100 Hz sample rate. |
| 25 |
int lengths[9] = {1777, 1847, 1993, 2137, 389, 127, 43, 211, 179}; |
| 26 |
double scaler = Stk::sampleRate() / 44100.0; |
| 27 |
|
| 28 |
int delay, i; |
| 29 |
if ( scaler != 1.0 ) { |
| 30 |
for (i=0; i<9; i++) { |
| 31 |
delay = (int) floor(scaler * lengths[i]); |
| 32 |
if ( (delay & 1) == 0) delay++; |
| 33 |
while ( !this->isPrime(delay) ) delay += 2; |
| 34 |
lengths[i] = delay; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
for (i=0; i<3; i++) { |
| 39 |
allpassDelays_[i].setMaximumDelay( lengths[i+4] ); |
| 40 |
allpassDelays_[i].setDelay( lengths[i+4] ); |
| 41 |
} |
| 42 |
|
| 43 |
for ( i=0; i<4; i++ ) { |
| 44 |
combDelays_[i].setMaximumDelay( lengths[i] ); |
| 45 |
combDelays_[i].setDelay( lengths[i] ); |
| 46 |
} |
| 47 |
|
| 48 |
this->setT60( T60 ); |
| 49 |
outLeftDelay_.setMaximumDelay( lengths[7] ); |
| 50 |
outLeftDelay_.setDelay( lengths[7] ); |
| 51 |
outRightDelay_.setMaximumDelay( lengths[8] ); |
| 52 |
outRightDelay_.setDelay( lengths[8] ); |
| 53 |
allpassCoefficient_ = 0.7; |
| 54 |
effectMix_ = 0.3; |
| 55 |
this->clear(); |
| 56 |
} |
| 57 |
|
| 58 |
JCRev :: ~JCRev() |
| 59 |
{ |
| 60 |
} |
| 61 |
|
| 62 |
void JCRev :: clear() |
| 63 |
{ |
| 64 |
allpassDelays_[0].clear(); |
| 65 |
allpassDelays_[1].clear(); |
| 66 |
allpassDelays_[2].clear(); |
| 67 |
combDelays_[0].clear(); |
| 68 |
combDelays_[1].clear(); |
| 69 |
combDelays_[2].clear(); |
| 70 |
combDelays_[3].clear(); |
| 71 |
outRightDelay_.clear(); |
| 72 |
outLeftDelay_.clear(); |
| 73 |
lastOutput_[0] = 0.0; |
| 74 |
lastOutput_[1] = 0.0; |
| 75 |
} |
| 76 |
|
| 77 |
void JCRev :: setT60( StkFloat T60 ) |
| 78 |
{ |
| 79 |
for ( int i=0; i<4; i++ ) |
| 80 |
combCoefficient_[i] = pow(10.0, (-3.0 * combDelays_[i].getDelay() / (T60 * Stk::sampleRate()))); |
| 81 |
} |
| 82 |
|
| 83 |
StkFloat JCRev :: computeSample(StkFloat input) |
| 84 |
{ |
| 85 |
StkFloat temp, temp0, temp1, temp2, temp3, temp4, temp5, temp6; |
| 86 |
StkFloat filtout; |
| 87 |
|
| 88 |
temp = allpassDelays_[0].lastOut(); |
| 89 |
temp0 = allpassCoefficient_ * temp; |
| 90 |
temp0 += input; |
| 91 |
allpassDelays_[0].tick(temp0); |
| 92 |
temp0 = -(allpassCoefficient_ * temp0) + temp; |
| 93 |
|
| 94 |
temp = allpassDelays_[1].lastOut(); |
| 95 |
temp1 = allpassCoefficient_ * temp; |
| 96 |
temp1 += temp0; |
| 97 |
allpassDelays_[1].tick(temp1); |
| 98 |
temp1 = -(allpassCoefficient_ * temp1) + temp; |
| 99 |
|
| 100 |
temp = allpassDelays_[2].lastOut(); |
| 101 |
temp2 = allpassCoefficient_ * temp; |
| 102 |
temp2 += temp1; |
| 103 |
allpassDelays_[2].tick(temp2); |
| 104 |
temp2 = -(allpassCoefficient_ * temp2) + temp; |
| 105 |
|
| 106 |
temp3 = temp2 + (combCoefficient_[0] * combDelays_[0].lastOut()); |
| 107 |
temp4 = temp2 + (combCoefficient_[1] * combDelays_[1].lastOut()); |
| 108 |
temp5 = temp2 + (combCoefficient_[2] * combDelays_[2].lastOut()); |
| 109 |
temp6 = temp2 + (combCoefficient_[3] * combDelays_[3].lastOut()); |
| 110 |
|
| 111 |
combDelays_[0].tick(temp3); |
| 112 |
combDelays_[1].tick(temp4); |
| 113 |
combDelays_[2].tick(temp5); |
| 114 |
combDelays_[3].tick(temp6); |
| 115 |
|
| 116 |
filtout = temp3 + temp4 + temp5 + temp6; |
| 117 |
|
| 118 |
lastOutput_[0] = effectMix_ * (outLeftDelay_.tick(filtout)); |
| 119 |
lastOutput_[1] = effectMix_ * (outRightDelay_.tick(filtout)); |
| 120 |
temp = (1.0 - effectMix_) * input; |
| 121 |
lastOutput_[0] += temp; |
| 122 |
lastOutput_[1] += temp; |
| 123 |
|
| 124 |
return Effect::lastOut(); |
| 125 |
} |