00001 // 00002 // Reverb.h -- The CSL port of the public domain Freeverb reverberator 00003 // Freeverb was written by Jezar at Dreampoint, June 2000 -- http://www.dreampoint.co.uk 00004 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT 00005 // 00006 00007 #ifndef CSL_Reverb_H 00008 #define CSL_Reverb_H 00009 00010 #include "CSL_Core.h" 00011 00012 #define undenormalise(sample) if (((*(unsigned int*)&sample)&0x7f800000)==0) sample=0.0f 00013 00014 namespace csl { 00015 00016 class Comb; // predeclaration of utility classes 00017 class FAllpass; 00018 00022 00023 class Freeverb : public Effect, public Scalable { 00024 00025 public: 00026 Freeverb(UnitGenerator &input); 00027 ~Freeverb(); 00028 00029 float roomSize(); 00030 void setRoomSize(float size); 00031 float dampening(); 00032 void setDampening(float damp); 00033 float wetLevel(); 00034 void setWetLevel(float level); 00035 float dryLevel(); 00036 void setDryLevel(float level); 00037 float width(); 00038 void setWidth(float width); 00039 00040 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException); 00041 00042 protected: // accessable parameters 00043 float mRoomSize; 00044 float mDampening; 00045 float mWetLevel; 00046 float mDryLevel; 00047 float mWidth; 00048 // internal parameters 00049 float mGain; 00050 00051 std::vector <Comb *> mCombFilters; 00052 std::vector <FAllpass *> mAllpassFilters; 00053 00054 SampleBufferVector mCombBuffers; 00055 SampleBufferVector mAllpassBuffers; 00056 00057 void constructReverbGraph(); 00058 void updateParameters(); 00059 }; 00060 00064 00065 class Comb { 00066 public: 00067 Comb() : mFilterStore(0), mBufIdx(0) { }; 00068 00069 void mute(); 00070 float damp() { return mDamp1; } 00071 float feedback() { return mFeedback; } 00072 void setDamp(float val); 00073 void setFeedback(float val) { mFeedback = val; } 00074 void setBuffer(float *buf, int size); 00075 00076 inline float process(float inp); 00077 00078 private: 00079 float mFeedback; 00080 float mFilterStore; 00081 float mDamp1; 00082 float mDamp2; 00083 float *mBufferPtr; 00084 int mBufSize; 00085 int mBufIdx; 00086 }; 00087 00091 00092 class FAllpass { 00093 public: 00094 FAllpass() : mBufIdx(0) { }; 00095 00096 void mute(); 00097 float feedback() { return mFeedback; }; 00098 void setFeedback(float val) { mFeedback = val; }; 00099 void setBuffer(float *buf, int size); 00100 00101 inline float process(float inp); 00102 00103 private: 00104 float mFeedback; 00105 float *mBufferPtr; 00106 int mBufSize; 00107 int mBufIdx; 00108 }; 00109 00110 // Big to inline - but crucial for speed 00111 00112 inline float Comb::process(float input) { 00113 float output = mBufferPtr[mBufIdx]; 00114 undenormalise(output); 00115 mFilterStore = (output * mDamp2) + (mFilterStore * mDamp1); 00116 undenormalise(mFilterStore); 00117 mBufferPtr[mBufIdx] = input + (mFilterStore * mFeedback); 00118 if (++mBufIdx >= mBufSize) 00119 mBufIdx = 0; 00120 return output; 00121 } 00122 00123 inline float FAllpass::process(float input) { 00124 float bufout = mBufferPtr[mBufIdx]; 00125 undenormalise(bufout); 00126 float output = -input + bufout; 00127 mBufferPtr[mBufIdx] = input + (bufout * mFeedback); 00128 if (++mBufIdx >= mBufSize) 00129 mBufIdx = 0; 00130 return output; 00131 } 00132 00134 // Stereoverb is a simple wrapper around 2 freeverbs with splitter/joiners for handling stereo inputs 00136 00137 class Stereoverb : public Effect { 00138 00139 public: 00140 Stereoverb(UnitGenerator & input); 00141 ~Stereoverb(); 00142 00143 void setRoomSize(float size); 00144 void setDampening(float damp); 00145 void setWetLevel(float level); 00146 void setDryLevel(float level); 00147 void setWidth(float width); 00148 00149 void nextBuffer(Buffer &outputBuffer) throw (CException); 00150 00151 protected: 00152 Freeverb * leftRev, * rightRev; // 2 mono reverberators 00153 Splitter * split; // stereo-to-mono splitter 00154 Joiner * join; // mono-to-stereo joiner 00155 }; 00156 00157 } 00158 00159 #endif
1.4.5-20051010