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.

globals.h 7.7KB

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