Minot coding style fix
[zyn.git] / oscillator.h
bloba3ed7498d5b114f754011a3928da34e4f7c0915d
1 /*
2 ZynAddSubFX - a software synthesizer
4 OscilGen.h - Waveform generator for ADnote
5 Copyright (C) 2002-2005 Nasca Octavian Paul
6 Author: Nasca Octavian Paul
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.
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.
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
23 #ifndef OSCIL_GEN_H
24 #define OSCIL_GEN_H
26 #define ZYN_OSCILLATOR_EXTRA_POINTS 2
28 struct zyn_oscillator
30 //Parameters
32 /*
33 The hmag and hphase starts counting from 0, so the first harmonic(1) has the index 0,
34 2-nd harmonic has index 1, ..the 128 harminic has index 127
36 unsigned char Phmag[MAX_AD_HARMONICS],Phphase[MAX_AD_HARMONICS];//the MIDI parameters for mag. and phases
39 /*The Type of magnitude:
40 0 - Linear
41 1 - dB scale (-40)
42 2 - dB scale (-60)
43 3 - dB scale (-80)
44 4 - dB scale (-100)*/
45 unsigned char Phmagtype;
47 unsigned int base_function; /* The base function used, one of ZYN_OSCILLATOR_BASE_FUNCTION_XXX */
48 float base_function_adjust; /* the parameter of the base function, 0..1 */
50 bool base_function_needs_prepare;
52 unsigned char Pbasefuncmodulation;//what modulation is applied to the basefunc
53 unsigned char Pbasefuncmodulationpar1,Pbasefuncmodulationpar2,Pbasefuncmodulationpar3;//the parameter of the base function modulation
55 /*the Randomness:
56 64=no randomness
57 63..0 - block type randomness - 0 is maximum
58 65..127 - each harmonic randomness - 127 is maximum*/
59 unsigned char Prand;
61 float waveshaping_drive; /* 0..100 */
62 unsigned int waveshaping_function; /* waveshape type, one of ZYN_OSCILLATOR_WAVESHAPE_TYPE_XXX */
64 unsigned char Pfiltertype,Pfilterpar1,Pfilterpar2;
65 unsigned char Pfilterbeforews;
67 /* spectrum adjust */
68 unsigned int spectrum_adjust_type; /* one of ZYN_OSCILLATOR_SPECTRUM_ADJUST_TYPE_XXX */
69 float spectrum_adjust; /* 0..100 */
71 unsigned char Pamprandpower, Pamprandtype;//amplitude randomness
72 int Pharmonicshift;//how the harmonics are shifted
73 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
80 unsigned char Pmodulation;//what modulation is applied to the oscil
81 unsigned char Pmodulationpar1,Pmodulationpar2,Pmodulationpar3;//the parameter of the parameters
83 bool ADvsPAD;//if it is used by ADsynth or by PADsynth
85 // pointer to array of OSCIL_SIZE samples that stores some termporary data
86 zyn_sample_type * temporary_samples_ptr;
87 struct zyn_fft_freqs * oscillator_fft_frequencies_ptr;
89 float sample_rate;
91 REALTYPE hmag[MAX_AD_HARMONICS],hphase[MAX_AD_HARMONICS];//the magnituides and the phases of the sine/nonsine harmonics
93 zyn_fft_handle fft;
95 //Internal Data
97 unsigned char oldhmagtype;
99 int oldfilterpars,oldbasefuncmodulation,oldbasefuncmodulationpar1,oldbasefuncmodulationpar2,oldbasefuncmodulationpar3,oldharmonicshift;
100 int oldmodulation,oldmodulationpar1,oldmodulationpar2,oldmodulationpar3;
102 // Base Function Frequencies
103 struct zyn_fft_freqs basefuncFFTfreqs;
105 // 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
106 struct zyn_fft_freqs oscilFFTfreqs;
108 // true if the oscillator is prepared, false if it is not prepared and it is needed to call prepare() before get()
109 bool prepared;
111 struct zyn_resonance * resonance_ptr;
113 unsigned int randseed;
115 float modulation_temp[OSCIL_SIZE + ZYN_OSCILLATOR_EXTRA_POINTS];
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121 #if 0
122 } /* Adjust editor indent */
123 #endif
125 void
126 zyn_oscillator_init(
127 struct zyn_oscillator * oscillator_ptr,
128 float sample_rate,
129 zyn_fft_handle fft,
130 struct zyn_resonance * resonance_ptr,
131 zyn_sample_type * temporary_samples_ptr,
132 struct zyn_fft_freqs * oscillator_fft_frequencies_ptr);
134 void
135 zyn_oscillator_uninit(
136 struct zyn_oscillator * oscillator_ptr);
138 // makes a new random seed for Amplitude Randomness
139 // this should be called every note on event
140 void
141 zyn_oscillator_new_rand_seed(
142 struct zyn_oscillator * oscillator_ptr,
143 unsigned int randseed);
145 // do the antialiasing(cut off higher freqs.),apply randomness and do a IFFT
146 // returns where should I start getting samples, used in block type randomness
147 //if freqHz is smaller than 0, return the "un-randomized" sample for UI
149 short
150 zyn_oscillator_get(
151 struct zyn_oscillator * oscillator_ptr,
152 zyn_sample_type *smps,
153 float freqHz,
154 bool resonance);
156 #if 0
157 { /* Adjust editor indent */
158 #endif
159 #ifdef __cplusplus
160 } /* extern "C" */
161 #endif
163 #endif