Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

348 lines
8.1KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. globals.h - it contains program settings and the program capabilities
  4. like number of parts, of effects
  5. Copyright (C) 2002-2005 Nasca Octavian Paul
  6. Author: Nasca Octavian Paul
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of version 2 of the GNU General Public License
  9. as published by the Free Software Foundation.
  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 (version 2 or later) for more details.
  14. You should have received a copy of the GNU General Public License (version 2)
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef GLOBALS_H
  19. #define GLOBALS_H
  20. #if defined(__clang__)
  21. #define REALTIME __attribute__((annotate("realtime")))
  22. #define NONREALTIME __attribute__((annotate("nonrealtime")))
  23. #else
  24. #define REALTIME
  25. #define NONREALTIME
  26. #endif
  27. //Forward Declarations
  28. namespace rtosc{struct Ports; struct ClonePorts; struct MergePorts; class ThreadLink;};
  29. class EffectMgr;
  30. class ADnoteParameters;
  31. struct ADnoteGlobalParam;
  32. class SUBnoteParameters;
  33. class PADnoteParameters;
  34. class SynthNote;
  35. class Allocator;
  36. class AbsTime;
  37. class RelTime;
  38. class Microtonal;
  39. class XMLwrapper;
  40. class Resonance;
  41. class FFTwrapper;
  42. class EnvelopeParams;
  43. class LFOParams;
  44. class FilterParams;
  45. class LFO;
  46. class Envelope;
  47. class OscilGen;
  48. class Controller;
  49. class Master;
  50. class Part;
  51. class Filter;
  52. class AnalogFilter;
  53. class SVFilter;
  54. class FormantFilter;
  55. class ModFilter;
  56. #if defined(__APPLE__) || defined(__FreeBSD__)
  57. #include <complex>
  58. #else
  59. namespace std {
  60. template<class T> struct complex;
  61. };
  62. #endif
  63. typedef double fftw_real;
  64. typedef std::complex<fftw_real> fft_t;
  65. /**
  66. * The number of harmonics of additive synth
  67. * This must be smaller than OSCIL_SIZE/2
  68. */
  69. #define MAX_AD_HARMONICS 128
  70. /**
  71. * The number of harmonics of substractive
  72. */
  73. #define MAX_SUB_HARMONICS 64
  74. /*
  75. * The maximum number of samples that are used for 1 PADsynth instrument(or item)
  76. */
  77. #define PAD_MAX_SAMPLES 64
  78. /*
  79. * Number of parts
  80. */
  81. #define NUM_MIDI_PARTS 16
  82. /*
  83. * Number of Midi channes
  84. */
  85. #define NUM_MIDI_CHANNELS 16
  86. /*
  87. * The number of voices of additive synth for a single note
  88. */
  89. #define NUM_VOICES 8
  90. /*
  91. * The polyphony (notes)
  92. */
  93. #define POLYPHONY 60
  94. /*
  95. * Number of system effects
  96. */
  97. #define NUM_SYS_EFX 4
  98. /*
  99. * Number of insertion effects
  100. */
  101. #define NUM_INS_EFX 8
  102. /*
  103. * Number of part's insertion effects
  104. */
  105. #define NUM_PART_EFX 3
  106. /*
  107. * Maximum number of the instrument on a part
  108. */
  109. #define NUM_KIT_ITEMS 16
  110. /*
  111. * How is applied the velocity sensing
  112. */
  113. #define VELOCITY_MAX_SCALE 8.0f
  114. /*
  115. * The maximum length of instrument's name
  116. */
  117. #define PART_MAX_NAME_LEN 30
  118. /*
  119. * The maximum we allow for an XMZ path
  120. *
  121. * Note that this is an ugly hack. Finding a compile time path
  122. * max portably is painful.
  123. */
  124. #define XMZ_PATH_MAX 1024
  125. /*
  126. * The maximum number of bands of the equaliser
  127. */
  128. #define MAX_EQ_BANDS 8
  129. #if (MAX_EQ_BANDS >= 20)
  130. #error "Too many EQ bands in globals.h"
  131. #endif
  132. /*
  133. * Maximum filter stages
  134. */
  135. #define MAX_FILTER_STAGES 5
  136. /*
  137. * Formant filter (FF) limits
  138. */
  139. #define FF_MAX_VOWELS 6
  140. #define FF_MAX_FORMANTS 12
  141. #define FF_MAX_SEQUENCE 8
  142. #define MAX_PRESETTYPE_SIZE 30
  143. #define LOG_2 0.693147181f
  144. #define PI 3.1415926536f
  145. #define LOG_10 2.302585093f
  146. /*
  147. * For de-pop adjustment
  148. */
  149. #define FADEIN_ADJUSTMENT_SCALE 20
  150. /*
  151. * Envelope Limits
  152. */
  153. #define MAX_ENVELOPE_POINTS 40
  154. #define MIN_ENVELOPE_DB -400
  155. /*
  156. * The threshold for the amplitude interpolation used if the amplitude
  157. * is changed (by LFO's or Envelope's). If the change of the amplitude
  158. * is below this, the amplitude is not interpolated
  159. */
  160. #define AMPLITUDE_INTERPOLATION_THRESHOLD 0.0001f
  161. /*
  162. * How the amplitude threshold is computed
  163. */
  164. #define ABOVE_AMPLITUDE_THRESHOLD(a, b) ((2.0f * fabs((b) - (a)) \
  165. / (fabs((b) + (a) \
  166. + 0.0000000001f))) > \
  167. AMPLITUDE_INTERPOLATION_THRESHOLD)
  168. /*
  169. * Interpolate Amplitude
  170. */
  171. #define INTERPOLATE_AMPLITUDE(a, b, x, size) ((a) \
  172. + ((b) \
  173. - (a)) * (float)(x) \
  174. / (float) (size))
  175. /*
  176. * dB
  177. */
  178. #define dB2rap(dB) ((expf((dB) * LOG_10 / 20.0f)))
  179. #define rap2dB(rap) ((20 * logf(rap) / LOG_10))
  180. #define ZERO(data, size) {char *data_ = (char *) data; for(int i = 0; \
  181. i < size; \
  182. i++) \
  183. data_[i] = 0; }
  184. #define ZERO_float(data, size) {float *data_ = (float *) data; \
  185. for(int i = 0; \
  186. i < size; \
  187. i++) \
  188. data_[i] = 0.0f; }
  189. enum ONOFFTYPE {
  190. OFF = 0, ON = 1
  191. };
  192. enum MidiControllers {
  193. C_bankselectmsb = 0, C_pitchwheel = 1000, C_NULL = 1001,
  194. C_expression = 11, C_panning = 10, C_bankselectlsb = 32,
  195. C_filtercutoff = 74, C_filterq = 71, C_bandwidth = 75, C_modwheel = 1,
  196. C_fmamp = 76,
  197. C_volume = 7, C_sustain = 64, C_allnotesoff = 123, C_allsoundsoff = 120,
  198. C_resetallcontrollers = 121,
  199. C_portamento = 65, C_resonance_center = 77, C_resonance_bandwidth = 78,
  200. C_dataentryhi = 0x06, C_dataentrylo = 0x26, C_nrpnhi = 99, C_nrpnlo = 98
  201. };
  202. enum LegatoMsg {
  203. LM_Norm, LM_FadeIn, LM_FadeOut, LM_CatchUp, LM_ToNorm
  204. };
  205. //is like i=(int)(floor(f))
  206. #ifdef ASM_F2I_YES
  207. #define F2I(f, \
  208. i) __asm__ __volatile__ ("fistpl %0" : "=m" (i) : "t" (f \
  209. - \
  210. 0.49999999f) \
  211. : "st");
  212. #else
  213. #define F2I(f, i) (i) = ((f > 0) ? ((int)(f)) : ((int)(f - 1.0f)));
  214. #endif
  215. #ifndef O_BINARY
  216. #define O_BINARY 0
  217. #endif
  218. template<class T>
  219. class m_unique_ptr
  220. {
  221. T* ptr = nullptr;
  222. public:
  223. m_unique_ptr() = default;
  224. m_unique_ptr(m_unique_ptr&& other) {
  225. ptr = other.ptr;
  226. other.ptr = nullptr;
  227. }
  228. m_unique_ptr(const m_unique_ptr& other) = delete;
  229. ~m_unique_ptr() { ptr = nullptr; }
  230. void resize(unsigned sz) {
  231. delete[] ptr;
  232. ptr = new T[sz]; }
  233. operator T*() { return ptr; }
  234. operator const T*() const { return ptr; }
  235. //T& operator[](unsigned idx) { return ptr[idx]; }
  236. //const T& operator[](unsigned idx) const { return ptr[idx]; }
  237. };
  238. //temporary include for synth->{samplerate/buffersize} members
  239. struct SYNTH_T {
  240. SYNTH_T(void)
  241. :samplerate(44100), buffersize(256), oscilsize(1024)
  242. {
  243. alias(false);
  244. }
  245. SYNTH_T(const SYNTH_T& ) = delete;
  246. SYNTH_T(SYNTH_T&& ) = default;
  247. /** the buffer to add noise in order to avoid denormalisation */
  248. m_unique_ptr<float> denormalkillbuf;
  249. /**Sampling rate*/
  250. unsigned int samplerate;
  251. /**
  252. * The size of a sound buffer (or the granularity)
  253. * All internal transfer of sound data use buffer of this size.
  254. * All parameters are constant during this period of time, except
  255. * some parameters(like amplitudes) which are linearly interpolated.
  256. * If you increase this you'll ecounter big latencies, but if you
  257. * decrease this the CPU requirements gets high.
  258. */
  259. int buffersize;
  260. /**
  261. * The size of ADnote Oscillator
  262. * Decrease this => poor quality
  263. * Increase this => CPU requirements gets high (only at start of the note)
  264. */
  265. int oscilsize;
  266. //Alias for above terms
  267. float samplerate_f;
  268. float halfsamplerate_f;
  269. float buffersize_f;
  270. int bufferbytes;
  271. float oscilsize_f;
  272. float dt(void) const
  273. {
  274. return buffersize_f / samplerate_f;
  275. }
  276. void alias(bool randomize=true);
  277. static float numRandom(void); //defined in Util.cpp for now
  278. };
  279. #endif