Minor detune bandwidth optimization
[zyn.git] / addsynth_internal.h
blob1cae5f3f8b3d4959ef09271f52e576cba97707f0
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Copyright (C) 2006,2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *****************************************************************************/
21 #ifndef ADDSYNTH_INTERNAL_H__9870368A_F1C9_4F0D_ADC1_B07ECFF2F9C7__INCLUDED
22 #define ADDSYNTH_INTERNAL_H__9870368A_F1C9_4F0D_ADC1_B07ECFF2F9C7__INCLUDED
24 #include "filter_common.h"
25 #include "filter_sv.h"
27 struct note_channel;
29 #define ZYN_FM_TYPE_NONE 0
30 #define ZYN_FM_TYPE_MORPH 1
31 #define ZYN_FM_TYPE_RING_MOD 2
32 #define ZYN_FM_TYPE_PHASE_MOD 3
33 #define ZYN_FM_TYPE_FREQ_MOD 4
34 #define ZYN_FM_TYPE_PITCH_MOD 5 /* code for this is disabled for some reason */
36 #define ZYN_DETUNE_NORMAL 0 /* the base frequency is normal one */
37 #define ZYN_DETUNE_FIXED_440 1 /* the base frequency is fixed to 440 Hz */
38 #define ZYN_DETUNE_EQUAL_TEMPERATE 2 /* Equal temperate */
40 struct zyn_fixed_detune
42 int mode; /* One of ZYN_DETUNE_XXX */
44 /* 0 .. 127 */
45 /* at 64, 1 MIDI halftone -> 1 frequency halftone */
46 unsigned char equal_temperate;
49 struct zyn_detune
51 signed int type; /* Detune type, one of ZYN_DETUNE_TYPE_XXX */
52 signed int octave; /* Octave, -8..7 */
53 signed int coarse; /* Coarse detune, -64 .. 63 */
54 float fine; /* Fine detune, -1..1 */
57 /***********************************************************/
58 /* VOICE PARAMETERS */
59 /***********************************************************/
60 struct zyn_addnote_voice_parameters
62 /* whether voice is enabled */
63 bool enabled;
65 /* Type of the voice (false = Sound, true = White Noise)*/
66 bool white_noise;
68 /* Voice Delay */
69 unsigned char PDelay;
71 /* whether resonance is enabled for this voice */
72 bool resonance;
74 // What external oscil should I use, -1 for internal OscilSmp&FMSmp
75 short int Pextoscil,PextFMoscil;
76 // it is not allowed that the externoscil,externFMoscil => current voice
78 // oscillator phases
79 unsigned char Poscilphase,PFMoscilphase;
81 // filter bypass
82 unsigned char Pfilterbypass;
84 /* Voice oscillator */
85 struct zyn_oscillator oscillator;
87 /**********************************
88 * FREQUENCY PARAMETERS *
89 **********************************/
91 struct zyn_detune detune;
92 struct zyn_fixed_detune fixed_detune;
94 /* Frequency Envelope */
95 unsigned char PFreqEnvelopeEnabled;
96 EnvelopeParams m_frequency_envelope_params;
98 /* Frequency LFO */
99 unsigned char PFreqLfoEnabled;
100 struct zyn_lfo_parameters frequency_lfo_params;
102 /***************************
103 * AMPLITUDE PARAMETERS *
104 ***************************/
106 /* Panning 0 - random
107 1 - left
108 64 - center
109 127 - right
110 The Panning is ignored if the instrument is mono */
111 unsigned char PPanning;
113 /* Voice Volume */
114 unsigned char PVolume;
116 /* If the Volume negative */
117 unsigned char PVolumeminus;
119 /* Velocity sensing */
120 unsigned char PAmpVelocityScaleFunction;
122 /* Amplitude Envelope */
123 unsigned char PAmpEnvelopeEnabled;
124 EnvelopeParams m_amplitude_envelope_params;
126 /* Amplitude LFO */
127 unsigned char PAmpLfoEnabled;
128 struct zyn_lfo_parameters amplitude_lfo_params;
130 /*************************
131 * FILTER PARAMETERS *
132 *************************/
134 /* Voice Filter */
135 unsigned char PFilterEnabled;
136 FilterParams m_filter_params;
138 /* Filter Envelope */
139 unsigned char PFilterEnvelopeEnabled;
140 EnvelopeParams m_filter_envelope_params;
142 /* LFO Envelope */
143 unsigned char PFilterLfoEnabled;
144 struct zyn_lfo_parameters filter_lfo_params;
146 /****************************
147 * MODULLATOR PARAMETERS *
148 ****************************/
150 /* Modullator Parameters, one of ZYN_FM_TYPE_XXX */
151 unsigned int fm_type;
153 /* Voice that I use as modullator instead of FMSmp.
154 It is -1 if I use FMSmp(default).
155 It maynot be equal or bigger than current voice */
156 short int PFMVoice;
158 /* Modullator oscillator */
159 struct zyn_oscillator modulator_oscillator;
161 /* Modullator Volume */
162 unsigned char PFMVolume;
164 /* Modullator damping at higher frequencies */
165 unsigned char PFMVolumeDamp;
167 /* Modullator Velocity Sensing */
168 unsigned char PFMVelocityScaleFunction;
170 /* Detune of the Modullator */
171 struct zyn_detune fm_detune;
173 /* Frequency Envelope of the Modullator */
174 unsigned char PFMFreqEnvelopeEnabled;
175 EnvelopeParams m_fm_frequency_envelope_params;
177 /* Frequency Envelope of the Modullator */
178 unsigned char PFMAmpEnvelopeEnabled;
179 EnvelopeParams m_fm_amplitude_envelope_params;
182 #include "addsynth_component.h"
184 struct zyn_addsynth
186 float sample_rate;
187 unsigned int polyphony;
188 struct note_channel * notes_array;
189 bool all_sound_off;
190 zyn_fft_handle fft;
191 unsigned char velsns; // velocity sensing (amplitude velocity scale)
192 zyn_sample_type oldfreq; // this is used for portamento
194 bool random_panorama; // whether panorama is random for each note
195 float panorama; // -1.0 for left, 0.0 for center, 1.0 for right
197 /* The instrument type - MONO/STEREO
198 If the mode is MONO, the panning of voices are not used
199 Stereo=true, Mono=false. */
200 bool stereo; // stereo or mono
202 // How the Harmonic Amplitude is applied to voices that use the same oscillator
203 bool random_grouping;
205 // RESONANCE
206 struct zyn_resonance resonance;
208 // 0-127, Master volume
209 unsigned char PVolume;
211 // 0-127, velocity sensing
212 unsigned char PAmpVelocityScaleFunction;
214 // 0-127
215 unsigned char PPunchStrength;
217 // 0-127
218 unsigned char PPunchTime;
220 // 0-127
221 unsigned char PPunchStretch;
223 // 0-127
224 unsigned char PPunchVelocitySensing;
226 // Amplitude LFO parameters
227 struct zyn_lfo_parameters amplitude_lfo_params;
229 EnvelopeParams m_amplitude_envelope_params;
231 int filter_type; /* filter category/supertype, one of ZYN_FILTER_TYPE_XXX */
232 FilterParams m_filter_params;
233 zyn_filter_sv_handle filter_sv;
235 // Velocity sensing amount of the Filter, 0 .. 1
236 float m_filter_velocity_sensing_amount;
238 // Velocity sensing function of the Filter, 1 .. -1
239 float m_filter_velocity_scale_function;
241 // Filter LFO parameters
242 struct zyn_lfo_parameters filter_lfo_params;
244 EnvelopeParams m_filter_envelope_params;
246 struct zyn_detune detune;
248 /* how much the relative fine detunes of the voices are changed */
249 /* -1.0 .. 1.0 */
250 float detune_bandwidth;
252 // Frequency LFO parameters
253 struct zyn_lfo_parameters frequency_lfo_params;
255 EnvelopeParams m_frequency_envelope_params;
257 zyn_portamento portamento;
259 float pitch_bend_range;
260 float pitch_bend;
261 float pitch_bend_relative_frequency;
263 int bandwidth_depth;
264 int bandwidth_exponential;
265 float bandwidth_relbw;
267 int modwheel_depth;
268 int modwheel_exponential;
269 float modwheel_relmod;
271 zyn_sample_type * temporary_samples_ptr; // this array stores some termporary data and it has OSCIL_SIZE elements
272 struct zyn_fft_freqs oscillator_fft_frequencies;
274 unsigned int voices_count;
276 struct zyn_addnote_voice_parameters * voices_params_ptr; /* array with one entry per voice */
278 struct zyn_component_descriptor global_components[ZYNADD_GLOBAL_COMPONENTS_COUNT];
280 struct zyn_component_descriptor * voices_components;
283 #ifdef __cplusplus
284 extern "C" {
285 #endif
286 #if 0
287 } /* Adjust editor indent */
288 #endif
290 float percent_from_0_127(unsigned char value);
291 unsigned char percent_to_0_127(float value);
293 void zyn_addsynth_set_bandwidth(struct zyn_addsynth * zyn_addsynth_ptr, int value);
294 void zyn_addsynth_set_modwheel(struct zyn_addsynth * zyn_addsynth_ptr, int value);
296 #if 0
297 { /* Adjust editor indent */
298 #endif
299 #ifdef __cplusplus
300 } /* extern "C" */
301 #endif
303 #define ZYN_UPDATE_PITCH_BEND(zyn_addsynth_ptr) \
304 (zyn_addsynth_ptr)->pitch_bend_relative_frequency = \
305 pow(2, (zyn_addsynth_ptr)->pitch_bend * \
306 (zyn_addsynth_ptr)->pitch_bend_range / \
307 1200.0);
309 #endif /* #ifndef ADDSYNTH_INTERNAL_H__9870368A_F1C9_4F0D_ADC1_B07ECFF2F9C7__INCLUDED */