1 /*
2   Rakarrack   Audio FX software
3   Stompbox.C - stompbox modeler
4   Modified for rakarrack by Ryan Billing
5 
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of version 2 of the GNU General Public License
8   as published by the Free Software Foundation.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License (version 2) for more details.
14 
15   You should have received a copy of the GNU General Public License (version 2)
16   along with this program; if not, write to the Free Software Foundation,
17   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 
19 */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <math.h>
24 #include "StompBox.h"
25 
26 
27 
StompBox(float * efxoutl_,float * efxoutr_,double sample_rate,uint32_t intermediate_bufsize,int wave_res,int wave_upq,int wave_dnq)28 StompBox::StompBox (float * efxoutl_, float * efxoutr_, double sample_rate, uint32_t intermediate_bufsize,
29 		int wave_res, int wave_upq, int wave_dnq)
30 {
31     efxoutl = efxoutl_;
32     efxoutr = efxoutr_;
33 
34 
35     //default values
36     Ppreset = 0;
37     Pvolume = 50;
38 
39     //left channel filters
40     interpbuf = new float[intermediate_bufsize];
41     linput = new AnalogFilter (1, 80.0f, 1.0f, 0, sample_rate, interpbuf);  //  AnalogFilter (unsigned char Ftype, float Ffreq, float Fq,unsigned char Fstages);
42     lpre1 = new AnalogFilter (1, 630.0f, 1.0f, 0, sample_rate, interpbuf);   // LPF = 0, HPF = 1
43     lpre2 = new AnalogFilter (1, 220.0f, 1.0f, 0, sample_rate, interpbuf);
44     lpost = new AnalogFilter (0, 720.0f, 1.0f, 0, sample_rate, interpbuf);
45     ltonehg = new AnalogFilter (1, 1500.0f, 1.0f, 0, sample_rate, interpbuf);
46     ltonemd = new AnalogFilter (4, 1000.0f, 1.0f, 0, sample_rate, interpbuf);
47     ltonelw = new AnalogFilter (0, 500.0f, 1.0, 0, sample_rate, interpbuf);
48 
49     //Right channel filters
50     rinput = new AnalogFilter (1, 80.0f, 1.0f, 0, sample_rate, interpbuf);  //  AnalogFilter (unsigned char Ftype, float Ffreq, float Fq,unsigned char Fstages);
51     rpre1 = new AnalogFilter (1, 630.0f, 1.0f, 0, sample_rate, interpbuf);   // , sample_rateLPF = 0, HPF = 1
52     rpre2 = new AnalogFilter (1, 220.0f, 1.0f, 0, sample_rate, interpbuf);
53     rpost = new AnalogFilter (0, 720.0f, 1.0f, 0, sample_rate, interpbuf);
54     rtonehg = new AnalogFilter (1, 1500.0f, 1.0f, 0, sample_rate, interpbuf);
55     rtonemd = new AnalogFilter (4, 1000.0f, 1.0f, 0, sample_rate, interpbuf);
56     rtonelw = new AnalogFilter (0, 500.0f, 1.0f, 0, sample_rate, interpbuf);
57 
58     //Anti-aliasing for between stages
59     ranti = new AnalogFilter (0, 6000.0f, 0.707f, 1, sample_rate, interpbuf);
60     lanti = new AnalogFilter (0, 6000.0f, 0.707f, 1, sample_rate, interpbuf);
61 
62     rwshape = new Waveshaper(sample_rate,wave_res,wave_upq,wave_dnq,intermediate_bufsize);
63     lwshape = new Waveshaper(sample_rate,wave_res,wave_upq,wave_dnq,intermediate_bufsize);
64     rwshape2 = new Waveshaper(sample_rate,wave_res,wave_upq,wave_dnq,intermediate_bufsize);
65     lwshape2 = new Waveshaper(sample_rate,wave_res,wave_upq,wave_dnq,intermediate_bufsize);
66 
67     cleanup ();
68 
69     setpreset (Ppreset);
70 };
71 
~StompBox()72 StompBox::~StompBox ()
73 {
74     delete linput;
75     delete lpre1;
76     delete lpre2;
77     delete lpost;
78     delete ltonehg;
79     delete ltonemd;
80     delete ltonelw;
81 
82     delete[] interpbuf;
83     //Right channel filters
84     delete rinput;
85     delete rpre1;
86     delete rpre2;
87     delete rpost;
88     delete rtonehg;
89     delete rtonemd;
90     delete rtonelw;
91 
92     //Anti-aliasing for between stages
93     delete ranti;
94     delete lanti;
95 
96     delete rwshape;
97     delete lwshape;
98     delete rwshape2;
99     delete lwshape2;
100 };
101 
102 /*
103  * Cleanup the effect
104  */
105 void
cleanup()106 StompBox::cleanup ()
107 {
108     linput->cleanup();
109     lpre1->cleanup();
110     lpre2->cleanup();
111     lpost->cleanup();
112     ltonehg->cleanup();
113     ltonemd->cleanup();
114     ltonelw->cleanup();
115 
116     //right channel filters
117     rinput->cleanup();
118     rpre1->cleanup();
119     rpre2->cleanup();
120     rpost->cleanup();
121     rtonehg->cleanup();
122     rtonemd->cleanup();
123     rtonelw->cleanup();
124 
125     ranti->cleanup();
126     lanti->cleanup();
127 
128     rwshape->cleanup();
129     lwshape->cleanup();
130     rwshape2->cleanup();
131     lwshape2->cleanup();
132 
133 };
134 
135 
136 /*
137  * Effect output
138  */
139 void
out(float * smpsl,float * smpsr,uint32_t period)140 StompBox::out (float * smpsl, float * smpsr, uint32_t period)
141 {
142     unsigned int i;
143 
144     float hfilter;  //temporary variables
145     float mfilter;
146     float lfilter;
147     float tempr;
148     float templ;
149 
150     switch (Pmode) {
151     case 0:          //Odie
152 
153         lpre2->filterout(smpsl, period);
154         rpre2->filterout(smpsr, period);
155         rwshape->waveshapesmps (period, smpsl, 28, 20, 1);  //Valve2
156         lwshape->waveshapesmps (period, smpsr, 28, 20, 1);
157         ranti->filterout(smpsr, period);
158         lanti->filterout(smpsl, period);
159         lpre1->filterout(smpsl, period);
160         rpre1->filterout(smpsr, period);
161         rwshape2->waveshapesmps (period, smpsl, 28, Pgain, 1);  //Valve2
162         lwshape2->waveshapesmps (period, smpsr, 28, Pgain, 1);
163 
164         lpost->filterout(smpsl, period);
165         rpost->filterout(smpsr, period);
166 
167         for (i = 0; i<period; i++) {
168             //left channel
169             lfilter =  ltonelw->filterout_s(smpsl[i]);
170             mfilter =  ltonemd->filterout_s(smpsl[i]);
171             hfilter =  ltonehg->filterout_s(smpsl[i]);
172 
173             efxoutl[i] = 0.5f * volume * (smpsl[i] + lowb*lfilter + midb*mfilter + highb*hfilter);
174 
175             //Right channel
176             lfilter =  rtonelw->filterout_s(smpsr[i]);
177             mfilter =  rtonemd->filterout_s(smpsr[i]);
178             hfilter =  rtonehg->filterout_s(smpsr[i]);
179 
180             efxoutr[i] = 0.5f * volume * (smpsr[i] + lowb*lfilter + midb*mfilter + highb*hfilter);
181 
182         }
183 
184         break;
185 
186     case 1:  //Grunge
187     case 5:  //Death Metal
188     case 6:  //Metal Zone
189         linput->filterout(smpsl, period);
190         rinput->filterout(smpsr, period);
191 
192         for (i = 0; i<period; i++) {
193             templ = smpsl[i] * (gain * pgain + 0.01f);
194             tempr = smpsr[i] * (gain * pgain + 0.01f);
195             smpsl[i] += lpre1->filterout_s(templ);
196             smpsr[i] += rpre1->filterout_s(tempr);
197         }
198         rwshape->waveshapesmps (period, smpsl, 24, 1, 1);  // Op amp limiting
199         lwshape->waveshapesmps (period, smpsr, 24, 1, 1);
200 
201         ranti->filterout(smpsr, period);
202         lanti->filterout(smpsl, period);
203 
204         rwshape2->waveshapesmps (period, smpsl, 23, Pgain, 1);  // hard comp
205         lwshape2->waveshapesmps (period, smpsr, 23, Pgain, 1);
206 
207 
208         for (i = 0; i<period; i++) {
209             smpsl[i] = smpsl[i] + RGP2 * lpre2->filterout_s(smpsl[i]);
210             smpsr[i] = smpsr[i] + RGP2 * rpre2->filterout_s(smpsr[i]);
211             smpsl[i] = smpsl[i] + RGPST * lpost->filterout_s(smpsl[i]);
212             smpsr[i] = smpsr[i] + RGPST * rpost->filterout_s(smpsr[i]);
213 
214             //left channel
215             lfilter =  ltonelw->filterout_s(smpsl[i]);
216             mfilter =  ltonemd->filterout_s(smpsl[i]);
217             hfilter =  ltonehg->filterout_s(smpsl[i]);
218 
219             efxoutl[i] = 0.1f * volume * (smpsl[i] + lowb*lfilter + midb*mfilter + highb*hfilter);
220 
221             //Right channel
222             lfilter =  rtonelw->filterout_s(smpsr[i]);
223             mfilter =  rtonemd->filterout_s(smpsr[i]);
224             hfilter =  rtonehg->filterout_s(smpsr[i]);
225 
226             efxoutr[i] = 0.1f * volume * (smpsr[i] + lowb*lfilter + midb*mfilter + highb*hfilter);
227 
228         }
229 
230 
231 
232         break;
233     case 2:  //Rat
234     case 3:  //Fat Cat  //Pre gain & filter freqs the only difference
235 
236         linput->filterout(smpsl, period);
237         rinput->filterout(smpsr, period);
238 
239         for (i = 0; i<period; i++) {
240             templ = smpsl[i];
241             tempr = smpsr[i];
242             smpsl[i] += lpre1->filterout_s(pre1gain*gain*templ);
243             smpsr[i] += rpre1->filterout_s(pre1gain*gain*tempr);  //Low freq gain stage
244             smpsl[i] += lpre2->filterout_s(pre2gain*gain*templ);
245             smpsr[i] += rpre2->filterout_s(pre2gain*gain*tempr); //High freq gain stage
246 
247         }
248 
249 
250         rwshape->waveshapesmps (period, smpsl, 24, 1, 1);  // Op amp limiting
251         lwshape->waveshapesmps (period, smpsr, 24, 1, 1);
252 
253         ranti->filterout(smpsr, period);
254         lanti->filterout(smpsl, period);
255 
256         rwshape2->waveshapesmps (period, smpsl, 23, 1, 0);  // hard comp
257         lwshape2->waveshapesmps (period, smpsr, 23, 1, 0);
258 
259 
260         for (i = 0; i<period; i++) {
261             //left channel
262             lfilter =  ltonelw->filterout_s(smpsl[i]);
263             mfilter =  ltonemd->filterout_s(smpsl[i]);
264 
265             efxoutl[i] = 0.5f * ltonehg->filterout_s(volume * (smpsl[i] + lowb*lfilter + midb*mfilter));
266 
267             //Right channel
268             lfilter =  rtonelw->filterout_s(smpsr[i]);
269             mfilter =  rtonemd->filterout_s(smpsr[i]);
270 
271             efxoutr[i] = 0.5f * rtonehg->filterout_s(volume * (smpsr[i] + lowb*lfilter + midb*mfilter));
272 
273         }
274 
275         break;
276     case 4:  //Dist+
277 
278         linput->filterout(smpsl, period);
279         rinput->filterout(smpsr, period);
280 
281         for (i = 0; i<period; i++) {
282             templ = smpsl[i];
283             tempr = smpsr[i];
284             smpsl[i] += lpre1->filterout_s(pre1gain*gain*templ);
285             smpsr[i] += rpre1->filterout_s(pre1gain*gain*tempr);  //Low freq gain stage
286         }
287 
288 
289         rwshape->waveshapesmps (period, smpsl, 24, 1, 1);  // Op amp limiting
290         lwshape->waveshapesmps (period, smpsr, 24, 1, 1);
291 
292         ranti->filterout(smpsr, period);
293         lanti->filterout(smpsl, period);
294 
295         rwshape2->waveshapesmps (period, smpsl, 29, 1, 0);  // diode limit
296         lwshape2->waveshapesmps (period, smpsr, 29, 1, 0);
297 
298 
299         for (i = 0; i<period; i++) {
300             //left channel
301             lfilter =  ltonelw->filterout_s(smpsl[i]);
302             mfilter =  ltonemd->filterout_s(smpsl[i]);
303 
304             efxoutl[i] = 0.5f * ltonehg->filterout_s(volume * (smpsl[i] + lowb*lfilter + midb*mfilter));
305 
306             //Right channel
307             lfilter =  rtonelw->filterout_s(smpsr[i]);
308             mfilter =  rtonemd->filterout_s(smpsr[i]);
309 
310             efxoutr[i] = 0.5f * rtonehg->filterout_s(volume * (smpsr[i] + lowb*lfilter + midb*mfilter));
311 
312         }
313 
314         break;
315 
316     case 7:          //Classic Fuzz
317 
318         lpre1->filterout(smpsl, period);
319         rpre1->filterout(smpsr, period);
320         linput->filterout(smpsl, period);
321         rinput->filterout(smpsr, period);
322         rwshape->waveshapesmps (period, smpsr, 19, 25, 1);  //compress
323         lwshape->waveshapesmps (period, smpsl, 19, 25, 1);
324 
325         for (i = 0; i<period; i++) {
326 
327             //left channel
328             mfilter =  ltonemd->filterout_s(smpsl[i]);
329 
330             templ = lpost->filterout_s(fabs(smpsl[i]));
331             tempr = rpost->filterout_s(fabs(smpsr[i]));   //dynamic symmetry
332 
333             smpsl[i] += lowb*templ + midb*mfilter;      //In this case, lowb control tweaks symmetry
334 
335             //Right channel
336             mfilter =  rtonemd->filterout_s(smpsr[i]);
337             smpsr[i] += lowb*tempr + midb*mfilter;
338 
339         }
340 
341         ranti->filterout(smpsr, period);
342         lanti->filterout(smpsl, period);
343         rwshape2->waveshapesmps (period, smpsr, 25, Pgain, 1);  //JFET
344         lwshape2->waveshapesmps (period, smpsl, 25, Pgain, 1);
345         lpre2->filterout(smpsl, period);
346         rpre2->filterout(smpsr, period);
347 
348         for (i = 0; i<period; i++) {
349             //left channel
350             lfilter =  ltonelw->filterout_s(smpsl[i]);
351             hfilter =  ltonehg->filterout_s(smpsl[i]);
352 
353             efxoutl[i] = volume * ((1.0f - highb)*lfilter + highb*hfilter);  //classic BMP tone stack
354 
355             //Right channel
356             lfilter =  rtonelw->filterout_s(smpsr[i]);
357             hfilter =  rtonehg->filterout_s(smpsr[i]);
358 
359             efxoutr[i] = volume * ((1.0f - highb)*lfilter + highb*hfilter);
360 
361         }
362         break;
363     }
364 
365 
366 
367 };
368 
369 
370 /*
371  * Parameter control
372  */
init_mode(int value)373 void StompBox::init_mode (int value)
374 {
375     int tinput = 1;
376     float finput = 80.0f;
377     float qinput = 1.0f;
378     int sinput = 0;
379 
380     int tpre1 = 1;
381     float fpre1 = 708.0f;
382     float qpre1 = 1.0f;
383     int spre1 = 0;
384 
385     int tpre2 = 1;
386     float fpre2 = 30.0f;
387     float qpre2 = 1.0f;
388     int spre2 = 0;
389 
390     int tpost = 0;
391     float fpost = 720.0f;
392     float qpost = 1.0f;
393     int spost = 0;
394 
395     int ttonehg = 1;
396     float ftonehg = 1500.0f;
397     float qtonehg = 1.0f;
398     int stonehg = 0;
399 
400     int ttonemd = 4;
401     float ftonemd = 720.0f;
402     float qtonemd = 1.0f;
403     int stonemd = 0;
404 
405     int ttonelw = 0;
406     float ftonelw = 500.0f;
407     float qtonelw = 1.0f;
408     int stonelw = 0;
409 
410     switch (value) {
411     case 0:
412         tinput = 1;
413         finput = 80.0f;
414         qinput = 1.0f;
415         sinput = 0;
416 
417         tpre1 = 1;
418         fpre1 = 630.0f;
419         qpre1 = 1.0f;
420         spre1 = 0;
421 
422         tpre2 = 1;
423         fpre2 = 220.0f;
424         qpre2 = 1.0f;
425         spre2 = 0;
426 
427         tpost = 0;
428         fpost = 720.0f;
429         qpost = 1.0f;
430         spost = 0;
431 
432         ttonehg = 1;
433         ftonehg = 1500.0f;
434         qtonehg = 1.0f;
435         stonehg = 0;
436 
437         ttonemd = 4;
438         ftonemd = 720.0f;
439         qtonemd = 1.0f;
440         stonemd = 0;
441 
442         ttonelw = 0;
443         ftonelw = 500.0f;
444         qtonelw = 1.0f;
445         stonelw = 0;
446         break;
447 
448     case 1: //Grunge
449 // Some key filter stages based upon a schematic for a grunge pedal
450 // Total gain up to 25,740/2 (91dB)
451 // Fc1 =  999.02  Gain = 110 = 40.8dB
452 // Q1 =  2.9502
453 // gain stage 1rst order HP @ 340 Hz, Gain = 21.3 ... 234 (26dB ... 47dB)
454 // Fc2 =  324.50
455 // Q2 =  4.5039
456 // Fc3 =  5994.1
457 // Q3 =  1.7701
458 // Fc4 =  127.80
459 // Q4 =  3.7739
460 
461         tinput = 4;         //Pre-Emphasis filter
462         finput = 1000.0f;
463         qinput = 2.95f;
464         sinput = 0;
465         pgain = 110.0f;
466 
467         tpre1 = 0;         //Gain stage reduce aliasing
468         fpre1 = 6000.0f;
469         qpre1 = 0.707f;
470         spre1 = 2;
471 
472         tpre2 = 4;        //being used as a recovery filter, gain = 10
473         fpre2 = 324.5f;
474         qpre2 = 4.5f;
475         spre2 = 0;
476         RGP2 = 10.0f;
477 
478         tpost = 4;       //The other recovery filter, gain = 3
479         fpost = 6000.0f;
480         qpost = 1.77f;
481         spost = 0;
482         RGPST = 3.0f;
483 
484         ttonehg = 1;       //high shelf ranging 880 to 9700 Hz, gain 10
485         ftonehg = 4000.0f;
486         qtonehg = 1.0f;
487         stonehg = 0;
488 
489         ttonemd = 4;       // Pedal has no mid filter so I'll make up my own
490         ftonemd = 1000.0f;
491         qtonemd = 2.0f;
492         stonemd = 0;
493 
494         ttonelw = 4;       //Low Eq band, peaking type, gain = up to 22.
495         ftonelw = 128.0f;
496         qtonelw = 3.8f;
497         stonelw = 0;
498         break;
499 
500     case 2: //ProCo Rat Distortion emulation
501 // Some key filter stages based upon a schematic for a grunge pedal
502 
503         tinput = 0;         //Reduce some noise aliasing
504         finput = 5000.0f;
505         qinput = 1.0f;
506         sinput = 3;
507 
508         tpre1 = 1;         //Gain stage high boost, gain = 1 ... 268 (max)
509         fpre1 = 60.0f;
510         qpre1 = 1.0f;
511         spre1 = 0;
512         pre1gain = 268.0f;
513 
514         tpre2 = 1;        //being used as a recovery filter, gain = 1 ... 3000
515         fpre2 = 1539.0f;
516         qpre2 = 1.0f;
517         spre2 = 0;
518         pre2gain = 3000.0f;
519 
520         tpost = 0;       //Not used...initialized to "something"
521         fpost = 6000.0f;
522         qpost = 1.77f;
523         spost = 0;
524 
525         ttonehg = 0;       //frequency sweeping LPF
526         ftonehg = 1000.0f;
527         qtonehg = 1.0f;
528         stonehg = 0;
529 
530         ttonemd = 4;       // Pedal has no mid filter so I'll make up my own
531         ftonemd = 700.0f;
532         qtonemd = 2.0f;
533         stonemd = 0;
534 
535         ttonelw = 0;       //Pedal has no Low filter, so make up my own...Low Eq band, peaking type
536         ftonelw = 328.0f;  //Mild low boost
537         qtonelw = 0.50f;
538         stonelw = 1;
539         break;
540 
541     case 3: //Fat Cat Distortion emulation
542     case 4: //MXR Dist+ emulation (many below filters unuse)
543 // Some key filter stages based upon a schematic for a grunge pedal
544 
545         tinput = 0;         //Reduce some noise aliasing
546         finput = 5000.0f;
547         qinput = 1.0f;
548         sinput = 3;
549 
550         tpre1 = 1;         //Gain stage high boost, gain = 1 ... 100 (max)
551         fpre1 = 33.0f;
552         qpre1 = 1.0f;
553         spre1 = 0;
554         pre1gain = 100.0f;
555 
556         tpre2 = 1;        //being used as a recovery filter, gain = 1 ... 1700
557         fpre2 = 861.0f;
558         qpre2 = 1.0f;
559         spre2 = 0;
560         pre2gain = 1700.0f;
561 
562         tpost = 0;       //Not used...initialized to "something"
563         fpost = 6000.0f;
564         qpost = 1.77f;
565         spost = 0;
566 
567         ttonehg = 0;       //frequency sweeping LPF
568         ftonehg = 1000.0f;
569         qtonehg = 1.0f;
570         stonehg = 0;
571 
572         ttonemd = 4;       // Pedal has no mid filter so I'll make up my own
573         ftonemd = 700.0f;
574         qtonemd = 2.0f;
575         stonemd = 0;
576 
577         ttonelw = 0;       //Pedal has no Low filter, so make up my own...Low Eq band, peaking type
578         ftonelw = 328.0f;  //Mild low boost
579         qtonelw = 0.50f;
580         stonelw = 1;
581         break;
582 
583     case 5: //Death Metal
584 // Some key filter stages based upon a schematic for a grunge pedal
585 
586         tinput = 4;         //Pre-Emphasis filter
587         finput = 6735.4f;
588         qinput = 0.43f;
589         sinput = 0;
590         pgain = 110.0f;
591 
592         tpre1 = 0;         //Gain stage reduce aliasing
593         fpre1 = 6000.0f;
594         qpre1 = 0.707f;
595         spre1 = 2;
596 
597         tpre2 = 4;        //being used as a recovery filter, gain = 10
598         fpre2 = 517.0f;
599         qpre2 = 7.17f;
600         spre2 = 0;
601         RGP2 = 1.0f;
602 
603         tpost = 4;       //The other recovery filter, gain = 10
604         fpost = 48.0f;
605         qpost = 6.68f;
606         spost = 0;
607         RGPST = 10.0f;
608 
609         ttonehg = 1;       //high shelf ranging 880 to 9700 Hz, gain 11
610         ftonehg = 4000.0f;
611         qtonehg = 1.0f;
612         stonehg = 0;
613         HG = 11.0f;
614 
615         ttonemd = 4;       // Mid band EQ gain 11
616         ftonemd = 1017.0f;
617         qtonemd = 1.15f;
618         stonemd = 0;
619         MG = 11.0f;
620 
621         ttonelw = 4;       //Low Eq band, peaking type, gain = up to 22.
622         ftonelw = 107.0f;
623         qtonelw = 3.16f;
624         stonelw = 0;
625         LG = 22.0f;
626 
627         break;
628     case 6: //Metal Zone
629 // Some key filter stages based upon a schematic for a grunge pedal
630 
631         tinput = 4;         //Pre-Emphasis filter
632         finput = 952.53f;
633         qinput = 2.8f;
634         sinput = 0;
635         pgain = 100.0f;
636 
637         tpre1 = 0;         //Gain stage reduce aliasing
638         fpre1 = 6000.0f;
639         qpre1 = 0.707f;
640         spre1 = 2;
641 
642         tpre2 = 4;        //being used as a recovery filter, gain = 10
643         fpre2 = 4894.0f;
644         qpre2 = 2.16f;
645         spre2 = 0;
646         RGP2 = 3.3f;
647 
648         tpost = 4;       //The other recovery filter, gain = 10
649         fpost = 105.0f;
650         qpost = 14.62f;
651         spost = 0;
652         RGPST = 7.0f;
653 
654         ttonehg = 1;       //high shelf ranging 880 to 9700 Hz, gain 11
655         ftonehg = 4000.0f;
656         qtonehg = 1.0f;
657         stonehg = 0;
658         HG = 10.0f;
659 
660         ttonemd = 4;       // Mid band EQ gain 11
661         ftonemd = 1017.0f;
662         qtonemd = 1.15f;
663         stonemd = 0;
664         MG = 11.0f;
665 
666         ttonelw = 4;       //Low Eq band, peaking type, gain = up to 22.
667         ftonelw = 105.50f;
668         qtonelw = 3.11f;
669         stonelw = 0;
670         LG = 3.33f;
671 
672         break;
673 
674     case 7:  //Classic Fuzz
675         tinput = 1;
676         finput = 80.0f;
677         qinput = 1.0f;
678         sinput = 0;
679 
680         tpre1 = 0;
681         fpre1 = 4500.0f;
682         qpre1 = 1.0f;
683         spre1 = 1;
684 
685         tpre2 = 1;
686         fpre2 = 40.0f;
687         qpre2 = 1.0f;
688         spre2 = 0;
689 
690         tpost = 0;
691         fpost = 2.0f;
692         qpost = 1.0f;
693         spost = 0;
694 
695         ttonehg = 1;
696         ftonehg = 397.0f;
697         qtonehg = 1.0f;
698         stonehg = 0;
699 
700         ttonemd = 4;
701         ftonemd = 515.0f;  //sort of like a stuck wahwah
702         qtonemd = 4.0f;
703         stonemd = 0;
704 
705         ttonelw = 0;
706         ftonelw = 295.0f;
707         qtonelw = 1.0f;
708         stonelw = 0;
709         break;
710     }
711 
712     //left channel filters
713     //  AnalogFilter (unsigned char Ftype, float Ffreq, float Fq,unsigned char Fstages);
714     // LPF = 0, HPF = 1
715     linput->settype(tinput);
716     linput->setfreq_and_q(finput, qinput);
717     linput->setstages(sinput);
718 
719     lpre1->settype(tpre1);
720     lpre1->setfreq_and_q(fpre1, qpre1);
721     lpre1->setstages(spre1);
722 
723     lpre2->settype(tpre2);
724     lpre2->setfreq_and_q(fpre2, qpre2);
725     lpre2->setstages(spre2);
726 
727     lpost->settype(tpost);
728     lpost->setfreq_and_q(fpost, qpost);
729     lpost->setstages(spost);
730 
731     ltonehg->settype(ttonehg);
732     ltonehg->setfreq_and_q(ftonehg,qtonehg);
733     ltonehg->setstages(stonehg);
734 
735     ltonemd->settype(ttonemd);
736     ltonemd->setfreq_and_q(ftonemd,qtonemd);
737     ltonemd->setstages(stonemd);
738 
739     ltonelw->settype(ttonelw);
740     ltonelw->setfreq_and_q(ftonelw, qtonelw);
741     ltonelw->setstages(stonelw);
742 
743     //right channel filters
744 
745     rinput->settype(tinput);
746     rinput->setfreq_and_q(finput, qinput);
747     rinput->setstages(sinput);
748 
749     rpre1->settype(tpre1);
750     rpre1->setfreq_and_q(fpre1, qpre1);
751     rpre1->setstages(spre1);
752 
753     rpre2->settype(tpre2);
754     rpre2->setfreq_and_q(fpre2, qpre2);
755     rpre2->setstages(spre2);
756 
757     rpost->settype(tpost);
758     rpost->setfreq_and_q(fpost, qpost);
759     rpost->setstages(spost);
760 
761     rtonehg->settype(ttonehg);
762     rtonehg->setfreq_and_q(ftonehg,qtonehg);
763     rtonehg->setstages(stonehg);
764 
765     rtonemd->settype(ttonemd);
766     rtonemd->setfreq_and_q(ftonemd,qtonemd);
767     rtonemd->setstages(stonemd);
768 
769     rtonelw->settype(ttonelw);
770     rtonelw->setfreq_and_q(ftonelw, qtonelw);
771     rtonelw->setstages(stonelw);
772 
773 };
774 
init_tone()775 void StompBox::init_tone ()
776 {
777     float varf;
778     switch (Pmode) {
779     case 0:
780         varf = 2533.0f + highb*1733.0f;  //High tone ranges from 800 to 6000Hz
781         rtonehg->setfreq(varf);
782         ltonehg->setfreq(varf);
783         if (highb > 0.0f) highb = ((float) Phigh)/8.0f;
784         break;
785 
786     case 1:
787         varf = 3333.0f + highb*2500.0f;  //High tone ranges from 833 to 8333Hz
788         rtonehg->setfreq(varf);
789         ltonehg->setfreq(varf);
790 
791         if (highb > 0.0f) highb = ((float) Phigh)/16.0f;
792         if (lowb > 0.0f) lowb = ((float) Plow)/18.0f;
793         break;
794 
795     case 2:
796     case 3:
797         varf = 3653.0f + highb*3173.0f;  //High tone ranges from ~480 to 10k
798         rtonehg->setfreq(varf);
799         ltonehg->setfreq(varf);
800         break;
801     case 4:
802         varf = gain*700.0f + 20.0f;
803         rpre1->setfreq(varf);
804         lpre1->setfreq(varf);
805         pre1gain = 212.0f;
806         varf = 3653.0f + highb*3173.0f;  //High tone ranges from ~480 to 10k
807         rtonehg->setfreq(varf);
808         ltonehg->setfreq(varf);
809         break;
810     case 5: //Death Metal
811     case 6: //Mid Elves Own
812         varf = 3653.0f + highb*3173.0f;  //High tone ranges from ~480 to 10k
813         rtonehg->setfreq(varf);
814         ltonehg->setfreq(varf);
815 
816         if (highb > 0.0f) highb = HG * ((float) Phigh)/64.0f;
817         if (lowb > 0.0f) lowb = LG * ((float) Plow)/64.0f;
818         if (midb > 0.0f) midb = MG * ((float) Pmid)/64.0f;
819         break;
820 
821     case 7:
822         highb = ((float) Phigh + 64)/127.0f;
823         varf = 40.0f + gain * 200.0f;
824         linput->setfreq(varf);
825         rinput->setfreq(varf);
826         if (midb > 0.0f) midb = ((float) Pmid)/8.0f;
827         lowb = ((float) Plow)/64.0f;
828 
829         varf = 1085.0f - lowb * 1000.0f;
830         lpre1->setfreq(varf);
831         rpre1->setfreq(varf);
832         break;
833 
834 
835     }
836 
837 };
838 
839 
840 void
setvolume(int value)841 StompBox::setvolume (int value)
842 {
843     Pvolume = value;
844     volume = (float)Pvolume / 127.0f;
845 };
846 
847 void
setpreset(int npreset)848 StompBox::setpreset (int npreset)
849 {
850     const int PRESET_SIZE = 6;
851     const int NUM_PRESETS = 8;
852     int pdata[PRESET_SIZE];
853     int presets[NUM_PRESETS][PRESET_SIZE] = {
854         //Odie
855         {80, 32, 0, 32, 10, 0},
856         //Grunger
857         {48, 10, -6, 55, 85, 1},
858         //Hard Dist.
859         {48, -22, -6, 38, 12, 1},
860         //Ratty
861         {48, -20, 0, 0, 70, 2},
862         //Classic Dist
863         {50, 64, 0, 0, 110, 4},
864         //Morbid Impalement
865         {38, 6, 6, 6, 105, 5},
866         //Mid Elve
867         {48, 0, -12, 0, 127, 6},
868         //Fuzz
869         {48, 0, 0, 0, 127, 7}
870     };
871 
872     if(npreset>NUM_PRESETS-1) {
873         Fpre->ReadPreset(39,npreset-NUM_PRESETS+1,pdata);
874         for (int n = 0; n < PRESET_SIZE; n++)
875             changepar (n, pdata[n]);
876     } else {
877         for (int n = 0; n < PRESET_SIZE; n++)
878             changepar (n, presets[npreset][n]);
879     }
880     Ppreset = npreset;
881     cleanup ();
882 
883 };
884 
885 
886 void
changepar(int npar,int value)887 StompBox::changepar (int npar, int value)
888 {
889     switch (npar) {
890     case 0:
891         setvolume (value);
892         break;
893     case 1:
894         Phigh = value;
895         if( value < 0) highb = ((float) value)/64.0f;
896         if( value > 0) highb = ((float) value)/32.0f;
897         break;
898     case 2:
899         Pmid = value;
900         if( value < 0) midb = ((float) value)/64.0f;
901         if( value > 0) midb = ((float) value)/32.0f;
902         break;
903     case 3:
904         Plow = value;
905         if( value < 0) lowb = ((float) value)/64.0f;
906         if( value > 0) lowb = ((float) value)/32.0f;
907         break;
908     case 4:
909         Pgain = value;
910         gain = dB2rap(50.0f * ((float)value)/127.0f  - 50.0f);
911         break;
912     case 5:
913         Pmode = value;
914         init_mode (Pmode);
915         break;
916 
917     };
918     init_tone ();
919 };
920 
921 int
getpar(int npar)922 StompBox::getpar (int npar)
923 {
924     switch (npar) {
925     case 0:
926         return (Pvolume);
927         break;
928     case 1:
929         return (Phigh);
930         break;
931     case 2:
932         return (Pmid);
933         break;
934     case 3:
935         return (Plow);
936         break;
937     case 4:
938         return (Pgain);
939         break;
940     case 5:
941         return (Pmode);
942         break;
943 
944     };
945     return (0);			//in case of bogus parameter number
946 };
947 
948