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
;
74 typedef double fftw_real
;
75 typedef std::complex<fftw_real
> fft_t
;
78 * The number of harmonics of additive synth
79 * This must be smaller than OSCIL_SIZE/2
81 #define MAX_AD_HARMONICS 128
85 * The number of harmonics of substractive
87 #define MAX_SUB_HARMONICS 64
91 * The maximum number of samples that are used for 1 PADsynth instrument(or item)
93 #define PAD_MAX_SAMPLES 64
99 #define NUM_MIDI_PARTS 16
102 * Number of Midi channels
104 #define NUM_MIDI_CHANNELS 16
107 * The number of voices of additive synth for a single note
112 * The polyphony (notes)
117 * Number of system effects
119 #define NUM_SYS_EFX 4
123 * Number of insertion effects
125 #define NUM_INS_EFX 8
128 * Number of part's insertion effects
130 #define NUM_PART_EFX 3
133 * Maximum number of the instrument on a part
135 #define NUM_KIT_ITEMS 16
139 * How is applied the velocity sensing
141 #define VELOCITY_MAX_SCALE 8.0f
144 * The maximum length of instrument's name
146 #define PART_MAX_NAME_LEN 30
149 * The maximum we allow for an XMZ path
151 * Note that this is an ugly hack. Finding a compile time path
152 * max portably is painful.
154 #define XMZ_PATH_MAX 1024
157 * The maximum number of bands of the equaliser
159 #define MAX_EQ_BANDS 8
160 #if (MAX_EQ_BANDS >= 20)
161 #error "Too many EQ bands in globals.h"
166 * Maximum filter stages
168 #define MAX_FILTER_STAGES 5
171 * Formant filter (FF) limits
173 #define FF_MAX_VOWELS 6
174 #define FF_MAX_FORMANTS 12
175 #define FF_MAX_SEQUENCE 8
177 #define MAX_PRESETTYPE_SIZE 30
179 #define LOG_2 0.693147181f
180 #define PI 3.1415926536f
181 #define LOG_10 2.302585093f
184 * For de-pop adjustment
186 #define FADEIN_ADJUSTMENT_SCALE 20
191 #define MAX_ENVELOPE_POINTS 40
192 #define MIN_ENVELOPE_DB -400
195 * The threshold for the amplitude interpolation used if the amplitude
196 * is changed (by LFO's or Envelope's). If the change of the amplitude
197 * is below this, the amplitude is not interpolated
199 #define AMPLITUDE_INTERPOLATION_THRESHOLD 0.0001f
202 * How the amplitude threshold is computed
204 #define ABOVE_AMPLITUDE_THRESHOLD(a, b) ((2.0f * fabsf((b) - (a)) \
206 + 0.0000000001f))) > \
207 AMPLITUDE_INTERPOLATION_THRESHOLD)
210 * Interpolate Amplitude
212 #define INTERPOLATE_AMPLITUDE(a, b, x, size) ((a) \
214 - (a)) * (float)(x) \
221 #define dB2rap(dB) ((expf((dB) * LOG_10 / 20.0f)))
222 #define rap2dB(rap) ((20 * logf(rap) / LOG_10))
224 #define ZERO(data, size) {char *data_ = (char *) data; for(int i = 0; \
228 #define ZERO_float(data, size) {float *data_ = (float *) data; \
238 enum MidiControllers
{
239 C_bankselectmsb
= 0, C_pitchwheel
= 1000, C_NULL
= 1001,
240 C_aftertouch
= 1002, C_pitch
= 1003,
241 C_expression
= 11, C_panning
= 10, C_bankselectlsb
= 32,
242 C_filtercutoff
= 74, C_filterq
= 71, C_bandwidth
= 75, C_modwheel
= 1,
244 C_volume
= 7, C_sustain
= 64, C_allnotesoff
= 123, C_allsoundsoff
= 120,
245 C_resetallcontrollers
= 121,
246 C_portamento
= 65, C_resonance_center
= 77, C_resonance_bandwidth
= 78,
248 C_dataentryhi
= 0x06, C_dataentrylo
= 0x26, C_nrpnhi
= 99, C_nrpnlo
= 98
252 LM_Norm
, LM_FadeIn
, LM_FadeOut
, LM_CatchUp
, LM_ToNorm
255 //is like i=(int)(floor(f))
259 __asm__ __volatile__\
260 ("fistpl %0" : "=m" (i) : "t" (f - 0.49999999f) : "st");\
265 (i) = ((f > 0) ? ((int)(f)) : ((int)(f - 1.0f)));\
278 T
* ptr
= nullptr; //!< @invariant nullptr or pointer to new[]'ed memory
280 m_unique_array() = default;
281 m_unique_array(m_unique_array
&& other
) : ptr(other
.ptr
) {
284 m_unique_array
& operator=(m_unique_array
&& other
) {
289 m_unique_array(const m_unique_array
& other
) = delete;
290 ~m_unique_array() { delete[] ptr
; ptr
= nullptr; }
291 void resize(unsigned sz
) {
295 operator T
*() { return ptr
; }
296 operator const T
*() const { return ptr
; }
297 //T& operator[](unsigned idx) { return ptr[idx]; }
298 //const T& operator[](unsigned idx) const { return ptr[idx]; }
301 //temporary include for synth->{samplerate/buffersize} members
305 :samplerate(44100), buffersize(256), oscilsize(1024)
310 SYNTH_T(const SYNTH_T
& ) = delete;
311 SYNTH_T(SYNTH_T
&& ) = default;
312 SYNTH_T
& operator=(const SYNTH_T
& ) = delete;
313 SYNTH_T
& operator=(SYNTH_T
&& ) = default;
315 /** the buffer to add noise in order to avoid denormalisation */
316 m_unique_array
<float> denormalkillbuf
;
319 unsigned int samplerate
;
322 * The size of a sound buffer (or the granularity)
323 * All internal transfer of sound data use buffer of this size.
324 * All parameters are constant during this period of time, except
325 * some parameters(like amplitudes) which are linearly interpolated.
326 * If you increase this you'll ecounter big latencies, but if you
327 * decrease this the CPU requirements gets high.
332 * The size of ADnote Oscillator
333 * Decrease this => poor quality
334 * Increase this => CPU requirements gets high (only at start of the note)
338 //Alias for above terms
340 float halfsamplerate_f
;
347 return buffersize_f
/ samplerate_f
;
349 void alias(bool randomize
=true);
350 static float numRandom(void); //defined in Util.cpp for now
361 next_value
= curr_value
= 0.0f
;
363 smooth_float(const float value
) {
365 next_value
= curr_value
= value
;
368 const float delta
= (next_value
- curr_value
) / 128.0f
;
372 void operator =(const float value
) {
376 next_value
= curr_value
= value
;