Phaser.h (3333B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Phaser.h - Phaser effect 5 Copyright (C) 2002-2005 Nasca Octavian Paul 6 Copyright (C) 2009-2010 Ryan Billing 7 Copyright (C) 2010-2010 Mark McCurry 8 Author: Nasca Octavian Paul 9 Ryan Billing 10 Mark McCurry 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 18 #ifndef PHASER_H 19 #define PHASER_H 20 #include "../globals.h" 21 #include "Effect.h" 22 #include "EffectLFO.h" 23 24 #define MAX_PHASER_STAGES 12 25 26 namespace zyn { 27 28 class Phaser final:public Effect 29 { 30 public: 31 Phaser(EffectParams pars); 32 ~Phaser(); 33 void out(const Stereo<float *> &input); 34 unsigned char getpresetpar(unsigned char npreset, unsigned int npar); 35 void setpreset(unsigned char npreset); 36 void changepar(int npar, unsigned char value); 37 unsigned char getpar(int npar) const; 38 void cleanup(); 39 40 static rtosc::Ports ports; 41 private: 42 //Phaser parameters 43 EffectLFO lfo; //Phaser modulator 44 unsigned char Pvolume; //Used to set wet/dry mix 45 unsigned char Pdistortion; //Model distortion added by FET element 46 unsigned char Pdepth; //Depth of phaser sweep 47 unsigned char Pwidth; //Phaser width (LFO amplitude) 48 unsigned char Pfb; //feedback 49 unsigned char Poffset; //Model mismatch between variable resistors 50 unsigned char Pstages; //Number of first-order All-Pass stages 51 unsigned char Poutsub; //if I wish to subtract the output instead of adding 52 unsigned char Pphase; 53 unsigned char Phyper; //lfo^2 -- converts tri into hyper-sine 54 unsigned char Panalog; 55 56 //Control parameters 57 void setvolume(unsigned char Pvolume); 58 void setdepth(unsigned char Pdepth); 59 void setfb(unsigned char Pfb); 60 void setdistortion(unsigned char Pdistortion); 61 void setwidth(unsigned char Pwidth); 62 void setoffset(unsigned char Poffset); 63 void setstages(unsigned char Pstages); 64 void setphase(unsigned char Pphase); 65 66 //Internal Variables 67 bool barber; //Barber pole phasing flag 68 float distortion, width, offsetpct; 69 float feedback, depth, phase; 70 Stereo<float *> old, xn1, yn1; 71 Stereo<float> diff, oldgain, fb; 72 float invperiod; 73 float offset[12]; 74 75 float mis; 76 float Rmin; // 3N5457 typical on resistance at Vgs = 0 77 float Rmax; // Resistor parallel to FET 78 float Rmx; // Rmin/Rmax to avoid division in loop 79 float Rconst; // Handle parallel resistor relationship 80 float C; // Capacitor 81 float CFs; // A constant derived from capacitor and resistor relationships 82 83 void analog_setup(); 84 void AnalogPhase(const Stereo<float *> &input); 85 //analog case 86 float applyPhase(float x, float g, float fb, 87 float &hpf, float *yn1, float *xn1); 88 89 void normalPhase(const Stereo<float *> &input); 90 float applyPhase(float x, float g, float *old); 91 }; 92 93 } 94 95 #endif