2 ZynAddSubFX - a software synthesizer
4 globals.h - it contains program settings and the program capabilities
5 like number of parts, of effects
6 Copyright (C) 2002-2005 Nasca Octavian Paul
7 Author: Nasca Octavian Paul
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
19 #if defined(__clang__)
20 #define REALTIME __attribute__((annotate("realtime")))
21 #define NONREALTIME __attribute__((annotate("nonrealtime")))
27 //Forward Declarations
29 #if defined(HAVE_CPP_STD_COMPLEX)
33 template<class T
> struct complex;
37 namespace rtosc
{struct Ports
; struct ClonePorts
; struct MergePorts
; class ThreadLink
;}
41 class ADnoteParameters
;
42 struct ADnoteGlobalParam
;
43 class SUBnoteParameters
;
44 class PADnoteParameters
;
76 typedef float fftwf_real
;
77 typedef std::complex<fftwf_real
> fft_t
;
80 * The number of harmonics of additive synth
81 * This must be smaller than OSCIL_SIZE/2
83 #define MAX_AD_HARMONICS 128
87 * The number of harmonics of substractive
89 #define MAX_SUB_HARMONICS 64
93 * The maximum number of samples that are used for 1 PADsynth instrument(or item)
95 #define PAD_MAX_SAMPLES 64
101 #define NUM_MIDI_PARTS 16
104 * Number of Midi channels
106 #define NUM_MIDI_CHANNELS 16
109 * The number of voices of additive synth for a single note
114 * The polyphony (notes)
119 * Number of system effects
121 #define NUM_SYS_EFX 4
125 * Number of insertion effects
127 #define NUM_INS_EFX 8
130 * Number of part's insertion effects
132 #define NUM_PART_EFX 3
135 * Maximum number of the instrument on a part
137 #define NUM_KIT_ITEMS 16
140 * Maximum number of "strings" in Sympathetic Resonance Effect
142 #define NUM_SYMPATHETIC_STRINGS 228U // 76*3
145 * How is applied the velocity sensing
147 #define VELOCITY_MAX_SCALE 8.0f
150 * The maximum length of instrument's name
152 #define PART_MAX_NAME_LEN 30
155 * The maximum we allow for an XMZ path
157 * Note that this is an ugly hack. Finding a compile time path
158 * max portably is painful.
160 #define XMZ_PATH_MAX 1024
163 * The maximum number of bands of the equaliser
165 #define MAX_EQ_BANDS 8
166 #if (MAX_EQ_BANDS >= 20)
167 #error "Too many EQ bands in globals.h"
172 * Maximum filter stages
174 #define MAX_FILTER_STAGES 5
177 * Formant filter (FF) limits
179 #define FF_MAX_VOWELS 6
180 #define FF_MAX_FORMANTS 12
181 #define FF_MAX_SEQUENCE 8
183 #define MAX_PRESETTYPE_SIZE 30
185 #define LOG_2 0.693147181f
186 #define PI 3.1415926536f
187 #define PIDIV2 1.5707963268f
188 #define LOG_10 2.302585093f
191 * For de-pop adjustment
193 #define FADEIN_ADJUSTMENT_SCALE 20
198 #define MAX_ENVELOPE_POINTS 40
199 #define MIN_ENVELOPE_DB -400
202 * The threshold for the amplitude interpolation used if the amplitude
203 * is changed (by LFO's or Envelope's). If the change of the amplitude
204 * is below this, the amplitude is not interpolated
206 #define AMPLITUDE_INTERPOLATION_THRESHOLD 0.0001f
209 * How the amplitude threshold is computed
211 #define ABOVE_AMPLITUDE_THRESHOLD(a, b) ((2.0f * fabsf((b) - (a)) \
213 + 0.0000000001f))) > \
214 AMPLITUDE_INTERPOLATION_THRESHOLD)
217 * Interpolate Amplitude
219 #define INTERPOLATE_AMPLITUDE(a, b, x, size) ((a) \
221 - (a)) * (float)(x) \
228 #define dB2rap(dB) ((expf((dB) * LOG_10 / 20.0f)))
229 #define rap2dB(rap) ((20 * logf(rap) / LOG_10))
231 #define ZERO(data, size) {char *data_ = (char *) data; for(int i = 0; \
235 #define ZERO_float(data, size) {float *data_ = (float *) data; \
245 enum MidiControllers
{
246 C_bankselectmsb
= 0, C_pitchwheel
= 1000, C_NULL
= 1001,
247 C_aftertouch
= 1002, C_pitch
= 1003,
248 C_expression
= 11, C_panning
= 10, C_bankselectlsb
= 32,
249 C_filtercutoff
= 74, C_filterq
= 71, C_bandwidth
= 75, C_modwheel
= 1,
251 C_volume
= 7, C_sustain
= 64, C_allnotesoff
= 123, C_allsoundsoff
= 120,
252 C_resetallcontrollers
= 121,
253 C_portamento
= 65, C_resonance_center
= 77, C_resonance_bandwidth
= 78,
255 C_dataentryhi
= 0x06, C_dataentrylo
= 0x26, C_nrpnhi
= 99, C_nrpnlo
= 98
259 LM_Norm
, LM_FadeIn
, LM_FadeOut
, LM_CatchUp
, LM_ToNorm
262 //is like i=(int)(floor(f))
266 __asm__ __volatile__\
267 ("fistpl %0" : "=m" (i) : "t" (f - 0.49999999f) : "st");\
272 (i) = ((f > 0) ? ((int)(f)) : ((int)(f - 1.0f)));\
285 T
* ptr
= nullptr; //!< @invariant nullptr or pointer to new[]'ed memory
287 m_unique_array() = default;
288 m_unique_array(m_unique_array
&& other
) : ptr(other
.ptr
) {
291 m_unique_array
& operator=(m_unique_array
&& other
) {
296 m_unique_array(const m_unique_array
& other
) = delete;
297 ~m_unique_array() { delete[] ptr
; ptr
= nullptr; }
298 void resize(unsigned sz
) {
302 operator T
*() { return ptr
; }
303 operator const T
*() const { return ptr
; }
304 //T& operator[](unsigned idx) { return ptr[idx]; }
305 //const T& operator[](unsigned idx) const { return ptr[idx]; }
308 //temporary include for synth->{samplerate/buffersize} members
312 :samplerate(44100), buffersize(256), oscilsize(1024)
317 SYNTH_T(const SYNTH_T
& ) = delete;
318 SYNTH_T(SYNTH_T
&& ) = default;
319 SYNTH_T
& operator=(const SYNTH_T
& ) = delete;
320 SYNTH_T
& operator=(SYNTH_T
&& ) = default;
322 /** the buffer to add noise in order to avoid denormalisation */
323 m_unique_array
<float> denormalkillbuf
;
326 unsigned int samplerate
;
329 * The size of a sound buffer (or the granularity)
330 * All internal transfer of sound data use buffer of this size.
331 * All parameters are constant during this period of time, except
332 * some parameters(like amplitudes) which are linearly interpolated.
333 * If you increase this you'll encounter big latencies, but if you
334 * decrease this the CPU requirements gets high.
339 * The size of ADnote Oscillator
340 * Decrease this => poor quality
341 * Increase this => CPU requirements gets high (only at start of the note)
345 //Alias for above terms
347 float halfsamplerate_f
;
354 return buffersize_f
/ samplerate_f
;
356 void alias(bool randomize
=true);
357 static float numRandom(void); //defined in Util.cpp for now
368 next_value
= curr_value
= 0.0f
;
370 smooth_float(const float value
) {
372 next_value
= curr_value
= value
;
375 const float delta
= (next_value
- curr_value
) / 32.0f
;
379 void operator =(const float value
) {
383 next_value
= curr_value
= value
;