File: rev.h

package info (click to toggle)
musescore 0.9.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 128,372 kB
  • ctags: 30,007
  • sloc: cpp: 366,359; xml: 86,115; ansic: 6,146; python: 2,186; sh: 724; perl: 710; makefile: 236
file content (159 lines) | stat: -rw-r--r-- 4,635 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* FluidSynth - A Software Synthesizer
 *
 * Copyright (C) 2003  Peter Hanappe and others.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307, USA
 */


#ifndef _FLUID_REV_H
#define _FLUID_REV_H

namespace FluidS {

static const int numcombs = 8;
static const int numallpasses = 4;

//---------------------------------------------------------
//   Allpass
//---------------------------------------------------------

class Allpass {
      float feedback;
      float *buffer;
      int bufsize;
      int bufidx;

   public:
      void setbuffer(int size);
      void init();
      void setfeedback(float val) { feedback = val;  }
      float getfeedback() const   { return feedback; }

      float process(float _input) {
            float bufout = buffer[bufidx];
            float output = bufout - _input;
            buffer[bufidx] = _input + (bufout * feedback);
            if (++bufidx >= bufsize)
                  bufidx = 0;
            return output;
            }
      };

//---------------------------------------------------------
//   Comb
//---------------------------------------------------------

class Comb {
      float feedback;
      float filterstore;
      float damp1;
      float damp2;
      float *buffer;
      int bufsize;
      int bufidx;

   public:
      void setbuffer(int size);
      void init();
      void setdamp(float val);
      float getdamp() const       { return damp1;    }
      void setfeedback(float val) { feedback = val;  }
      float getfeedback() const   { return feedback; }

      float process(float input) {
            float tmp = buffer[bufidx];
            filterstore      = (tmp * damp2) + (filterstore * damp1);
            buffer[bufidx]   = input + (filterstore * feedback);
            if (++bufidx >= bufsize)
                  bufidx = 0;
            return tmp;
            }
      };

static const float scaleroom  = 0.28f;
static const float offsetroom = 0.7f;
static const float scalewet   = 3.0f;
static const float scaledamp  = 0.4f;

//---------------------------------------------------------
//   Reverb
//---------------------------------------------------------

class Reverb {
      void init();
      void update();

      float roomsize;
      float damp;
      float wet, wet1, wet2;
      float width;
      float gain;

      float newRoomsize;
      float newDamp;
      float newWidth;
      float newGain;
      bool parameterChanged;

      /*
       The following are all declared inline
       to remove the need for dynamic allocation
       with its subsequent error-checking messiness
       */

      Comb combL[numcombs];
      Comb combR[numcombs];

      Allpass allpassL[numallpasses];
      Allpass allpassR[numallpasses];

   public:
      Reverb();
      void process(int n, float* in, float* left_out, float* right_out);

      void reset() { init(); }

      void setroomsize(float value) { roomsize = (value * scaleroom) + offsetroom; }
      void setdamp(float value)     { damp = value * scaledamp;  }
      void setlevel(float value)    { wet  = value * scalewet;   }
      void setLevel(float value)    { setlevel(value); update(); }
      void setwidth(float value)    { width = value;             }
      void setmode(float value);
      float getroomsize() const     { return (roomsize - offsetroom) / scaleroom; }
      float getdamp() const         { return damp / scaledamp; }
      float getlevel() const        { return wet / scalewet;   }
      float getwidth()              { return width;            }

      void setParameter(int parameter, double value);
      double parameter(int idx) const;

      bool setPreset(int);
      };

//---------------------------------------------------------
//   ReverbPreset
//---------------------------------------------------------

struct ReverbPreset {
      const char* name;
      float roomsize;
      float damp;
      float width;
      float level;
      };
}
#endif /* _FLUID_REV_H */