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"
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 */
45 /* at 64, 1 MIDI halftone -> 1 frequency halftone */
46 unsigned char equal_temperate
;
52 unsigned short int fine
;
54 /* Coarse detune + octave */
55 unsigned short int coarse
;
61 /***********************************************************/
62 /* VOICE PARAMETERS */
63 /***********************************************************/
64 struct zyn_addnote_voice_parameters
66 /* whether voice is enabled */
69 /* Type of the voice (false = Sound, true = White Noise)*/
75 /* whether resonance is enabled for this voice */
78 // What external oscil should I use, -1 for internal OscilSmp&FMSmp
79 short int Pextoscil
,PextFMoscil
;
80 // it is not allowed that the externoscil,externFMoscil => current voice
83 unsigned char Poscilphase
,PFMoscilphase
;
86 unsigned char Pfilterbypass
;
88 /* Voice oscillator */
89 struct zyn_oscillator oscillator
;
91 /**********************************
92 * FREQUENCY PARAMETERS *
93 **********************************/
95 struct zyn_detune detune
;
96 struct zyn_fixed_detune fixed_detune
;
98 /* Frequency Envelope */
99 unsigned char PFreqEnvelopeEnabled
;
100 EnvelopeParams m_frequency_envelope_params
;
103 unsigned char PFreqLfoEnabled
;
104 struct zyn_lfo_parameters frequency_lfo_params
;
106 /***************************
107 * AMPLITUDE PARAMETERS *
108 ***************************/
110 /* Panning 0 - random
114 The Panning is ignored if the instrument is mono */
115 unsigned char PPanning
;
118 unsigned char PVolume
;
120 /* If the Volume negative */
121 unsigned char PVolumeminus
;
123 /* Velocity sensing */
124 unsigned char PAmpVelocityScaleFunction
;
126 /* Amplitude Envelope */
127 unsigned char PAmpEnvelopeEnabled
;
128 EnvelopeParams m_amplitude_envelope_params
;
131 unsigned char PAmpLfoEnabled
;
132 struct zyn_lfo_parameters amplitude_lfo_params
;
134 /*************************
135 * FILTER PARAMETERS *
136 *************************/
139 unsigned char PFilterEnabled
;
140 FilterParams m_filter_params
;
142 /* Filter Envelope */
143 unsigned char PFilterEnvelopeEnabled
;
144 EnvelopeParams m_filter_envelope_params
;
147 unsigned char PFilterLfoEnabled
;
148 struct zyn_lfo_parameters filter_lfo_params
;
150 /****************************
151 * MODULLATOR PARAMETERS *
152 ****************************/
154 /* Modullator Parameters, one of ZYN_FM_TYPE_XXX */
155 unsigned int fm_type
;
157 /* Voice that I use as modullator instead of FMSmp.
158 It is -1 if I use FMSmp(default).
159 It maynot be equal or bigger than current voice */
162 /* Modullator oscillator */
163 struct zyn_oscillator modulator_oscillator
;
165 /* Modullator Volume */
166 unsigned char PFMVolume
;
168 /* Modullator damping at higher frequencies */
169 unsigned char PFMVolumeDamp
;
171 /* Modullator Velocity Sensing */
172 unsigned char PFMVelocityScaleFunction
;
174 /* Detune of the Modullator */
175 struct zyn_detune fm_detune
;
177 /* Frequency Envelope of the Modullator */
178 unsigned char PFMFreqEnvelopeEnabled
;
179 EnvelopeParams m_fm_frequency_envelope_params
;
181 /* Frequency Envelope of the Modullator */
182 unsigned char PFMAmpEnvelopeEnabled
;
183 EnvelopeParams m_fm_amplitude_envelope_params
;
186 #include "addsynth_component.h"
191 unsigned int polyphony
;
192 struct note_channel
* notes_array
;
195 unsigned char velsns
; // velocity sensing (amplitude velocity scale)
196 zyn_sample_type oldfreq
; // this is used for portamento
198 bool random_panorama
; // whether panorama is random for each note
199 float panorama
; // -1.0 for left, 0.0 for center, 1.0 for right
201 /* The instrument type - MONO/STEREO
202 If the mode is MONO, the panning of voices are not used
203 Stereo=true, Mono=false. */
204 bool stereo
; // stereo or mono
206 // How the Harmonic Amplitude is applied to voices that use the same oscillator
207 bool random_grouping
;
210 struct zyn_resonance resonance
;
212 // 0-127, Master volume
213 unsigned char PVolume
;
215 // 0-127, velocity sensing
216 unsigned char PAmpVelocityScaleFunction
;
219 unsigned char PPunchStrength
;
222 unsigned char PPunchTime
;
225 unsigned char PPunchStretch
;
228 unsigned char PPunchVelocitySensing
;
230 // Amplitude LFO parameters
231 struct zyn_lfo_parameters amplitude_lfo_params
;
233 EnvelopeParams m_amplitude_envelope_params
;
235 int filter_type
; /* filter category/supertype, one of ZYN_FILTER_TYPE_XXX */
236 FilterParams m_filter_params
;
237 zyn_filter_sv_handle filter_sv
;
239 // Velocity sensing amount of the Filter, 0 .. 1
240 float m_filter_velocity_sensing_amount
;
242 // Velocity sensing function of the Filter, 1 .. -1
243 float m_filter_velocity_scale_function
;
245 // Filter LFO parameters
246 struct zyn_lfo_parameters filter_lfo_params
;
248 EnvelopeParams m_filter_envelope_params
;
250 struct zyn_detune detune
;
252 /* how much the relative fine detunes of the voices are changed */
254 float detune_bandwidth
;
256 // Frequency LFO parameters
257 struct zyn_lfo_parameters frequency_lfo_params
;
259 EnvelopeParams m_frequency_envelope_params
;
261 zyn_portamento portamento
;
263 float pitch_bend_range
;
265 float pitch_bend_relative_frequency
;
268 int bandwidth_exponential
;
269 float bandwidth_relbw
;
272 int modwheel_exponential
;
273 float modwheel_relmod
;
275 zyn_sample_type
* temporary_samples_ptr
; // this array stores some termporary data and it has OSCIL_SIZE elements
276 struct zyn_fft_freqs oscillator_fft_frequencies
;
278 unsigned int voices_count
;
280 struct zyn_addnote_voice_parameters
* voices_params_ptr
; /* array with one entry per voice */
282 struct zyn_component_descriptor global_components
[ZYNADD_GLOBAL_COMPONENTS_COUNT
];
284 struct zyn_component_descriptor
* voices_components
;
291 } /* Adjust editor indent */
294 float percent_from_0_127(unsigned char value
);
295 unsigned char percent_to_0_127(float value
);
297 void zyn_addsynth_set_bandwidth(struct zyn_addsynth
* zyn_addsynth_ptr
, int value
);
298 void zyn_addsynth_set_modwheel(struct zyn_addsynth
* zyn_addsynth_ptr
, int value
);
301 { /* Adjust editor indent */
307 #define ZYN_UPDATE_PITCH_BEND(zyn_addsynth_ptr) \
308 (zyn_addsynth_ptr)->pitch_bend_relative_frequency = \
309 pow(2, (zyn_addsynth_ptr)->pitch_bend * \
310 (zyn_addsynth_ptr)->pitch_bend_range / \
313 #endif /* #ifndef ADDSYNTH_INTERNAL_H__9870368A_F1C9_4F0D_ADC1_B07ECFF2F9C7__INCLUDED */