00001
00002
00003
00004
00005
00006
00007 #ifndef REVERB_H
00008 #define REVERB_H
00009
00010 namespace FD {
00011
00012 #define undenormalise(sample) if(((*(unsigned int*)&sample)&0x7f800000)==0) sample=0.0f
00013
00014
00015 class allpass
00016 {
00017 public:
00018 allpass();
00019 void setbuffer(float *buf, int size);
00020 inline float process(float inp);
00021 void mute();
00022 void setfeedback(float val);
00023 float getfeedback();
00024
00025 float feedback;
00026 float *buffer;
00027 int bufsize;
00028 int bufidx;
00029 };
00030
00031
00032
00033
00034 inline float allpass::process(float input)
00035 {
00036 float output;
00037 float bufout;
00038
00039 bufout = buffer[bufidx];
00040 undenormalise(bufout);
00041
00042 output = -input + bufout;
00043 buffer[bufidx] = input + (bufout*feedback);
00044
00045 if(++bufidx>=bufsize) bufidx = 0;
00046
00047 return output;
00048 }
00049
00050
00051 class comb
00052 {
00053 public:
00054 comb();
00055 void setbuffer(float *buf, int size);
00056 inline float process(float inp);
00057 void mute();
00058 void setdamp(float val);
00059 float getdamp();
00060 void setfeedback(float val);
00061 float getfeedback();
00062 private:
00063 float feedback;
00064 float filterstore;
00065 float damp1;
00066 float damp2;
00067 float *buffer;
00068 int bufsize;
00069 int bufidx;
00070 };
00071
00072
00073
00074
00075 inline float comb::process(float input)
00076 {
00077 float output;
00078
00079 output = buffer[bufidx];
00080 undenormalise(output);
00081
00082 filterstore = (output*damp2) + (filterstore*damp1);
00083 undenormalise(filterstore);
00084
00085 buffer[bufidx] = input + (filterstore*feedback);
00086
00087 if(++bufidx>=bufsize) bufidx = 0;
00088
00089 return output;
00090 }
00091
00092
00093
00094
00095
00096 const int numcombs = 8;
00097 const int numallpasses = 4;
00098 const float muted = 0;
00099 const float fixedgain = 0.015f;
00100 const float scalewet = 3;
00101 const float scaledry = 2;
00102 const float scaledamp = 0.4f;
00103 const float scaleroom = 0.28f;
00104 const float offsetroom = 0.7f;
00105 const float initialroom = 0.5f;
00106 const float initialdamp = 0.5f;
00107 const float initialwet = 1/scalewet;
00108 const float initialdry = 0;
00109 const float initialwidth = 1;
00110 const float initialmode = 0;
00111 const float freezemode = 0.5f;
00112 const int stereospread = 23;
00113
00114
00115
00116
00117
00118 const int combtuningL1 = 1116;
00119 const int combtuningR1 = 1116+stereospread;
00120 const int combtuningL2 = 1188;
00121 const int combtuningR2 = 1188+stereospread;
00122 const int combtuningL3 = 1277;
00123 const int combtuningR3 = 1277+stereospread;
00124 const int combtuningL4 = 1356;
00125 const int combtuningR4 = 1356+stereospread;
00126 const int combtuningL5 = 1422;
00127 const int combtuningR5 = 1422+stereospread;
00128 const int combtuningL6 = 1491;
00129 const int combtuningR6 = 1491+stereospread;
00130 const int combtuningL7 = 1557;
00131 const int combtuningR7 = 1557+stereospread;
00132 const int combtuningL8 = 1617;
00133 const int combtuningR8 = 1617+stereospread;
00134 const int allpasstuningL1 = 556;
00135 const int allpasstuningR1 = 556+stereospread;
00136 const int allpasstuningL2 = 441;
00137 const int allpasstuningR2 = 441+stereospread;
00138 const int allpasstuningL3 = 341;
00139 const int allpasstuningR3 = 341+stereospread;
00140 const int allpasstuningL4 = 225;
00141 const int allpasstuningR4 = 225+stereospread;
00142
00143 class revmodel
00144 {
00145 public:
00146 revmodel();
00147 void mute();
00148 void processmix(float *inputL, float *inputR, float *outputL, float *outputR, long numsamples, int skip);
00149 void processreplace(const float *inputL, const float *inputR, float *outputL, float *outputR, long numsamples, int skip);
00150 void setroomsize(float value);
00151 float getroomsize();
00152 void setdamp(float value);
00153 float getdamp();
00154 void setwet(float value);
00155 float getwet();
00156 void setdry(float value);
00157 float getdry();
00158 void setwidth(float value);
00159 float getwidth();
00160 void setmode(float value);
00161 float getmode();
00162 private:
00163 void update();
00164 private:
00165 float gain;
00166 float roomsize,roomsize1;
00167 float damp,damp1;
00168 float wet,wet1,wet2;
00169 float dry;
00170 float width;
00171 float mode;
00172
00173
00174
00175
00176
00177
00178 comb combL[numcombs];
00179 comb combR[numcombs];
00180
00181
00182 allpass allpassL[numallpasses];
00183 allpass allpassR[numallpasses];
00184
00185
00186 float bufcombL1[combtuningL1];
00187 float bufcombR1[combtuningR1];
00188 float bufcombL2[combtuningL2];
00189 float bufcombR2[combtuningR2];
00190 float bufcombL3[combtuningL3];
00191 float bufcombR3[combtuningR3];
00192 float bufcombL4[combtuningL4];
00193 float bufcombR4[combtuningR4];
00194 float bufcombL5[combtuningL5];
00195 float bufcombR5[combtuningR5];
00196 float bufcombL6[combtuningL6];
00197 float bufcombR6[combtuningR6];
00198 float bufcombL7[combtuningL7];
00199 float bufcombR7[combtuningR7];
00200 float bufcombL8[combtuningL8];
00201 float bufcombR8[combtuningR8];
00202
00203
00204 float bufallpassL1[allpasstuningL1];
00205 float bufallpassR1[allpasstuningR1];
00206 float bufallpassL2[allpasstuningL2];
00207 float bufallpassR2[allpasstuningR2];
00208 float bufallpassL3[allpasstuningL3];
00209 float bufallpassR3[allpasstuningR3];
00210 float bufallpassL4[allpasstuningL4];
00211 float bufallpassR4[allpasstuningR4];
00212 };
00213
00214 }
00215
00216 #endif