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.

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