Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.6KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. OscilGen.h - Waveform generator for ADnote
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef OSCIL_GEN_H
  18. #define OSCIL_GEN_H
  19. #include "../globals.h"
  20. #include "../Misc/XMLwrapper.h"
  21. #include "../DSP/FFTwrapper.h"
  22. #include "../Params/Presets.h"
  23. #include "Resonance.h"
  24. class OscilGen:public Presets
  25. {
  26. public:
  27. OscilGen(FFTwrapper *fft_, Resonance *res_);
  28. ~OscilGen();
  29. /**computes the full spectrum of oscil from harmonics,phases and basefunc*/
  30. void prepare();
  31. /**do the antialiasing(cut off higher freqs.),apply randomness and do a IFFT*/
  32. //returns where should I start getting samples, used in block type randomness
  33. short get(float *smps, float freqHz, int resonance = 0);
  34. //if freqHz is smaller than 0, return the "un-randomized" sample for UI
  35. void getbasefunction(float *smps);
  36. //called by UI
  37. void getspectrum(int n, float *spc, int what); //what=0 pt. oscil,1 pt. basefunc
  38. void getcurrentbasefunction(float *smps);
  39. /**convert oscil to base function*/
  40. void useasbase();
  41. void add2XML(XMLwrapper *xml);
  42. void defaults();
  43. void getfromXML(XMLwrapper *xml);
  44. void convert2sine();
  45. //Parameters
  46. /**
  47. * The hmag and hphase starts counting from 0, so the first harmonic(1) has the index 0,
  48. * 2-nd harmonic has index 1, ..the 128 harminic has index 127
  49. */
  50. unsigned char Phmag[MAX_AD_HARMONICS], Phphase[MAX_AD_HARMONICS]; //the MIDI parameters for mag. and phases
  51. /**The Type of magnitude:
  52. * 0 - Linear
  53. * 1 - dB scale (-40)
  54. * 2 - dB scale (-60)
  55. * 3 - dB scale (-80)
  56. * 4 - dB scale (-100)*/
  57. unsigned char Phmagtype;
  58. unsigned char Pcurrentbasefunc; //The base function used - 0=sin, 1=...
  59. unsigned char Pbasefuncpar; //the parameter of the base function
  60. unsigned char Pbasefuncmodulation; //what modulation is applied to the basefunc
  61. unsigned char Pbasefuncmodulationpar1, Pbasefuncmodulationpar2,
  62. Pbasefuncmodulationpar3; //the parameter of the base function modulation
  63. /*the Randomness:
  64. 64=no randomness
  65. 63..0 - block type randomness - 0 is maximum
  66. 65..127 - each harmonic randomness - 127 is maximum*/
  67. unsigned char Prand;
  68. unsigned char Pwaveshaping, Pwaveshapingfunction;
  69. unsigned char Pfiltertype, Pfilterpar1, Pfilterpar2;
  70. unsigned char Pfilterbeforews;
  71. unsigned char Psatype, Psapar; //spectrum adjust
  72. unsigned char Pamprandpower, Pamprandtype; //amplitude randomness
  73. int Pharmonicshift; //how the harmonics are shifted
  74. int Pharmonicshiftfirst; //if the harmonic shift is done before waveshaping and filter
  75. unsigned char Padaptiveharmonics; //the adaptive harmonics status (off=0,on=1,etc..)
  76. unsigned char Padaptiveharmonicsbasefreq; //the base frequency of the adaptive harmonic (30..3000Hz)
  77. unsigned char Padaptiveharmonicspower; //the strength of the effect (0=off,100=full)
  78. unsigned char Padaptiveharmonicspar; //the parameters in 2,3,4.. modes of adaptive harmonics
  79. unsigned char Pmodulation; //what modulation is applied to the oscil
  80. unsigned char Pmodulationpar1, Pmodulationpar2, Pmodulationpar3; //the parameter of the parameters
  81. //makes a new random seed for Amplitude Randomness
  82. //this should be called every note on event
  83. void newrandseed(unsigned int randseed);
  84. bool ADvsPAD; //if it is used by ADsynth or by PADsynth
  85. private:
  86. //This array stores some termporary data and it has OSCIL_SIZE elements
  87. float *tmpsmps;
  88. fft_t *outoscilFFTfreqs;
  89. float hmag[MAX_AD_HARMONICS], hphase[MAX_AD_HARMONICS]; //the magnituides and the phases of the sine/nonsine harmonics
  90. // private:
  91. FFTwrapper *fft;
  92. //computes the basefunction and make the FFT; newbasefunc<0 = same basefunc
  93. void changebasefunction();
  94. //Waveshaping
  95. void waveshape();
  96. //Filter the oscillator accotding to Pfiltertype and Pfilterpar
  97. void oscilfilter();
  98. //Adjust the spectrum
  99. void spectrumadjust();
  100. //Shift the harmonics
  101. void shiftharmonics();
  102. //Do the oscil modulation stuff
  103. void modulation();
  104. //Check system for needed updates
  105. bool needPrepare(void);
  106. //Do the adaptive harmonic stuff
  107. void adaptiveharmonic(fft_t *f, float freq);
  108. //Do the adaptive harmonic postprocessing (2n+1,2xS,2xA,etc..)
  109. //this function is called even for the user interface
  110. //this can be called for the sine and components, and for the spectrum
  111. //(that's why the sine and cosine components should be processed with a separate call)
  112. void adaptiveharmonicpostprocess(fft_t *f, int size);
  113. //Internal Data
  114. unsigned char oldbasefunc, oldbasepar, oldhmagtype,
  115. oldwaveshapingfunction, oldwaveshaping;
  116. int oldfilterpars, oldsapars, oldbasefuncmodulation,
  117. oldbasefuncmodulationpar1, oldbasefuncmodulationpar2,
  118. oldbasefuncmodulationpar3, oldharmonicshift;
  119. int oldmodulation, oldmodulationpar1, oldmodulationpar2,
  120. oldmodulationpar3;
  121. fft_t *basefuncFFTfreqs; //Base Function Frequencies
  122. fft_t *oscilFFTfreqs; //Oscillator Frequencies - this is different than the hamonics set-up by the user, it may contains time-domain data if the antialiasing is turned off
  123. int oscilprepared; //1 if the oscil is prepared, 0 if it is not prepared and is need to call ::prepare() before ::get()
  124. Resonance *res;
  125. unsigned int randseed;
  126. };
  127. typedef float (*filter_func)(unsigned int, float, float);
  128. filter_func getFilter(unsigned char func);
  129. typedef float (*base_func)(float, float);
  130. base_func getBaseFunction(unsigned char func);
  131. #endif