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.

340 lines
7.7KB

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