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 00015 namespace csl { 00016 00017 class Comb; // predeclaration of utility classes 00018 class Allpass; 00019 00021 class Freeverb : public Effect, public Scalable { 00022 00023 public: 00024 Freeverb(UnitGenerator &input); 00025 ~Freeverb(); 00026 00027 float roomSize(); 00028 void setRoomSize(float size); 00029 float dampening(); 00030 void setDampening(float damp); 00031 float wetLevel(); 00032 void setWetLevel(float level); 00033 float dryLevel(); 00034 void setDryLevel(float level); 00035 float width(); 00036 void setWidth(float width); 00037 00038 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException); 00039 00040 protected: // accessable parameters 00041 float mRoomSize; 00042 float mDampening; 00043 float mWetLevel; 00044 float mDryLevel; 00045 float mWidth; 00046 // internal parameters 00047 float mGain; 00048 00049 std::vector<Comb*> mCombFilters; 00050 std::vector<Allpass*> mAllpassFilters; 00051 00052 SampleBufferVector mCombBuffers; 00053 SampleBufferVector mAllpassBuffers; 00054 00055 void constructReverbGraph(); 00056 void updateParameters(); 00057 00058 }; 00059 00060 class Comb { 00061 00062 public: 00063 00064 Comb() : mFilterStore(0), mBufIdx(0) { }; 00065 00066 void mute(); 00067 float damp() { return mDamp1; } 00068 float feedback() { return mFeedback; } 00069 void setDamp(float val); 00070 void setFeedback(float val) { mFeedback = val; } 00071 void setBuffer(float *buf, int size); 00072 00073 inline float process(float inp); 00074 00075 private: 00076 00077 float mFeedback; 00078 float mFilterStore; 00079 float mDamp1; 00080 float mDamp2; 00081 float *mBufferPtr; 00082 int mBufSize; 00083 int mBufIdx; 00084 00085 }; 00086 00087 class Allpass { 00088 00089 public: 00090 00091 Allpass() : mBufIdx(0) { }; 00092 00093 void mute(); 00094 float feedback() { return mFeedback; }; 00095 void setFeedback(float val) { mFeedback = val; }; 00096 void setBuffer(float *buf, int size); 00097 00098 inline float process(float inp); 00099 00100 private: 00101 00102 float mFeedback; 00103 float *mBufferPtr; 00104 int mBufSize; 00105 int mBufIdx; 00106 00107 }; 00108 00109 // Big to inline - but crucial for speed 00110 inline float Comb::process(float input) { 00111 00112 float output = mBufferPtr[mBufIdx]; 00113 undenormalise(output); 00114 00115 mFilterStore = (output * mDamp2) + (mFilterStore * mDamp1); 00116 undenormalise(mFilterStore); 00117 00118 mBufferPtr[mBufIdx] = input + (mFilterStore * mFeedback); 00119 if(++mBufIdx >= mBufSize) 00120 mBufIdx = 0; 00121 00122 return output; 00123 00124 } 00125 00126 inline float Allpass::process(float input) { 00127 00128 float bufout = mBufferPtr[mBufIdx]; 00129 undenormalise(bufout); 00130 00131 float output = -input + bufout; 00132 mBufferPtr[mBufIdx] = input + (bufout * mFeedback); 00133 00134 if(++mBufIdx >= mBufSize) 00135 mBufIdx = 0; 00136 00137 return output; 00138 00139 } 00140 00141 // Stereoverb is a simple wrapper around 2 freeverbs with splitter/joiners for handling stereo inputs 00142 00143 //class Stereoverb : public Effect { 00144 // 00145 //protected: 00146 // Freeverb * leftRev, * rightRev; // 2 mono reverberators 00147 // Splitter * split; // stereo-to-mono splitter 00148 // Joiner * join; // mono-to-stereo joiner 00149 // 00150 //public: 00151 // Stereoverb(FrameStream & input); 00152 // ~Stereoverb(); 00153 // 00154 // void set_room_size(float size); 00155 // void set_dampening(float damp); 00156 // void set_wet_level(float level); 00157 // void set_dry_level(float level); 00158 // void set_width(float width); 00159 // 00160 // status next_buffer(Buffer & inputBuffer, Buffer & outputBuffer); 00161 // 00162 //}; 00163 00164 } 00165 00166 #endif 00167
1.4.5-20051010