Collection of DPF-based plugins for packaging
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.

378 lines
11KB

  1. #include "gen_exported.h"
  2. namespace gen_exported {
  3. /*******************************************************************************************************************
  4. Copyright (c) 2012 Cycling '74
  5. Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  6. and associated documentation files (the "Software"), to deal in the Software without restriction,
  7. including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
  9. subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all copies
  11. or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  14. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  15. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  16. OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. *******************************************************************************************************************/
  18. // global noise generator
  19. Noise noise;
  20. static const int GENLIB_LOOPCOUNT_BAIL = 100000;
  21. // The State struct contains all the state and procedures for the gendsp kernel
  22. typedef struct State {
  23. CommonState __commonstate;
  24. DCBlock m_dcblock_13;
  25. Delay m_delay_5;
  26. Delay m_delay_4;
  27. SineCycle m_cycle_14;
  28. SineData __sinedata;
  29. double m_depth_9;
  30. double m_time_10;
  31. double m_tone_12;
  32. double m_morph_11;
  33. double m_rate_8;
  34. double m_repeats_6;
  35. double m_smth_3;
  36. double m_mix_7;
  37. double m_smth_1;
  38. double samplerate;
  39. double m_y_2;
  40. int vectorsize;
  41. int __exception;
  42. // re-initialize all member variables;
  43. inline void reset(double __sr, int __vs) {
  44. __exception = 0;
  45. vectorsize = __vs;
  46. samplerate = __sr;
  47. m_smth_1 = 0;
  48. m_y_2 = 0;
  49. m_smth_3 = 0;
  50. m_delay_4.reset("m_delay_4", 44100);
  51. m_delay_5.reset("m_delay_5", 44100);
  52. m_repeats_6 = 75;
  53. m_mix_7 = 75;
  54. m_rate_8 = 2;
  55. m_depth_9 = 1;
  56. m_time_10 = 500;
  57. m_morph_11 = 50;
  58. m_tone_12 = 3000;
  59. m_dcblock_13.reset();
  60. m_cycle_14.reset(samplerate, 0);
  61. genlib_reset_complete(this);
  62. };
  63. // the signal processing routine;
  64. inline int perform(t_sample ** __ins, t_sample ** __outs, int __n) {
  65. vectorsize = __n;
  66. const t_sample * __in1 = __ins[0];
  67. t_sample * __out1 = __outs[0];
  68. if (__exception) {
  69. return __exception;
  70. } else if (( (__in1 == 0) || (__out1 == 0) )) {
  71. __exception = GENLIB_ERR_NULL_BUFFER;
  72. return __exception;
  73. };
  74. double mul_141 = (m_mix_7 * 0.01);
  75. double mstosamps_153 = (m_time_10 * (samplerate * 0.001));
  76. double expr_185 = safediv(((m_tone_12 * 2) * 3.1415926535898), 48000);
  77. double sin_148 = sin(expr_185);
  78. double clamp_149 = ((sin_148 <= 1e-05) ? 1e-05 : ((sin_148 >= 0.99999) ? 0.99999 : sin_148));
  79. int lt_156 = (m_morph_11 < 50);
  80. double mul_166 = (m_morph_11 * -0.8);
  81. double add_164 = (mul_166 + 40);
  82. double abs_165 = fabs(add_164);
  83. double mul_169 = (abs_165 * 0.01);
  84. double mul_145 = (m_repeats_6 * 0.01);
  85. double mul_155 = (m_morph_11 * -0.4);
  86. double add_154 = (mul_155 + 20);
  87. double mul_157 = (lt_156 * add_154);
  88. double mul_138 = (m_morph_11 * -0.8);
  89. double add_136 = (mul_138 + 40);
  90. double abs_137 = fabs(add_136);
  91. double rsub_135 = (80 - abs_137);
  92. double mul_139 = (rsub_135 * 0.01);
  93. double mul_168 = (m_morph_11 * 0.8);
  94. double sub_167 = (mul_168 - 40);
  95. double mul_170 = (sub_167 * 0.01);
  96. int gt_162 = (m_morph_11 > 50);
  97. double mul_161 = (gt_162 * m_morph_11);
  98. double sub_160 = (mul_161 - 50);
  99. double clamp_159 = ((sub_160 <= 0) ? 0 : ((sub_160 >= 50) ? 50 : sub_160));
  100. double mul_163 = (clamp_159 * 0.04);
  101. double add_158 = (mul_157 + mul_163);
  102. // the main sample loop;
  103. while ((__n--)) {
  104. const double in1 = (*(__in1++));
  105. double mix_189 = (mstosamps_153 + (0.999 * (m_smth_3 - mstosamps_153)));
  106. double mix_142 = mix_189;
  107. double tap_152 = m_delay_5.read_linear(mix_142);
  108. double mix_190 = (m_y_2 + (clamp_149 * (tap_152 - m_y_2)));
  109. double mix_146 = mix_190;
  110. double mul_175 = (mix_146 * mul_169);
  111. double mul_150 = (mix_146 * mul_145);
  112. double dcblock_143 = m_dcblock_13(mul_150);
  113. double clamp_144 = ((dcblock_143 <= -1) ? -1 : ((dcblock_143 >= 1) ? 1 : dcblock_143));
  114. m_cycle_14.freq(m_rate_8);
  115. double cycle_180 = m_cycle_14(__sinedata);
  116. double cycleindex_181 = m_cycle_14.phase();
  117. double add_179 = (cycle_180 + 1);
  118. double mul_178 = (add_179 * 0.5);
  119. double mul_182 = (m_depth_9 * mul_178);
  120. double add_171 = (mul_182 + add_158);
  121. double mstosamps_177 = (add_171 * (samplerate * 0.001));
  122. double mix_191 = (mstosamps_177 + (0.999 * (m_smth_1 - mstosamps_177)));
  123. double mix_176 = mix_191;
  124. double tap_184 = m_delay_4.read_linear(mix_176);
  125. double mul_172 = (tap_184 * mul_139);
  126. double mul_140 = ((mul_172 + mul_175) * mul_141);
  127. double out1 = (mul_140 + in1);
  128. double mul_173 = (tap_184 * mul_170);
  129. double add_174 = (mix_146 + mul_173);
  130. double smth1_next_186 = mix_142;
  131. double y0_next_187 = mix_146;
  132. double smth2_next_188 = mix_176;
  133. m_delay_5.write((clamp_144 + in1));
  134. m_delay_4.write(add_174);
  135. m_smth_3 = smth1_next_186;
  136. m_y_2 = y0_next_187;
  137. m_smth_1 = smth2_next_188;
  138. m_delay_4.step();
  139. m_delay_5.step();
  140. // assign results to output buffer;
  141. (*(__out1++)) = out1;
  142. };
  143. return __exception;
  144. };
  145. inline void set_repeats(double _value) {
  146. m_repeats_6 = (_value < 0 ? 0 : (_value > 110 ? 110 : _value));
  147. };
  148. inline void set_mix(double _value) {
  149. m_mix_7 = (_value < 0 ? 0 : (_value > 100 ? 100 : _value));
  150. };
  151. inline void set_rate(double _value) {
  152. m_rate_8 = (_value < 0.1 ? 0.1 : (_value > 5 ? 5 : _value));
  153. };
  154. inline void set_depth(double _value) {
  155. m_depth_9 = (_value < 0.1 ? 0.1 : (_value > 3 ? 3 : _value));
  156. };
  157. inline void set_time(double _value) {
  158. m_time_10 = (_value < 20 ? 20 : (_value > 1000 ? 1000 : _value));
  159. };
  160. inline void set_morph(double _value) {
  161. m_morph_11 = (_value < 0 ? 0 : (_value > 100 ? 100 : _value));
  162. };
  163. inline void set_tone(double _value) {
  164. m_tone_12 = (_value < 500 ? 500 : (_value > 6000 ? 6000 : _value));
  165. };
  166. } State;
  167. ///
  168. /// Configuration for the genlib API
  169. ///
  170. /// Number of signal inputs and outputs
  171. int gen_kernel_numins = 1;
  172. int gen_kernel_numouts = 1;
  173. int num_inputs() { return gen_kernel_numins; }
  174. int num_outputs() { return gen_kernel_numouts; }
  175. int num_params() { return 7; }
  176. /// Assistive lables for the signal inputs and outputs
  177. const char * gen_kernel_innames[] = { "in1" };
  178. const char * gen_kernel_outnames[] = { "out1" };
  179. /// Invoke the signal process of a State object
  180. int perform(CommonState *cself, t_sample **ins, long numins, t_sample **outs, long numouts, long n) {
  181. State * self = (State *)cself;
  182. return self->perform(ins, outs, n);
  183. }
  184. /// Reset all parameters and stateful operators of a State object
  185. void reset(CommonState *cself) {
  186. State * self = (State *)cself;
  187. self->reset(cself->sr, cself->vs);
  188. }
  189. /// Set a parameter of a State object
  190. void setparameter(CommonState *cself, long index, double value, void *ref) {
  191. State * self = (State *)cself;
  192. switch (index) {
  193. case 0: self->set_repeats(value); break;
  194. case 1: self->set_mix(value); break;
  195. case 2: self->set_rate(value); break;
  196. case 3: self->set_depth(value); break;
  197. case 4: self->set_time(value); break;
  198. case 5: self->set_morph(value); break;
  199. case 6: self->set_tone(value); break;
  200. default: break;
  201. }
  202. }
  203. /// Get the value of a parameter of a State object
  204. void getparameter(CommonState *cself, long index, double *value) {
  205. State *self = (State *)cself;
  206. switch (index) {
  207. case 0: *value = self->m_repeats_6; break;
  208. case 1: *value = self->m_mix_7; break;
  209. case 2: *value = self->m_rate_8; break;
  210. case 3: *value = self->m_depth_9; break;
  211. case 4: *value = self->m_time_10; break;
  212. case 5: *value = self->m_morph_11; break;
  213. case 6: *value = self->m_tone_12; break;
  214. default: break;
  215. }
  216. }
  217. /// Allocate and configure a new State object and it's internal CommonState:
  218. void * create(double sr, long vs) {
  219. State *self = new State;
  220. self->reset(sr, vs);
  221. ParamInfo *pi;
  222. self->__commonstate.inputnames = gen_kernel_innames;
  223. self->__commonstate.outputnames = gen_kernel_outnames;
  224. self->__commonstate.numins = gen_kernel_numins;
  225. self->__commonstate.numouts = gen_kernel_numouts;
  226. self->__commonstate.sr = sr;
  227. self->__commonstate.vs = vs;
  228. self->__commonstate.params = (ParamInfo *)genlib_sysmem_newptr(7 * sizeof(ParamInfo));
  229. self->__commonstate.numparams = 7;
  230. // initialize parameter 0 ("m_repeats_6")
  231. pi = self->__commonstate.params + 0;
  232. pi->name = "repeats";
  233. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  234. pi->defaultvalue = self->m_repeats_6;
  235. pi->defaultref = 0;
  236. pi->hasinputminmax = false;
  237. pi->inputmin = 0;
  238. pi->inputmax = 1;
  239. pi->hasminmax = true;
  240. pi->outputmin = 0;
  241. pi->outputmax = 110;
  242. pi->exp = 0;
  243. pi->units = ""; // no units defined
  244. // initialize parameter 1 ("m_mix_7")
  245. pi = self->__commonstate.params + 1;
  246. pi->name = "mix";
  247. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  248. pi->defaultvalue = self->m_mix_7;
  249. pi->defaultref = 0;
  250. pi->hasinputminmax = false;
  251. pi->inputmin = 0;
  252. pi->inputmax = 1;
  253. pi->hasminmax = true;
  254. pi->outputmin = 0;
  255. pi->outputmax = 100;
  256. pi->exp = 0;
  257. pi->units = ""; // no units defined
  258. // initialize parameter 2 ("m_rate_8")
  259. pi = self->__commonstate.params + 2;
  260. pi->name = "rate";
  261. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  262. pi->defaultvalue = self->m_rate_8;
  263. pi->defaultref = 0;
  264. pi->hasinputminmax = false;
  265. pi->inputmin = 0;
  266. pi->inputmax = 1;
  267. pi->hasminmax = true;
  268. pi->outputmin = 0.1;
  269. pi->outputmax = 5;
  270. pi->exp = 0;
  271. pi->units = ""; // no units defined
  272. // initialize parameter 3 ("m_depth_9")
  273. pi = self->__commonstate.params + 3;
  274. pi->name = "depth";
  275. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  276. pi->defaultvalue = self->m_depth_9;
  277. pi->defaultref = 0;
  278. pi->hasinputminmax = false;
  279. pi->inputmin = 0;
  280. pi->inputmax = 1;
  281. pi->hasminmax = true;
  282. pi->outputmin = 0.1;
  283. pi->outputmax = 3;
  284. pi->exp = 0;
  285. pi->units = ""; // no units defined
  286. // initialize parameter 4 ("m_time_10")
  287. pi = self->__commonstate.params + 4;
  288. pi->name = "time";
  289. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  290. pi->defaultvalue = self->m_time_10;
  291. pi->defaultref = 0;
  292. pi->hasinputminmax = false;
  293. pi->inputmin = 0;
  294. pi->inputmax = 1;
  295. pi->hasminmax = true;
  296. pi->outputmin = 20;
  297. pi->outputmax = 1000;
  298. pi->exp = 0;
  299. pi->units = ""; // no units defined
  300. // initialize parameter 5 ("m_morph_11")
  301. pi = self->__commonstate.params + 5;
  302. pi->name = "morph";
  303. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  304. pi->defaultvalue = self->m_morph_11;
  305. pi->defaultref = 0;
  306. pi->hasinputminmax = false;
  307. pi->inputmin = 0;
  308. pi->inputmax = 1;
  309. pi->hasminmax = true;
  310. pi->outputmin = 0;
  311. pi->outputmax = 100;
  312. pi->exp = 0;
  313. pi->units = ""; // no units defined
  314. // initialize parameter 6 ("m_tone_12")
  315. pi = self->__commonstate.params + 6;
  316. pi->name = "tone";
  317. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  318. pi->defaultvalue = self->m_tone_12;
  319. pi->defaultref = 0;
  320. pi->hasinputminmax = false;
  321. pi->inputmin = 0;
  322. pi->inputmax = 1;
  323. pi->hasminmax = true;
  324. pi->outputmin = 500;
  325. pi->outputmax = 6000;
  326. pi->exp = 0;
  327. pi->units = ""; // no units defined
  328. return self;
  329. }
  330. /// Release all resources and memory used by a State object:
  331. void destroy(CommonState *cself) {
  332. State * self = (State *)cself;
  333. genlib_sysmem_freeptr(cself->params);
  334. delete self;
  335. }
  336. } // gen_exported::