home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / ZynAddFX / Setup_ZynAddSubFX-2.1.1.exe / OscilGen.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-08-24  |  6.2 KB  |  174 lines

  1. /*
  2.   ZynAddSubFX - a software synthesizer
  3.  
  4.   OscilGen.h - Waveform generator for ADnote
  5.   Copyright (C) 2002-2004 Nasca Octavian Paul
  6.   Author: Nasca Octavian Paul
  7.  
  8.   This program is free software; you can redistribute it and/or modify
  9.   it under the terms of version 2 of the GNU General Public License 
  10.   as published by the Free Software Foundation.
  11.  
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License (version 2) for more details.
  16.  
  17.   You should have received a copy of the GNU General Public License (version 2)
  18.   along with this program; if not, write to the Free Software Foundation,
  19.   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  20.  
  21. */
  22.  
  23. #ifndef OSCIL_GEN_H
  24. #define OSCIL_GEN_H
  25.  
  26. #include "../globals.h"
  27. #include "../Misc/XMLwrapper.h"
  28. #include "Resonance.h"
  29. #include "../DSP/FFTwrapper.h"  
  30. #include "../Params/Presets.h"
  31.  
  32. class OscilGen:public Presets{
  33.     public:
  34.     OscilGen(FFTwrapper *fft_,Resonance *res_);
  35.     ~OscilGen();
  36.  
  37.         //computes the full spectrum of oscil from harmonics,phases and basefunc
  38.     void prepare();
  39.  
  40.     //do the antialiasing(cut off higher freqs.),apply randomness and do a IFFT
  41.     short get(REALTYPE *smps,REALTYPE freqHz);//returns where should I start getting samples, used in block type randomness
  42.     short get(REALTYPE *smps,REALTYPE freqHz,int resonance);
  43.     //if freqHz is smaller than 0, return the "un-randomized" sample for UI
  44.     
  45.         void getbasefunction(REALTYPE *smps);
  46.  
  47.     //called by UI
  48.     void getspectrum(int n,REALTYPE *spc,int what);//what=0 pt. oscil,1 pt. basefunc
  49.         void getcurrentbasefunction(REALTYPE *smps);
  50.     void useasbase();//convert oscil to base function
  51.  
  52.         void add2XML(XMLwrapper *xml);
  53.     void defaults();
  54.     void getfromXML(XMLwrapper *xml);
  55.  
  56.     void convert2sine(int magtype);
  57.     
  58.     //Parameters
  59.             
  60.     /* 
  61.       The hmag and hphase starts counting from 0, so the first harmonic(1) has the index 0,
  62.       2-nd harmonic has index 1, ..the 128 harminic has index 127
  63.     */
  64.     unsigned char Phmag[MAX_AD_HARMONICS],Phphase[MAX_AD_HARMONICS];//the MIDI parameters for mag. and phases
  65.     
  66.     
  67.     /*The Type of magnitude:
  68.         0 - Linear
  69.         1 - dB scale (-40)
  70.         2 - dB scale (-60)
  71.         3 - dB scale (-80)
  72.         4 - dB scale (-100)*/
  73.     unsigned char Phmagtype;
  74.  
  75.     unsigned char Pcurrentbasefunc;//The base function used - 0=sin, 1=...
  76.     unsigned char Pbasefuncpar;//the parameter of the base function
  77.     
  78.     unsigned char Pbasefuncmodulation;//what modulation is applied to the basefunc
  79.     unsigned char Pbasefuncmodulationpar1,Pbasefuncmodulationpar2,Pbasefuncmodulationpar3;//the parameter of the base function modulation
  80.  
  81.     /*the Randomness:
  82.       64=no randomness
  83.       63..0 - block type randomness - 0 is maximum
  84.       65..127 - each harmonic randomness - 127 is maximum*/
  85.     unsigned char Prand;
  86.     unsigned char Pwaveshaping,Pwaveshapingfunction;
  87.     unsigned char Pfiltertype,Pfilterpar1,Pfilterpar2;
  88.     unsigned char Pfilterbeforews;
  89.     unsigned char Psatype,Psapar;//spectrum adjust
  90.  
  91.     unsigned char Pamprandpower, Pamprandtype;//amplitude randomness
  92.     int Pharmonicshift;//how the harmonics are shifted
  93.     int Pharmonicshiftfirst;//if the harmonic shift is done before waveshaping and filter
  94.  
  95.     unsigned char Padaptiveharmonics;//the adaptive harmonics status (off=0,on=1)
  96.     unsigned char Padaptiveharmonicsbasefreq;//the base frequency of the adaptive harmonic (30..3000Hz)
  97.     unsigned char Padaptiveharmonicspower;//the strength of the effect (0=off,100=full)
  98.  
  99.     unsigned char Pmodulation;//what modulation is applied to the oscil
  100.     unsigned char Pmodulationpar1,Pmodulationpar2,Pmodulationpar3;//the parameter of the parameters
  101.  
  102.  
  103.     //makes a new random seed for Amplitude Randomness
  104.     //this should be called every note on event
  105.     void newrandseed(unsigned int randseed);
  106.     
  107.     bool ADvsPAD;//if it is used by ADsynth or by PADsynth
  108.     
  109.     private:
  110.     
  111.     REALTYPE hmag[MAX_AD_HARMONICS],hphase[MAX_AD_HARMONICS];//the magnituides and the phases of the sine/nonsine harmonics
  112. //    private:
  113.     FFTwrapper *fft;
  114.     //computes the basefunction and make the FFT; newbasefunc<0  = same basefunc
  115.     void changebasefunction();
  116.     //Waveshaping
  117.     void waveshape();
  118.  
  119.     //Filter the oscillator accotding to Pfiltertype and Pfilterpar
  120.     void oscilfilter();
  121.  
  122.     //Adjust the spectrum
  123.     void spectrumadjust();
  124.     
  125.     //Shift the harmonics
  126.     void shiftharmonics();
  127.     
  128.     //Do the oscil modulation stuff
  129.     void modulation();
  130.  
  131.     //Do the adaptive harmonic stuff
  132.     void adaptiveharmonic(REALTYPE *freqs,REALTYPE freq);
  133.     
  134.         
  135.         //Basic/base functions (Functiile De Baza)
  136.     REALTYPE basefunc_pulse(REALTYPE x,REALTYPE a);
  137.     REALTYPE basefunc_saw(REALTYPE x,REALTYPE a);
  138.     REALTYPE basefunc_triangle(REALTYPE x,REALTYPE a);
  139.     REALTYPE basefunc_power(REALTYPE x,REALTYPE a);
  140.     REALTYPE basefunc_gauss(REALTYPE x,REALTYPE a);
  141.     REALTYPE basefunc_diode(REALTYPE x,REALTYPE a);
  142.     REALTYPE basefunc_abssine(REALTYPE x,REALTYPE a);
  143.     REALTYPE basefunc_pulsesine(REALTYPE x,REALTYPE a);
  144.     REALTYPE basefunc_stretchsine(REALTYPE x,REALTYPE a);
  145.     REALTYPE basefunc_chirp(REALTYPE x,REALTYPE a);
  146.     REALTYPE basefunc_absstretchsine(REALTYPE x,REALTYPE a);
  147.     REALTYPE basefunc_chebyshev(REALTYPE x,REALTYPE a);
  148.     REALTYPE basefunc_sqr(REALTYPE x,REALTYPE a);
  149.  
  150.     //Internal Data
  151.     unsigned char oldbasefunc,oldbasepar,oldhmagtype,oldwaveshapingfunction,oldwaveshaping;
  152.     int oldfilterpars,oldsapars,oldbasefuncmodulation,oldbasefuncmodulationpar1,oldbasefuncmodulationpar2,oldbasefuncmodulationpar3,oldharmonicshift;
  153.     int oldmodulation,oldmodulationpar1,oldmodulationpar2,oldmodulationpar3;
  154.     /*
  155.       The frequencies of wavefroms are stored like this:
  156.       c[0],c[1],....,c[OSCIL_SIZE/2],s[OSCIL_SIZE/2-1],...,s[2],s[1]
  157.       c[N] is the cosine component and the s[N] is the sine component in the frequency domain
  158.       This way of storing of frequencies is similar to the FFTW package.
  159.     */
  160.     REALTYPE *basefuncFFTfreqs;//Base Function Frequencies
  161.     REALTYPE *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
  162.     int oscilprepared;//1 if the oscil is prepared, 0 if it is not prepared and is need to call ::prepare() before ::get()
  163.     REALTYPE *outoscilFFTfreqs;
  164.     
  165.     unsigned short int *basefuncFFTfreqsQ;
  166.     Resonance *res;    
  167.     
  168.     unsigned int randseed;
  169.     
  170. };
  171.  
  172.  
  173. #endif
  174.