Debian Codegraph @

lib-src/libnyquist/nyquist/nyqstk/src/PRCRev.cpp

raw
1 /***************************************************/
2 /*! \class PRCRev
3 \brief Perry's simple reverberator class.
4
5 This class is based on some of the famous
6 Stanford/CCRMA reverbs (NRev, KipRev), which
7 were based on the Chowning/Moorer/Schroeder
8 reverberators using networks of simple allpass
9 and comb delay filters. This class implements
10 two series allpass units and two parallel comb
11 filters.
12
13 by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
14 */
15 /***************************************************/
16
17 #include "PRCRev.h"
18 #include <math.h>
19
20 using namespace Nyq;
21
22 PRCRev :: PRCRev(StkFloat T60)
23 {
24 // Delay lengths for 44100 Hz sample rate.
25 int lengths[4]= {353, 1097, 1777, 2137};
26 double scaler = Stk::sampleRate() / 44100.0;
27
28 // Scale the delay lengths if necessary.
29 int delay, i;
30 if ( scaler != 1.0 ) {
31 for (i=0; i<4; i++) {
32 delay = (int) floor(scaler * lengths[i]);
33 if ( (delay & 1) == 0) delay++;
34 while ( !this->isPrime(delay) ) delay += 2;
35 lengths[i] = delay;
36 }
37 }
38
39 for (i=0; i<2; i++) {
40 allpassDelays_[i].setMaximumDelay( lengths[i] );
41 allpassDelays_[i].setDelay( lengths[i] );
42
43 combDelays_[i].setMaximumDelay( lengths[i+2] );
44 combDelays_[i].setDelay( lengths[i+2] );
45 }
46
47 this->setT60( T60 );
48 allpassCoefficient_ = 0.7;
49 effectMix_ = 0.5;
50 this->clear();
51 }
52
53 PRCRev :: ~PRCRev()
54 {
55 }
56
57 void PRCRev :: clear()
58 {
59 allpassDelays_[0].clear();
60 allpassDelays_[1].clear();
61 combDelays_[0].clear();
62 combDelays_[1].clear();
63 lastOutput_[0] = 0.0;
64 lastOutput_[1] = 0.0;
65 }
66
67 void PRCRev :: setT60( StkFloat T60 )
68 {
69 combCoefficient_[0] = pow(10.0, (-3.0 * combDelays_[0].getDelay() / (T60 * Stk::sampleRate())));
70 combCoefficient_[1] = pow(10.0, (-3.0 * combDelays_[1].getDelay() / (T60 * Stk::sampleRate())));
71 }
72
73 StkFloat PRCRev :: computeSample(StkFloat input)
74 {
75 StkFloat temp, temp0, temp1, temp2, temp3;
76
77 temp = allpassDelays_[0].lastOut();
78 temp0 = allpassCoefficient_ * temp;
79 temp0 += input;
80 allpassDelays_[0].tick(temp0);
81 temp0 = -(allpassCoefficient_ * temp0) + temp;
82
83 temp = allpassDelays_[1].lastOut();
84 temp1 = allpassCoefficient_ * temp;
85 temp1 += temp0;
86 allpassDelays_[1].tick(temp1);
87 temp1 = -(allpassCoefficient_ * temp1) + temp;
88
89 temp2 = temp1 + (combCoefficient_[0] * combDelays_[0].lastOut());
90 temp3 = temp1 + (combCoefficient_[1] * combDelays_[1].lastOut());
91
92 lastOutput_[0] = effectMix_ * (combDelays_[0].tick(temp2));
93 lastOutput_[1] = effectMix_ * (combDelays_[1].tick(temp3));
94 temp = (1.0 - effectMix_) * input;
95 lastOutput_[0] += temp;
96 lastOutput_[1] += temp;
97
98 return Effect::lastOut();
99 }
100