LMMS
Loading...
Searching...
No Matches
ToneStack.h
Go to the documentation of this file.
1/*
2 ToneStack.h
3
4 Copyright 2006-9
5 David Yeh <dtyeh@ccrma.stanford.edu> (implementation)
6 Tim Goetze <tim@quitte.de> (cosmetics)
7
8 Tone Stack emulation.
9
10*/
11/*
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA or point your web browser to http://www.gnu.org.
26*/
27
28#ifndef _DSP_TONESTACK_H_
29#define _DSP_TONESTACK_H_
30
31#include "util.h"
32#include "windows.h"
33#include "TDFII.h"
34#include "LatFilt.h"
35#include "tonestack/tables.h"
36
37namespace DSP {
38
39typedef struct {
40 double R1, R2, R3, R4;
41 double C1, C2, C3;
43
44#define TS_N_PRESETS (sizeof (DSP::ToneStack::presets) / \
45 sizeof (DSP::TSParameters))
46
48{
49 private:
50 enum { Order = 3 };
51
52 double c; // BT coef
53
54 double b1t, b1m, b1l, b1d,
58 a3lm, a3m2, a3m, a3l, a3d; // intermediate calculations
59
60 struct {
61 double b1;
62 double b2;
63 double b3;
64 double a1;
65 double a2;
66 double a3;
67 } acoef; // analog coefficients
68
69 // digital coefficients
70 double dcoef_a[Order + 1];
71 double dcoef_b[Order + 1];
72
74
75 public:
76 int model;
77
78 static TSParameters presets[]; /* in ../ToneStack.cc */
79 static int n_presets;
80
82 {
83 model = -1;
84 setparams (presets[0]);
85 }
86
87 void init (double _fs)
88 {
89 c = 2 * _fs;
90 }
91
92 void activate (sample_t ** ports)
93 {
94 filter.reset();
95 }
96
97 /* pass in pointer to ports and relative index of first eq band control */
98 void start_cycle (sample_t ** ports, int bassindex = 1)
99 {
100 int m = clamp<int> ((int) *ports[0], 0, n_presets - 1);
101 if (m != model)
102 {
103 model = m;
105 filter.reset();
106 }
107 updatecoefs (ports + bassindex);
108 }
109
110
112 {
113 double R1 = p.R1, R2 = p.R2, R3 = p.R3, R4 = p.R4;
114 double C1 = p.C1, C2 = p.C2, C3 = p.C3;
115
116 b1t = C1*R1;
117 b1m = C3*R3;
118 b1l = C1*R2 + C2*R2;
119 b1d = C1*R3 + C2*R3;
120 b2t = C1*C2*R1*R4 + C1*C3*R1*R4;
121 b2m2 = -(C1*C3*R3*R3 + C2*C3*R3*R3);
122 b2m = C1*C3*R1*R3 + C1*C3*R3*R3 + C2*C3*R3*R3;
123 b2l = C1*C2*R1*R2 + C1*C2*R2*R4 + C1*C3*R2*R4;
124 b2lm = C1*C3*R2*R3 + C2*C3*R2*R3;
125 b2d = C1*C2*R1*R3 + C1*C2*R3*R4 + C1*C3*R3*R4;
126 b3lm = C1*C2*C3*R1*R2*R3 + C1*C2*C3*R2*R3*R4;
127 b3m2 = -(C1*C2*C3*R1*R3*R3 + C1*C2*C3*R3*R3*R4);
128 b3m = C1*C2*C3*R1*R3*R3 + C1*C2*C3*R3*R3*R4;
129 b3t = C1*C2*C3*R1*R3*R4;
130 b3tm = -b3t;
131 b3tl = C1*C2*C3*R1*R2*R4;
132 a0 = 1;
133 a1d = C1*R1 + C1*R3 + C2*R3 + C2*R4 + C3*R4;
134 a1m = C3*R3;
135 a1l = C1*R2 + C2*R2;
136 a2m = C1*C3*R1*R3 - C2*C3*R3*R4 + C1*C3*R3*R3 + C2*C3*R3*R3;
137 a2lm = C1*C3*R2*R3 + C2*C3*R2*R3;
138 a2m2 = -(C1*C3*R3*R3 + C2*C3*R3*R3);
139 a2l = C1*C2*R2*R4 + C1*C2*R1*R2 + C1*C3*R2*R4 + C2*C3*R2*R4;
140 a2d = C1*C2*R1*R4 + C1*C3*R1*R4 + C1*C2*R3*R4
141 + C1*C2*R1*R3 + C1*C3*R3*R4 + C2*C3*R3*R4;
142 a3lm = C1*C2*C3*R1*R2*R3 + C1*C2*C3*R2*R3*R4;
143 a3m2 = -(C1*C2*C3*R1*R3*R3 + C1*C2*C3*R3*R3*R4);
144 a3m = C1*C2*C3*R3*R3*R4 + C1*C2*C3*R1*R3*R3 - C1*C2*C3*R1*R3*R4;
145 a3l = C1*C2*C3*R1*R2*R4;
146 a3d = C1*C2*C3*R1*R3*R4;
147
148 filter.reset();
149 }
150
151 inline void updatecoefs (sample_t ** ports)
152 {
153 /* range checks on input */
154 double b = clamp<double> (*ports[0], 0, 1);
155 double m = clamp<double> (*ports[1], 0, 1);
156 double t = clamp<double> (*ports[2], 0, 1);
157
158 m = (m - 1) * 3.5;
159 m = pow (10, m);
160
161 acoef.a1 = a1d + m*a1m + b*a1l;
162 acoef.a2 = m*a2m + b*m*a2lm + m*m*a2m2 + b*a2l + a2d;
163 acoef.a3 = b*m*a3lm + m*m*a3m2 + m*a3m + b*a3l + a3d;
164 dcoef_a[0] = -1 - acoef.a1*c - acoef.a2*c*c - acoef.a3*c*c*c; // sets scale
165 dcoef_a[1] = -3 - acoef.a1*c + acoef.a2*c*c + 3*acoef.a3*c*c*c;
166 dcoef_a[2] = -3 + acoef.a1*c + acoef.a2*c*c - 3*acoef.a3*c*c*c;
167 dcoef_a[3] = -1 + acoef.a1*c - acoef.a2*c*c + acoef.a3*c*c*c;
168
169 acoef.b1 = t*b1t + m*b1m + b*b1l + b1d;
170 acoef.b2 = t*b2t + m*m*b2m2 + m*b2m + b*b2l + b*m*b2lm + b2d;
171 acoef.b3 = b*m*b3lm + m*m*b3m2 + m*b3m + t*b3t + t*m*b3tm + t*b*b3tl;
172 dcoef_b[0] = - acoef.b1*c - acoef.b2*c*c - acoef.b3*c*c*c;
173 dcoef_b[1] = - acoef.b1*c + acoef.b2*c*c + 3*acoef.b3*c*c*c;
174 dcoef_b[2] = acoef.b1*c + acoef.b2*c*c - 3*acoef.b3*c*c*c;
175 dcoef_b[3] = acoef.b1*c - acoef.b2*c*c + acoef.b3*c*c*c;
176
177 for (int i=1; i<=3; ++i)
178 filter.a[i] = dcoef_a[i] / dcoef_a[0];
179
180 for (int i=0; i<=3; ++i)
181 filter.b[i] = dcoef_b[i] / dcoef_a[0];
182 }
183
184 // actualy do the DFII filtering, one sample at a time
186 {
187 return filter.process (x);
188 }
189};
190
191/* /////////////////////////////////////////////////////////////////////// */
192
193/*
194 hardcode this, known size memory blocks
195 extern double* KS; // 25 x 25 x 3
196 extern double* VS; // 25 x 25 x 25 x 4
197 extern double KS[NSTEPS][NSTEPS][TSORDER]; //[bass][mid][coefs]
198 extern double VS[NSTEPS][NSTEPS][NSTEPS][TSORDER+1]; //[bass][mid][treb][coefs]
199 */
200
202{
203 private:
204 enum { Order = 3, Steps = 25 };
205
206 // digital coefficients
207 double *kcoef;
208 double *vcoef;
210
211 public:
213 {
214 setparams (250000, 1000000, 25000, 56000, 0.25e-9, 20e-9, 20e-9);
215 }
216
217 void init (double _fs)
218 { }
219
220 void activate (sample_t ** ports)
221 {
222 filter.reset();
223 }
224
226 (double R1, double R2, double R3, double R4,
227 double C1, double C2, double C3) {
228 }
229
230 void updatecoefs (sample_t ** ports)
231 {
232 double b = min (Steps - 1, max (*ports[0] * (Steps - 1), 0));
233 double m = min (Steps - 1, max (*ports[1] * (Steps - 1), 0));
234 double t = min (Steps - 1, max (*ports[2] * (Steps - 1), 0));
235
236 int bi = (int) b;
237 int mi = (int) m;
238 int ti = (int) t;
239
240 kcoef = DSP::ToneStackKS + (mi * Steps + bi) * Order;
241 vcoef = DSP::ToneStackVS + ((mi * Steps + bi) * Steps + ti) * (Order + 1);
242
243 for (int i = 0; i < Order; ++i)
244 filter.set_ki (kcoef[i], i);
245
246 for (int i = 0; i < Order + 1; ++i)
247 filter.set_vi (vcoef[i], i);
248 }
249
250 // actualy do the DFII filtering, one sample at a time
252 {
253 return filter.process (x);
254 }
255};
256
257} /* namespace DSP */
258
259#endif /* _DSP_TONESTACK_H_ */
LADSPA_Data sample_t
Definition basics.h:100
T clamp(T value, T lower, T upper)
Definition basics.h:135
Definition LatFilt.h:36
Definition TDFII.h:38
double a3d
Definition ToneStack.h:58
static int n_presets
Definition ToneStack.h:79
@ Order
Definition ToneStack.h:50
double a1l
Definition ToneStack.h:57
double a2
Definition ToneStack.h:65
double b2lm
Definition ToneStack.h:55
static TSParameters presets[]
Definition ToneStack.h:78
double a3
Definition ToneStack.h:66
double a1d
Definition ToneStack.h:57
double c
Definition ToneStack.h:52
double a3m
Definition ToneStack.h:58
double a2m2
Definition ToneStack.h:57
double a1m
Definition ToneStack.h:57
double a3m2
Definition ToneStack.h:58
double a2l
Definition ToneStack.h:57
double b3t
Definition ToneStack.h:56
double b3tm
Definition ToneStack.h:56
double a2lm
Definition ToneStack.h:57
double b2
Definition ToneStack.h:62
double b2d
Definition ToneStack.h:55
double b2t
Definition ToneStack.h:55
int model
Definition ToneStack.h:76
double a3lm
Definition ToneStack.h:58
double a2m
Definition ToneStack.h:57
double b3
Definition ToneStack.h:63
double b3lm
Definition ToneStack.h:56
void start_cycle(sample_t **ports, int bassindex=1)
Definition ToneStack.h:98
double b1t
Definition ToneStack.h:54
double b2m2
Definition ToneStack.h:55
TDFII< Order > filter
Definition ToneStack.h:73
void init(double _fs)
Definition ToneStack.h:87
double b3tl
Definition ToneStack.h:56
double b2m
Definition ToneStack.h:55
double b1m
Definition ToneStack.h:54
double a0
Definition ToneStack.h:57
void updatecoefs(sample_t **ports)
Definition ToneStack.h:151
sample_t process(sample_t x)
Definition ToneStack.h:185
double b3m
Definition ToneStack.h:56
double a2d
Definition ToneStack.h:57
double b1l
Definition ToneStack.h:54
double dcoef_a[Order+1]
Definition ToneStack.h:70
void setparams(TSParameters &p)
Definition ToneStack.h:111
double a3l
Definition ToneStack.h:58
double b1
Definition ToneStack.h:61
double b2l
Definition ToneStack.h:55
double dcoef_b[Order+1]
Definition ToneStack.h:71
double a1
Definition ToneStack.h:64
double b1d
Definition ToneStack.h:54
void activate(sample_t **ports)
Definition ToneStack.h:92
ToneStack()
Definition ToneStack.h:81
struct DSP::ToneStack::@345025224343273106103061156237136054111271131212 acoef
double b3m2
Definition ToneStack.h:56
void updatecoefs(sample_t **ports)
Definition ToneStack.h:230
LatFilt< Order > filter
Definition ToneStack.h:209
void activate(sample_t **ports)
Definition ToneStack.h:220
sample_t process(sample_t x)
Definition ToneStack.h:251
@ Order
Definition ToneStack.h:204
@ Steps
Definition ToneStack.h:204
ToneStackLT()
Definition ToneStack.h:212
double * kcoef
Definition ToneStack.h:207
void init(double _fs)
Definition ToneStack.h:217
void setparams(double R1, double R2, double R3, double R4, double C1, double C2, double C3)
Definition ToneStack.h:226
double * vcoef
Definition ToneStack.h:208
* e
Definition inflate.c:1404
unsigned * m
Definition inflate.c:1559
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition BiQuad.h:31
double ToneStackKS[]
Definition ks_tab.h:33
double ToneStackVS[]
Definition vs_tab.h:34
#define min(x, y)
Definition os.h:74
#define max(x, y)
Definition os.h:78
Definition ToneStack.h:39
double C2
Definition ToneStack.h:41
double R2
Definition ToneStack.h:40
double R3
Definition ToneStack.h:40
double C1
Definition ToneStack.h:41
double R1
Definition ToneStack.h:40
double R4
Definition ToneStack.h:40
double C3
Definition ToneStack.h:41
uch * p
Definition crypt.c:594
b
Definition crypt.c:628
typedef int(UZ_EXP MsgFn)()