MuseScore  3.4
Music composition and notation
zita.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------
2 // Copyright (C) 2003-2011 Fons Adriaensen <fons@linuxaudio.org>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 // -----------------------------------------------------------------------
18 
19 #ifndef __ZITA_H__
20 #define __ZITA_H__
21 
22 #include "effects/effect.h"
23 
24 namespace Ms {
25 
26 class EffectGui;
27 
28 //---------------------------------------------------------
29 // Pareq
30 //---------------------------------------------------------
31 
32 class Pareq
33  {
34  enum { BYPASS, STATIC, SMOOTH, MAXCH = 4 };
35 
36  void calcpar1 (int nsamp, float g, float f);
37  void process1 (int nsamp, float*);
38 
39  volatile int16_t _touch0;
40  volatile int16_t _touch1;
41 #if 0 // not yet (?) used
42  bool _bypass;
43 #endif
44  int _state;
45  float _fsamp;
46 
47  float _g;
48  float _g0, _g1;
49  float _f;
50  float _f0, _f1;
51  float _c1, _dc1;
52  float _c2, _dc2;
53  float _gg, _dgg;
54 
55  float _z1 [MAXCH];
56  float _z2 [MAXCH];
57 
58  public:
59  Pareq();
60 
61  void setfsamp(float fsamp);
62  void setparam(float f, float g) {
63  _f = f;
64  _g = g;
65  _f0 = f;
66  _g0 = powf (10.0f, 0.05f * g);
67  _touch0++;
68  }
69  void set_gn(float g) { setparam(_f, g); }
70  float gn() const { return _g; }
71  void set_fr(float f) { setparam(f, _g); }
72  float fr() const { return _f; }
73 
74  void reset();
75  void prepare(int nsamp);
76  void process(int nsamp, float* data) {
77  if (_state != BYPASS)
78  process1(nsamp, data);
79  }
80  };
81 
82 //---------------------------------------------------------
83 // Diff1
84 //---------------------------------------------------------
85 
86 class Diff1
87  {
88  friend class ZitaReverb;
89 
90  int _i;
91  float _c;
92  int _size = 0;
93  float* _line = 0;
94 
95  Diff1() {}
96  ~Diff1();
97  void init(int size, float c);
98  void fini();
99 
100  float process(float x) {
101  float z = _line [_i];
102  x -= _c * z;
103  _line [_i] = x;
104  if (++_i == _size)
105  _i = 0;
106  return z + _c * x;
107  }
108  };
109 
110 //---------------------------------------------------------
111 // Filt1
112 //---------------------------------------------------------
113 
114 class Filt1
115  {
116  friend class ZitaReverb;
117 
118  Filt1 () : _slo (0), _shi (0) {}
119  ~Filt1 () {}
120 
121  void set_params (float del, float tmf, float tlo, float wlo, float thi, float chi);
122 
123  float process(float x) {
124  _slo += _wlo * (x - _slo) + 1e-10f;
125  x += _glo * _slo;
126  _shi += _whi * (x - _shi);
127  return _gmf * _shi;
128  }
129  float _gmf;
130  float _glo;
131  float _wlo;
132  float _whi;
133  float _slo;
134  float _shi;
135  };
136 
137 //---------------------------------------------------------
138 // Delay
139 //---------------------------------------------------------
140 
141 class Delay
142  {
143  friend class ZitaReverb;
144 
145  Delay();
146  ~Delay();
147 
148  void init (int size);
149  void fini ();
150 
151  float read () { return _line [_i]; }
152 
153  void write (float x) {
154  _line [_i++] = x;
155  if (_i == _size)
156  _i = 0;
157  }
158  int _i;
159  int _size;
160  float *_line;
161  };
162 
163 //---------------------------------------------------------
164 // Vdelay
165 //---------------------------------------------------------
166 
167 class Vdelay
168  {
169  friend class ZitaReverb;
170 
171  Vdelay();
172  ~Vdelay();
173 
174  void init (int size);
175  void fini ();
176  void set_delay (int del);
177 
178  float read () {
179  float x = _line [_ir++];
180  if (_ir == _size)
181  _ir = 0;
182  return x;
183  }
184 
185  void write (float x) {
186  _line [_iw++] = x;
187  if (_iw == _size)
188  _iw = 0;
189  }
190  int _ir;
191  int _iw;
192  int _size;
193  float* _line;
194  };
195 
196 //---------------------------------------------------------
197 // ZitaReverb
198 //---------------------------------------------------------
199 
200 class ZitaReverb : public Effect
201  {
202  Q_OBJECT
203 
204  float _fsamp;
205 
208  Diff1 _diff1[8];
209  Filt1 _filt1[8];
210  Delay _delay[8];
211 
212  volatile int _cntA1;
213  volatile int _cntB1;
214  volatile int _cntC1;
215  int _cntA2;
216  int _cntB2;
217  int _cntC2;
218 
219  float _ipdel;
220  float _xover;
221  float _rtlow;
222  float _rtmid;
223  float _fdamp;
224  float _opmix;
225  float _rgxyz;
226 
227  float _g0, _d0;
228  float _g1, _d1;
229 
232 
233  static float _tdiff1 [8];
234  static float _tdelay [8];
235 
236  int _fragm;
237  int _nsamp;
238 
239  void prepare(int n);
240 
241  public:
243  ~ZitaReverb();
244 
245  virtual void init(float fsamp);
246  void fini();
247 
248  virtual void process(int n, float* inp, float* out);
249 
250  void set_delay(float v) { _ipdel = v; _cntA1++; }
251  float delay() const { return _ipdel; }
252 
253  void set_xover(float v) { _xover = v; _cntB1++; }
254  float xover() const { return _xover; }
255 
256  void set_rtlow(float v) { _rtlow = v; _cntB1++; }
257  float rtlow() const { return _rtlow; }
258 
259  void set_rtmid(float v) { _rtmid = v; _cntB1++; _cntC1++; }
260  float rtmid() const { return _rtmid; }
261 
262  void set_fdamp(float v) { _fdamp = v; _cntB1++; }
263  float fdamp() const { return _fdamp; }
264 
265  void set_eq1fr(float f) { _pareq1.set_fr(f); }
266  float eq1fr() const { return _pareq1.fr(); }
267 
268  void set_eq1gn(float f) { _pareq1.set_gn(f); }
269  float eq1gn() const { return _pareq1.gn(); }
270 
271  void set_eq2fr(float f) { _pareq2.set_fr(f); }
272  float eq2fr() const { return _pareq2.fr(); }
273 
274  void set_eq2gn(float f) { _pareq2.set_gn(f); }
275  float eq2gn() const { return _pareq2.gn(); }
276 
277  void set_opmix(float v) { _opmix = v; _cntC1++; }
278  float opmix() const { return _opmix; }
279 
280  virtual const char* name() const { return "Zita1"; }
281  virtual EffectGui* gui();
282  virtual const std::vector<ParDescr>& parDescr() const;
283 
284  virtual void setNValue(int parameter, double value);
285  virtual double nvalue(int idx) const;
286 
287  virtual SynthesizerGroup state() const;
288  virtual void setState(const SynthesizerGroup&);
289  };
290 }
291 
292 #endif
293 
void set_eq2gn(float f)
Definition: zita.h:274
Definition: effect.h:41
float _dc2
Definition: zita.h:52
volatile int _cntA1
Definition: zita.h:212
int _iw
Definition: zita.h:191
float _g1
Definition: zita.h:48
Definition: zita.h:34
float eq2fr() const
Definition: zita.h:272
float _ipdel
Definition: zita.h:219
float * _line
Definition: zita.h:193
void set_fdamp(float v)
Definition: zita.h:262
void reset()
Definition: zita.cpp:78
Definition: zita.h:167
void prepare(int nsamp)
Definition: zita.cpp:88
Vdelay _vdelay0
Definition: zita.h:206
Definition: effectgui.h:24
void write(float x)
Definition: zita.h:185
int _nsamp
Definition: zita.h:237
float _g0
Definition: zita.h:227
float _rgxyz
Definition: zita.h:225
void setparam(float f, float g)
Definition: zita.h:62
Pareq _pareq2
Definition: zita.h:231
int _state
Definition: zita.h:44
Vdelay _vdelay1
Definition: zita.h:207
float process(float x)
Definition: zita.h:100
float fr() const
Definition: zita.h:72
float _dgg
Definition: zita.h:53
virtual const char * name() const
Definition: zita.h:280
float _rtlow
Definition: zita.h:221
float _g
Definition: zita.h:47
Definition: zita.h:141
float _gg
Definition: zita.h:53
float _c1
Definition: zita.h:51
int _size
Definition: zita.h:192
Definition: zita.h:200
void set_fr(float f)
Definition: zita.h:71
void write(float x)
Definition: zita.h:153
Diff1()
Definition: zita.h:95
float _fsamp
Definition: zita.h:204
float _g0
Definition: zita.h:48
void process1(int nsamp, float *)
Definition: zita.cpp:163
float _whi
Definition: zita.h:132
float rtmid() const
Definition: zita.h:260
Filt1()
Definition: zita.h:118
void setfsamp(float fsamp)
Definition: zita.cpp:68
float _fsamp
Definition: zita.h:45
void set_delay(float v)
Definition: zita.h:250
float eq1fr() const
Definition: zita.h:266
float _z2[MAXCH]
Definition: zita.h:56
volatile int _cntC1
Definition: zita.h:214
volatile int _cntB1
Definition: zita.h:213
Definition: zita.h:34
float _rtmid
Definition: zita.h:222
~Filt1()
Definition: zita.h:119
float _opmix
Definition: zita.h:224
float _dc1
Definition: zita.h:51
float read()
Definition: zita.h:178
void set_eq1fr(float f)
Definition: zita.h:265
void set_gn(float g)
Definition: zita.h:69
volatile int16_t _touch1
Definition: zita.h:40
float eq2gn() const
Definition: zita.h:275
float _f0
Definition: zita.h:50
void process(int nsamp, float *data)
Definition: zita.h:76
float _c2
Definition: zita.h:52
float rtlow() const
Definition: zita.h:257
Definition: zita.h:34
Definition: aeolus.cpp:26
int _cntA2
Definition: zita.h:215
void set_rtlow(float v)
Definition: zita.h:256
float _f
Definition: zita.h:49
int _cntC2
Definition: zita.h:217
Definition: zita.h:114
Definition: zita.h:34
float _shi
Definition: zita.h:134
float _glo
Definition: zita.h:130
Definition: zita.h:86
ZitaReverb()
Definition: zita.h:242
float xover() const
Definition: zita.h:254
float _wlo
Definition: zita.h:131
float _xover
Definition: zita.h:220
float _f1
Definition: zita.h:50
int _cntB2
Definition: zita.h:216
Definition: synthesizerstate.h:40
float _slo
Definition: zita.h:133
int _ir
Definition: zita.h:190
void set_rtmid(float v)
Definition: zita.h:259
float gn() const
Definition: zita.h:70
float _fdamp
Definition: zita.h:223
float fdamp() const
Definition: zita.h:263
volatile int16_t _touch0
Definition: zita.h:39
Pareq _pareq1
Definition: zita.h:230
Definition: zita.h:32
float _c
Definition: zita.h:91
int _i
Definition: zita.h:158
int _i
Definition: zita.h:90
float _gmf
Definition: zita.h:129
float process(float x)
Definition: zita.h:123
Pareq()
Definition: zita.cpp:51
int _fragm
Definition: zita.h:236
void set_eq1gn(float f)
Definition: zita.h:268
void set_eq2fr(float f)
Definition: zita.h:271
float _z1[MAXCH]
Definition: zita.h:55
float eq1gn() const
Definition: zita.h:269
void set_opmix(float v)
Definition: zita.h:277
int _size
Definition: zita.h:159
float _g1
Definition: zita.h:228
void calcpar1(int nsamp, float g, float f)
Definition: zita.cpp:139
float opmix() const
Definition: zita.h:278
float delay() const
Definition: zita.h:251
float read()
Definition: zita.h:151
void set_xover(float v)
Definition: zita.h:253
float * _line
Definition: zita.h:160