1 /* 2 FilterParams.h - Parameters for filter 3 4 Original ZynAddSubFX author Nasca Octavian Paul 5 Copyright (C) 2002-2005 Nasca Octavian Paul 6 Copyright 2009-2011, Alan Calvert 7 Copyright 2018, 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 a ZynAddSubFX original. 24 25 Modified July 2018 26 */ 27 28 #ifndef FILTER_PARAMS_H 29 #define FILTER_PARAMS_H 30 31 #include "Params/Presets.h" 32 #include "Misc/NumericFuncs.h" 33 #include "globals.h" 34 35 #include <cmath> 36 37 using func::power; 38 using func::decibel; 39 40 class XMLwrapper; 41 class SynthEngine; 42 43 class FilterParams : public Presets 44 { 45 public: 46 FilterParams(unsigned char Ptype_, unsigned char Pfreq, unsigned char Pq_, unsigned char Pfreqtrackoffset_, SynthEngine *_synth); ~FilterParams()47 ~FilterParams() { } 48 49 void add2XML(XMLwrapper *xml); 50 void add2XMLsection(XMLwrapper *xml, int n); 51 void defaults(void); 52 void getfromXML(XMLwrapper *xml); 53 void getfromXMLsection(XMLwrapper *xml, int n); 54 55 56 void getfromFilterParams(FilterParams *pars); 57 58 float getfreq(void); 59 float getq(void); 60 float getfreqtracking(float notefreq); 61 float getgain(void); 62 63 float getcenterfreq(void); 64 float getoctavesfreq(void); 65 float getfreqpos(float freq); 66 float getfreqx(float x); 67 68 void formantfilterH(int nvowel, int nfreqs, float *freqs); // used by UI 69 getformantfreq(unsigned char freq)70 float getformantfreq(unsigned char freq) // Transforms a parameter to 71 { return getfreqx(freq / 127.0f); } // the real value getformantamp(unsigned char amp)72 float getformantamp(unsigned char amp) 73 { return decibel<-80>(1.0f - amp / 127.0f); } getformantq(unsigned char q)74 float getformantq(unsigned char q) 75 { return power<25>((q - 32.0f) / 64.0f); } 76 77 unsigned char Pcategory; // Filter category (Analog/Formant/StVar) 78 unsigned char Ptype; // Filter type (for analog lpf,hpf,bpf..) 79 unsigned char Pfreq; // Frequency (64-central frequency) 80 unsigned char Pq; // Q parameters (resonance or bandwidth) 81 unsigned char Pstages; // filter stages+1 82 unsigned char Pfreqtrack; // how the filter frequency is changing 83 // according the note frequency 84 unsigned char Pfreqtrackoffset; // Shift range for freq tracking 85 unsigned char Pgain; // filter's output gain 86 87 // Formant filter parameters 88 unsigned char Pnumformants; // how many formants are used 89 unsigned char Pformantslowness; // how slow varies the formants 90 unsigned char Pvowelclearness; // how vowels are kept clean (how much try 91 // to avoid "mixed" vowels) 92 unsigned char Pcenterfreq,Poctavesfreq; // the centre frequency of the res. 93 // func., and the number of octaves 94 struct { 95 struct { 96 unsigned char freq, amp, q; // frequency,amplitude,Q 97 } formants[FF_MAX_FORMANTS]; 98 } Pvowels[FF_MAX_VOWELS]; 99 100 unsigned char Psequencesize; // how many vowels are in the sequence 101 unsigned char Psequencestretch; // how the sequence is stretched (how 102 // the input from filter envelopes/LFOs/etc. 103 // is "stretched") 104 unsigned char Psequencereversed; // if the input from filter envelopes/LFOs/etc. 105 // is reversed(negated) 106 struct { 107 unsigned char nvowel; // the vowel from the position 108 } Psequence[FF_MAX_SEQUENCE]; 109 110 bool changed; 111 112 private: 113 void defaults(int n); 114 115 // stored default parameters 116 unsigned char Dtype; 117 unsigned char Dfreq; 118 unsigned char Dq; 119 unsigned char Dfreqtrackoffset; 120 }; 121 122 class filterLimit 123 { 124 public: 125 float getFilterLimits(CommandBlock *getData); 126 }; 127 128 #endif 129