1 /*
2     Phaser.h - Phaser effect
3 
4     Original ZynAddSubFX author Nasca Octavian Paul
5     Copyright (C) 2002-2005 Nasca Octavian Paul
6     Copyright 2009, Alan Calvert
7     Copyright 2018-2019, Will Godfrey
8 
9     This file is part of yoshimi, which is free software: you can redistribute
10     it and/or modify it under the terms of the GNU Library General Public
11     License as published by the Free Software Foundation; either version 2 of
12     the License, or (at your option) any later version.
13 
14     yoshimi is distributed in the hope that it will be useful, but WITHOUT ANY
15     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16     FOR A PARTICULAR PURPOSE.   See the GNU General Public License (version 2 or
17     later) for more details.
18 
19     You should have received a copy of the GNU General Public License along with
20     yoshimi; if not, write to the Free Software Foundation, Inc., 51 Franklin
21     Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 
23     This file is a derivative of the ZynAddSubFX original.
24 
25     Modified March 2019
26 */
27 
28 #ifndef PHASER_H
29 #define PHASER_H
30 
31 #include "Effects/Effect.h"
32 #include "Effects/EffectLFO.h"
33 
34 class SynthEngine;
35 
36 class Phaser : public Effect
37 {
38     public:
39         Phaser(bool insertion_, float *efxoutl_, float *efxoutr_, SynthEngine *_synth);
40         ~Phaser();
41         void out(float *smpsl, float *smpsr);
42         void setpreset(unsigned char npreset);
43         void changepar(int npar, unsigned char value);
44         unsigned char getpar(int npar);
45         void cleanup(void);
46         void setdryonly(void);
47 
48     private:
49         // Phaser Parameters
50         bool Pchanged;
51         EffectLFO lfo;           // <lfo-ul Phaser
52         unsigned char Pvolume;
53 //        unsigned char Ppanning;
54         unsigned char Pdistortion;  // Model distortion added by FET element
55         unsigned char Pdepth;    // <depth of Phaser sweep
56         unsigned char Pwidth;       //Phaser width (LFO amplitude)
57         unsigned char Pfb;       // <feedback
58         unsigned char Poffset;      //Model mismatch between variable resistors
59 //        unsigned char Plrcross;  // <feedback
60         unsigned char Pstages;
61         unsigned char Poutsub;   // <substract the output instead of adding it
62         unsigned char Pphase;
63         unsigned char Phyper;       //lfo^2 -- converts tri into hyper-sine
64         unsigned char Panalog;
65 
66         // Control Parameters
67         void setvolume(unsigned char Pvolume_);
68         void setdepth(unsigned char Pdepth_);
69         void setfb(unsigned char Pfb_);
70         void setdistortion(unsigned char Pdistortion_);
71         void setwidth(unsigned char Pwidth_);
72         void setoffset(unsigned char Poffset_);
73         void setstages(unsigned char Pstages_);
74         void setphase(unsigned char Pphase_);
75 
76         // Internal Values
77         // int insertion; // inherited from Effect
78         bool    barber; // Barber pole phasing flag
79         float   distortion;
80         float   width;
81         float   offsetpct;
82         float   fb;
83         float   depth;
84         float   fbl;
85         float   fbr;
86         float   phase;
87         float   invperiod;
88         float   offset[12];
89 
90         float  *oldl;
91         float  *oldr;
92         float  *xn1l;
93         float  *xn1r;
94         float  *yn1l;
95         float  *yn1r;
96 
97         float   diffl;
98         float   diffr;
99         float   oldlgain;
100         float   oldrgain;
101 
102         float mis;
103         float Rmin;     // 3N5457 typical on resistance at Vgs = 0
104         float Rmax;     // Resistor parallel to FET
105         float Rmx;      // Rmin/Rmax to avoid division in loop
106         float Rconst;   // Handle parallel resistor relationship
107         float C;        // Capacitor
108         float CFs;      // A constant derived from capacitor and resistor relationships
109         void analog_setup();
110         void AnalogPhase(float *smpsl, float *smpsr);
111         //analog case
112         float applyPhase(float x, float g, float fb,
113                          float &hpf, float *yn1, float *xn1);
114 
115         void NormalPhase(float *smpsl, float *smpsr);
116         float applyPhase(float x, float g, float *old);
117 };
118 
119 class Phaserlimit
120 {
121     public:
122         float getlimits(CommandBlock *getData);
123 };
124 
125 #endif
126