1 /*
2   Freeverb
3 
4   Written by Jezar at Dreampoint, June 2000
5   http://www.dreampoint.co.uk
6   This code is public domain
7 
8   modified for MuseScore Werner Schweer, 2009
9 */
10 
11 #ifndef _REV_H
12 #define _REV_H
13 
14 #include "effects/effect.h"
15 
16 static const int numcombs = 8;
17 static const int numallpasses = 4;
18 
19 //---------------------------------------------------------
20 //   Allpass
21 //---------------------------------------------------------
22 
23 class Allpass {
24       float feedback;
25       float* buffer;
26       int bufsize;
27       int bufidx;
28 
29    public:
30       void setbuffer(int size);
setfeedback(float val)31       void setfeedback(float val) { feedback = val;  }
getfeedback()32       float getfeedback() const   { return feedback; }
33 
process(float _input)34       float process(float _input) {
35             float bufout   = buffer[bufidx];
36             float output   = bufout - _input;
37             buffer[bufidx] = _input + (bufout * feedback);
38             ++bufidx      %= bufsize;
39             return output;
40             }
41       };
42 
43 //---------------------------------------------------------
44 //   Comb
45 //---------------------------------------------------------
46 
47 class Comb {
48       float feedback;
49       float filterstore;
50       float damp1;
51       float damp2;
52       float* buffer;
53       int bufsize;
54       int bufidx;
55 
56    public:
57       void setbuffer(int size);
58       void setdamp(float val);
getdamp()59       float getdamp() const       { return damp1;    }
setfeedback(float val)60       void setfeedback(float val) { feedback = val;  }
getfeedback()61       float getfeedback() const   { return feedback; }
62 
process(float input)63       float process(float input) {
64             float tmp      = buffer[bufidx];
65             filterstore    = (tmp * damp2) + (filterstore * damp1);
66             buffer[bufidx] = input + (filterstore * feedback);
67             ++bufidx      %= bufsize;
68             return tmp;
69             }
70       };
71 
72 //---------------------------------------------------------
73 //   Freeverb
74 //---------------------------------------------------------
75 
76 class Freeverb : public Effect {
77       //Q_OBJECT
78 
79       float roomsize, damp, width, sendLevel, wet;
80       float newRoomsize, newDamp, newWidth, newSendLevel, newWet;
81       float wet1, wet2;
82       bool parameterChanged;
83 
84       Comb combL[numcombs];
85       Comb combR[numcombs];
86 
87       Allpass allpassL[numallpasses];
88       Allpass allpassR[numallpasses];
89 
90       void update();
91 
92    public:
93       Freeverb();
94       virtual void process(int n, float* in, float* out);
95 
96       virtual void setNValue(int idx, double value);
97       virtual double nvalue(int idx) const;
98 
99       bool setPreset(int);
name()100       virtual const char* name() const { return "Freeverb"; }
101       virtual EffectGui* gui();
102       virtual const std::vector<ParDescr>& parDescr() const;
103       };
104 
105 #endif
106