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.

304 lines
7.2KB

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