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 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #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