SynthLab SDK
vafilters.h
Go to the documentation of this file.
1 #ifndef __vaFilters_h__
2 #define __vaFilters_h__
3 
4 // --- includes
5 #include "synthbase.h"
6 #include "synthfunctions.h"
7 
8 // -----------------------------
9 // --- SynthLab SDK File --- //
10 // ----------------------------
18 // -----------------------------------------------------------------------------
19 namespace SynthLab
20 {
21 
22 
23 
24  // --- makes all filter outputs: LPF1, LPF1A, HPF1, APF1
25  class VA1Filter : public IFilterBase
26  {
27  public:
28  // --- constructor/destructor
29  VA1Filter();
30  virtual ~VA1Filter() {}
31 
32  // --- these match SynthModule names
33  virtual bool reset(double _sampleRate);
34  virtual bool update();
35  virtual FilterOutput* process(double xn);
36  virtual void setFilterParams(double _fc, double _Q);
37 
38  // --- set coeffs directly, bypassing coeff calculation
39  void setAlpha(double _alpha) { coeffs.alpha = _alpha; }
40  void setBeta(double _beta) { coeffs.beta = _beta; }
41  void setCoeffs(VA1Coeffs& _coeffs) {
42  coeffs = _coeffs;
43  }
44 
45  void copyCoeffs(VA1Filter& destination) {
46  destination.setCoeffs(coeffs);
47  }
48 
49  // --- added for MOOG & K35, need access to this output value, scaled by beta
50  double getFBOutput() { return coeffs.beta * sn; }
51 
52  protected:
53  FilterOutput output;
54  double sampleRate = 44100.0;
55  double halfSamplePeriod = 1.0;
56  double fc = 0.0;
57 
58  // --- state storage
59  double sn = 0.0;
60 
61  // --- filter coefficients
62  VA1Coeffs coeffs;
63  };
64 
65  struct VASVFCoeffs
66  {
67  // --- filter coefficients
68  double alpha = 0.0;
69  double rho = 1.0;
70  double sigma = 1.0;
71  double alpha0 = 1.0;
72  };
73 
74  // --- makes all filter outputs: LPF1, LPF1A, HPF1, APF1
75  class VASVFilter : public IFilterBase
76  {
77  public:
78  // --- constructor/destructor
79  VASVFilter();
80  virtual ~VASVFilter() {}
81 
82  // --- these match SynthModule names
83  virtual bool reset(double _sampleRate);
84  virtual bool update();
85  virtual FilterOutput* process(double xn);
86  virtual void setFilterParams(double _fc, double _Q);
87 
88  // --- set coeffs directly, bypassing coeff calculation
89  void setCoeffs(VASVFCoeffs& _coeffs) {
90  coeffs = _coeffs;
91  }
92 
93  void copyCoeffs(VASVFilter& destination) {
94  destination.setCoeffs(coeffs);
95  }
96 
97  protected:
98  FilterOutput output;
99  double sampleRate = 44100.0;
100  double halfSamplePeriod = 1.0;
101  double fc = 0.0;
102  double Q = 0.0;
103 
104  // --- state storage
105  double integrator_z[2];
106 
107  // --- filter coefficients
108  VASVFCoeffs coeffs;
109  };
110 
112  {
113  // --- filter coefficients
114  double K = 1.0;
115  double alpha = 0.0;
116  double alpha0 = 1.0;
117  double g = 1.0;
118  };
119 
120  // --- makes both LPF and HPF (double filter)
122  {
123  public:
124  // --- constructor/destructor
125  VAKorg35Filter();
126  virtual ~VAKorg35Filter() {}
127 
128  // --- these match SynthModule names
129  virtual bool reset(double _sampleRate);
130  virtual bool update();
131  virtual FilterOutput* process(double xn);
132  virtual void setFilterParams(double _fc, double _Q);
133 
134  // --- set coeffs directly, bypassing coeff calculation
135  void setCoeffs(VAKorg35Coeffs& _coeffs) {
136  coeffs = _coeffs;
137 
138  // --- three sync-tuned filters
139  for (uint32_t i = 0; i < KORG_SUBFILTERS; i++)
140  {
141  lpfVAFilters[i].setAlpha(coeffs.alpha);
142  hpfVAFilters[i].setAlpha(coeffs.alpha);
143  }
144 
145  // --- set filter beta values
146  double deno = 1.0 + coeffs.g;
147 
148  lpfVAFilters[FLT2].setBeta((coeffs.K * (1.0 - coeffs.alpha)) / deno);
149  lpfVAFilters[FLT3].setBeta(-1.0 / deno);
150 
151  hpfVAFilters[FLT2].setBeta(-coeffs.alpha / deno);
152  hpfVAFilters[FLT3].setBeta(1.0 / deno);
153  // hpfVAFilters[FLT3].setBeta(lpfVAFilters[FLT3].getBeta);
154  }
155 
156  void copyCoeffs(VAKorg35Filter& destination) {
157  destination.setCoeffs(coeffs);
158  }
159 
160  protected:
161  FilterOutput output;
162  VA1Filter lpfVAFilters[KORG_SUBFILTERS];
163  VA1Filter hpfVAFilters[KORG_SUBFILTERS];
164  double sampleRate = 44100.0;
165  double halfSamplePeriod = 1.0;
166  double fc = 0.0;
167 
168  // --- filter coefficients
169  VAKorg35Coeffs coeffs;
170 
171  //double K = 0.0;
172  //double alpha = 0.0; ///< alpha is (wcT/2)
173  //double alpha0 = 0.0; ///< input scalar, correct delay-free loop
174  };
175 
177  {
178  // --- filter coefficients
179  double K = 1.0;
180  double alpha = 0.0;
181  double alpha0 = 1.0;
182  double sigma = 1.0;
183  double bassComp = 1.0;
184  double g = 1.0;
185 
186  // --- these are to minimize repeat calculations for left/right pairs
187  double subFilterBeta[MOOG_SUBFILTERS] = { 0.0, 0.0, 0.0, 0.0 };
188  };
189 
190  // --- makes both LPF and HPF (double filter)
191  class VAMoogFilter : public IFilterBase
192  {
193  public:
194  // --- constructor/destructor
195  VAMoogFilter();
196  virtual ~VAMoogFilter() {}
197 
198  // --- these match SynthModule names
199  virtual bool reset(double _sampleRate);
200  virtual bool update();
201  virtual FilterOutput* process(double xn);
202  virtual void setFilterParams(double _fc, double _Q);
203 
204  // --- set coeffs directly, bypassing coeff calculation
205  void setCoeffs(const VAMoogCoeffs& _coeffs) {
206  coeffs = _coeffs;
207 
208  // --- four sync-tuned filters
209  for (uint32_t i = 0; i < MOOG_SUBFILTERS; i++)
210  {
211  // --- set alpha directly
212  subFilter[i].setAlpha(coeffs.alpha);
213  subFilterFGN[i].setAlpha(coeffs.alpha);
214 
215  // --- set beta directly
216  subFilter[i].setBeta(coeffs.subFilterBeta[i]);
217  subFilterFGN[i].setBeta(coeffs.subFilterBeta[i]);
218  }
219  }
220 
221  void copyCoeffs(VAMoogFilter& destination) {
222  destination.setCoeffs(coeffs);
223  }
224 
225  protected:
226  FilterOutput output;
227  VA1Filter subFilter[MOOG_SUBFILTERS];
228  VA1Filter subFilterFGN[MOOG_SUBFILTERS];
229  double sampleRate = 44100.0;
230  double halfSamplePeriod = 1.0;
231  double fc = 0.0;
232 
233  // --- filter coefficients
234  VAMoogCoeffs coeffs;
235  };
236 
238  {
239  // --- filter coefficients
240  double alpha0 = 0.0;
241  double alpha = 0.0;
242  double beta = 1.0;
243  double gamma = 1.0;
244  double delta = 1.0;
245  double epsilon = 1.0;
246  };
247 
249  {
250  public:
251  // --- constructor/destructor
253  virtual ~VADiodeSubFilter() {}
254 
255  // --- these match SynthModule names
256  virtual bool reset(double _sampleRate);
257  virtual bool update();
258  virtual FilterOutput* process(double xn);
259  virtual void setFilterParams(double _fc, double _Q);
260 
261  void setCoeffs(const DiodeVA1Coeffs& _coeffs) { coeffs = _coeffs; }
262  void copyCoeffs(VADiodeSubFilter& destination) {
263  destination.setCoeffs(coeffs);
264  }
265 
266  void setFBInput(double _feedbackIn) { feedbackIn = _feedbackIn; }
267  double getFBOutput() { return coeffs.beta * (sn + feedbackIn*coeffs.delta); }
268 
269  protected:
270  DiodeVA1Coeffs coeffs;
271  FilterOutput output;
272  double sampleRate = 44100.0;
273  double halfSamplePeriod = 1.0;
274  double fc = 0.0;
275 
276  // --- state storage
277  double sn = 0.0;
278  double feedbackIn = 0.0;
279  };
280 
282  {
283  // --- filter coefficients
284 
285  double alpha0 = 0.0;
286  double gamma = 0.0;
287  double beta[4] = { 0.0, 0.0, 0.0, 0.0 };
288  DiodeVA1Coeffs diodeCoeffs[4];
289  double bassComp = 0.0; // --- increase for MORE bass
290  double alpha1 = 1.0; // --- FGN amp correction
291  double K = 1.0; // ---
292  };
293 
294  // --- makes both LPF and HPF (double filter)
296  {
297  public:
298  // --- constructor/destructor
299  VADiodeFilter();
300  virtual ~VADiodeFilter() {}
301 
302  // --- these match SynthModule names
303  virtual bool reset(double _sampleRate);
304  virtual bool update();
305  virtual FilterOutput* process(double xn);
306  virtual void setFilterParams(double _fc, double _Q);
307 
308  void setCoeffs(const VADiodeCoeffs& _coeffs) {
309  coeffs = _coeffs;
310 
311  // --- update subfilter coeffs
312  for (uint32_t i = 0; i < DIODE_SUBFILTERS; i++)
313  {
314  subFilter[i].setCoeffs(coeffs.diodeCoeffs[i]);
315  subFilterFGN[i].setCoeffs(coeffs.diodeCoeffs[i]);
316  }
317  }
318 
319  void copyCoeffs(VADiodeFilter& destination) {
320  destination.setCoeffs(coeffs);
321  }
322 
323  protected:
324  FilterOutput output;
325  VADiodeSubFilter subFilter[DIODE_SUBFILTERS];
326  VADiodeSubFilter subFilterFGN[DIODE_SUBFILTERS];
327 
328  double sampleRate = 44100.0;
329  double halfSamplePeriod = 1.0;
330  double fc = 0.0;
331 
332  // --- filter coefficients
333  VADiodeCoeffs coeffs;
334  };
335 
336 }
337 
338 #endif /* defined(__vaFilters_h__) */
double gamma
input scalar, correct delay-free loop
Definition: vafilters.h:286
double alpha0
beta value, not used
Definition: vafilters.h:116
virtual bool reset(double _sampleRate)
Definition: vafilters.cpp:438
virtual bool reset(double _sampleRate)
Definition: vafilters.cpp:150
double sampleRate
current sample rate
Definition: vafilters.h:272
double sampleRate
current sample rate
Definition: vafilters.h:328
Definition: vafilters.h:295
virtual bool update()
update the filter due to changes in the GUI controls and/or modulations
Definition: vafilters.cpp:393
virtual FilterOutput * process(double xn)
Process audio through the filter. Different filters produce different outputs in the FilterOutput&#39;s a...
Definition: vafilters.cpp:203
Definition: vafilters.h:191
Definition: vafilters.h:281
double alpha
alpha is (wcT/2)
Definition: vafilters.h:115
virtual void setFilterParams(double _fc, double _Q)
Sets the two parameters of all synth filters. You can add more here if you need to.
Definition: vafilters.cpp:85
Definition: vafilters.h:25
double sigma
beta value, not used
Definition: vafilters.h:182
virtual void setFilterParams(double _fc, double _Q)
Sets the two parameters of all synth filters. You can add more here if you need to.
Definition: vafilters.cpp:30
double sampleRate
current sample rate
Definition: vafilters.h:99
double integrator_z[2]
state variables
Definition: vafilters.h:105
virtual bool update()
update the filter due to changes in the GUI controls and/or modulations
Definition: vafilters.cpp:98
virtual void setFilterParams(double _fc, double _Q)
Sets the two parameters of all synth filters. You can add more here if you need to.
Definition: vafilters.cpp:165
virtual FilterOutput * process(double xn)
Process audio through the filter. Different filters produce different outputs in the FilterOutput&#39;s a...
Definition: vafilters.cpp:120
double sn
state variables
Definition: vafilters.h:277
Definition: vafilters.h:248
Definition: addosccore.cpp:4
virtual bool reset(double _sampleRate)
Definition: vafilters.cpp:261
double sampleRate
current sample rate
Definition: vafilters.h:229
double rho
beta value, not used
Definition: vafilters.h:69
double bassComp
beta value, not used
Definition: vafilters.h:183
Simple interface for SynthLab filters.
Definition: synthbase.h:1017
double alpha
alpha is (wcT/2)
Definition: synthlabparams.h:200
Definition: vafilters.h:121
double K
beta value, not used
Definition: vafilters.h:114
virtual bool update()
update the filter due to changes in the GUI controls and/or modulations
Definition: vafilters.cpp:178
virtual bool update()
update the filter due to changes in the GUI controls and/or modulations
Definition: vafilters.cpp:39
double sigma
beta value, not used
Definition: vafilters.h:70
Tiny structure to hold 1st order VA filter coefficients, to make it easier to share them across sync-...
Definition: synthlabparams.h:197
double alpha
alpha is (wcT/2)
Definition: vafilters.h:68
double alpha0
beta value, not used
Definition: vafilters.h:181
double beta
beta value, not used
Definition: synthlabparams.h:201
double g
beta value, not used
Definition: vafilters.h:184
virtual bool update()
update the filter due to changes in the GUI controls and/or modulations
Definition: vafilters.cpp:289
Definition: vafilters.h:237
double delta
beta value, not used
Definition: vafilters.h:244
double alpha
alpha is (wcT/2)
Definition: vafilters.h:180
double beta
beta value, not used
Definition: vafilters.h:242
double alpha
alpha is (wcT/2)
Definition: vafilters.h:241
Definition: vafilters.h:75
double sn
state variables
Definition: vafilters.h:59
Definition: vafilters.h:111
double alpha0
input scalar, correct delay-free loop
Definition: vafilters.h:285
double sampleRate
current sample rate
Definition: vafilters.h:54
virtual bool reset(double _sampleRate)
Definition: vafilters.cpp:74
virtual bool reset(double _sampleRate)
Definition: vafilters.cpp:21
virtual void setFilterParams(double _fc, double _Q)
Sets the two parameters of all synth filters. You can add more here if you need to.
Definition: vafilters.cpp:384
double alpha0
beta value, not used
Definition: vafilters.h:71
virtual void setFilterParams(double _fc, double _Q)
Sets the two parameters of all synth filters. You can add more here if you need to.
Definition: vafilters.cpp:276
double gamma
beta value, not used
Definition: vafilters.h:243
double alpha0
input scalar, correct delay-free loop
Definition: vafilters.h:240
virtual bool reset(double _sampleRate)
Definition: vafilters.cpp:373
virtual FilterOutput * process(double xn)
Process audio through the filter. Different filters produce different outputs in the FilterOutput&#39;s a...
Definition: vafilters.cpp:319
hard-coded arrays of FIR filter coefficients for the sample rate conversion objects (Interpolator and...
virtual FilterOutput * process(double xn)
Process audio through the filter. Different filters produce different outputs in the FilterOutput&#39;s a...
Definition: vafilters.cpp:47
Holds an array of filter output values; SynthLab filters can produce multiple outputs at once...
Definition: synthbase.h:988
double g
beta value, not used
Definition: vafilters.h:117
Definition: vafilters.h:65
double K
beta value, not used
Definition: vafilters.h:179
double sampleRate
current sample rate
Definition: vafilters.h:164
Definition: vafilters.h:176
virtual FilterOutput * process(double xn)
Process audio through the filter. Different filters produce different outputs in the FilterOutput&#39;s a...
Definition: vafilters.cpp:401
See also Designing Software Synthesizers in C++ 2nd Ed. by Will Pirkle.
double epsilon
beta value, not used
Definition: vafilters.h:245