DPF with Max Gen
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.

486 lines
16KB

  1. #include "gen_exported.h"
  2. namespace gen_exported {
  3. /*******************************************************************************************************************
  4. Cycling '74 License for Max-Generated Code for Export
  5. Copyright (c) 2016 Cycling '74
  6. The code that Max generates automatically and that end users are capable of exporting and using, and any
  7. associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author
  8. and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a
  9. copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software,
  10. and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the
  12. Software must contact the copyright owner to determine if a license for commercial use is available, and the
  13. terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries
  14. to licensing (at) cycling74.com. The determination of whether a use is commercial use or non-commercial use is based
  15. upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or
  16. other business whether for-profit or non-profit so long as the use itself is not a commercialization of the
  17. materials or a use that generates or is intended to generate income, revenue, sales or profit.
  18. The above copyright notice and this license shall be included in all copies or substantial portions of the Software.
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  20. THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  22. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. DEALINGS IN THE SOFTWARE.
  24. *******************************************************************************************************************/
  25. // global noise generator
  26. Noise noise;
  27. static const int GENLIB_LOOPCOUNT_BAIL = 100000;
  28. // The State struct contains all the state and procedures for the gendsp kernel
  29. typedef struct State {
  30. CommonState __commonstate;
  31. Delay m_delay_24;
  32. Delay m_delay_15;
  33. Delay m_delay_13;
  34. Delay m_delay_23;
  35. Delay m_delay_9;
  36. Delay m_delay_17;
  37. Delay m_delay_21;
  38. Delay m_delay_19;
  39. Delay m_delay_22;
  40. Delay m_delay_7;
  41. Delay m_delay_11;
  42. Delay m_delay_5;
  43. int vectorsize;
  44. int __exception;
  45. t_sample m_fb_1;
  46. t_sample m_history_20;
  47. t_sample samplerate;
  48. t_sample m_history_18;
  49. t_sample m_spread_2;
  50. t_sample m_history_16;
  51. t_sample m_damp_3;
  52. t_sample m_history_10;
  53. t_sample m_history_8;
  54. t_sample m_history_12;
  55. t_sample m_history_14;
  56. t_sample m_fb_4;
  57. t_sample m_history_6;
  58. // re-initialize all member variables;
  59. inline void reset(t_param __sr, int __vs) {
  60. __exception = 0;
  61. vectorsize = __vs;
  62. samplerate = __sr;
  63. m_fb_1 = 0.5;
  64. m_spread_2 = 0;
  65. m_damp_3 = 0.5;
  66. m_fb_4 = 0.9;
  67. m_delay_5.reset("m_delay_5", 2000);
  68. m_history_6 = 0;
  69. m_delay_7.reset("m_delay_7", 2000);
  70. m_history_8 = 0;
  71. m_delay_9.reset("m_delay_9", 2000);
  72. m_history_10 = 0;
  73. m_delay_11.reset("m_delay_11", 2000);
  74. m_history_12 = 0;
  75. m_delay_13.reset("m_delay_13", 2000);
  76. m_history_14 = 0;
  77. m_delay_15.reset("m_delay_15", 2000);
  78. m_history_16 = 0;
  79. m_delay_17.reset("m_delay_17", 2000);
  80. m_history_18 = 0;
  81. m_delay_19.reset("m_delay_19", 2000);
  82. m_history_20 = 0;
  83. m_delay_21.reset("m_delay_21", 2000);
  84. m_delay_22.reset("m_delay_22", 2000);
  85. m_delay_23.reset("m_delay_23", 2000);
  86. m_delay_24.reset("m_delay_24", 2000);
  87. genlib_reset_complete(this);
  88. };
  89. // the signal processing routine;
  90. inline int perform(t_sample ** __ins, t_sample ** __outs, int __n) {
  91. vectorsize = __n;
  92. const t_sample * __in1 = __ins[0];
  93. t_sample * __out1 = __outs[0];
  94. if (__exception) {
  95. return __exception;
  96. } else if (( (__in1 == 0) || (__out1 == 0) )) {
  97. __exception = GENLIB_ERR_NULL_BUFFER;
  98. return __exception;
  99. };
  100. t_sample mul_408 = (m_fb_1 * 0.5);
  101. t_sample add_394 = (225 + m_spread_2);
  102. t_sample add_396 = (341 + m_spread_2);
  103. t_sample add_406 = (441 + m_spread_2);
  104. t_sample add_392 = (556 + m_spread_2);
  105. t_sample damp_378 = m_damp_3;
  106. t_sample damp_377 = damp_378;
  107. t_sample damp_376 = damp_378;
  108. t_sample damp_379 = damp_378;
  109. t_sample damp_380 = damp_378;
  110. t_sample damp_381 = damp_378;
  111. t_sample damp_382 = damp_378;
  112. t_sample damp_383 = damp_378;
  113. t_sample add_399 = (1557 + m_spread_2);
  114. t_sample rsub_345 = (1 - damp_377);
  115. t_sample add_398 = (1617 + m_spread_2);
  116. t_sample rsub_525 = (1 - damp_376);
  117. t_sample add_400 = (1491 + m_spread_2);
  118. t_sample rsub_537 = (1 - damp_378);
  119. t_sample add_401 = (1422 + m_spread_2);
  120. t_sample rsub_549 = (1 - damp_379);
  121. t_sample add_402 = (1356 + m_spread_2);
  122. t_sample rsub_561 = (1 - damp_380);
  123. t_sample add_403 = (1277 + m_spread_2);
  124. t_sample rsub_573 = (1 - damp_381);
  125. t_sample add_404 = (1188 + m_spread_2);
  126. t_sample rsub_585 = (1 - damp_382);
  127. t_sample add_405 = (1116 + m_spread_2);
  128. t_sample rsub_597 = (1 - damp_383);
  129. // the main sample loop;
  130. while ((__n--)) {
  131. const t_sample in1 = (*(__in1++));
  132. t_sample mul_419 = (in1 * 0.015);
  133. t_sample tap_352 = m_delay_5.read_linear(add_399);
  134. t_sample gen_390 = tap_352;
  135. t_sample mul_350 = (tap_352 * damp_377);
  136. t_sample mul_348 = (m_history_6 * rsub_345);
  137. t_sample add_349 = (mul_350 + mul_348);
  138. t_sample mul_346 = (add_349 * m_fb_4);
  139. t_sample add_353 = (mul_419 + mul_346);
  140. t_sample history_347_next_354 = fixdenorm(add_349);
  141. t_sample tap_533 = m_delay_7.read_linear(add_398);
  142. t_sample gen_418 = tap_533;
  143. t_sample mul_528 = (tap_533 * damp_376);
  144. t_sample mul_530 = (m_history_8 * rsub_525);
  145. t_sample add_527 = (mul_528 + mul_530);
  146. t_sample mul_529 = (add_527 * m_fb_4);
  147. t_sample add_532 = (mul_419 + mul_529);
  148. t_sample history_347_next_531 = fixdenorm(add_527);
  149. t_sample tap_545 = m_delay_9.read_linear(add_400);
  150. t_sample gen_389 = tap_545;
  151. t_sample mul_540 = (tap_545 * damp_378);
  152. t_sample mul_542 = (m_history_10 * rsub_537);
  153. t_sample add_539 = (mul_540 + mul_542);
  154. t_sample mul_541 = (add_539 * m_fb_4);
  155. t_sample add_544 = (mul_419 + mul_541);
  156. t_sample history_347_next_543 = fixdenorm(add_539);
  157. t_sample tap_558 = m_delay_11.read_linear(add_401);
  158. t_sample gen_388 = tap_558;
  159. t_sample mul_556 = (tap_558 * damp_379);
  160. t_sample mul_557 = (m_history_12 * rsub_549);
  161. t_sample add_554 = (mul_556 + mul_557);
  162. t_sample mul_551 = (add_554 * m_fb_4);
  163. t_sample add_555 = (mul_419 + mul_551);
  164. t_sample history_347_next_552 = fixdenorm(add_554);
  165. t_sample tap_568 = m_delay_13.read_linear(add_402);
  166. t_sample gen_387 = tap_568;
  167. t_sample mul_567 = (tap_568 * damp_380);
  168. t_sample mul_569 = (m_history_14 * rsub_561);
  169. t_sample add_565 = (mul_567 + mul_569);
  170. t_sample mul_563 = (add_565 * m_fb_4);
  171. t_sample add_566 = (mul_419 + mul_563);
  172. t_sample history_347_next_570 = fixdenorm(add_565);
  173. t_sample tap_581 = m_delay_15.read_linear(add_403);
  174. t_sample gen_386 = tap_581;
  175. t_sample mul_580 = (tap_581 * damp_381);
  176. t_sample mul_582 = (m_history_16 * rsub_573);
  177. t_sample add_578 = (mul_580 + mul_582);
  178. t_sample mul_575 = (add_578 * m_fb_4);
  179. t_sample add_579 = (mul_419 + mul_575);
  180. t_sample history_347_next_576 = fixdenorm(add_578);
  181. t_sample tap_594 = m_delay_17.read_linear(add_404);
  182. t_sample gen_385 = tap_594;
  183. t_sample mul_591 = (tap_594 * damp_382);
  184. t_sample mul_592 = (m_history_18 * rsub_585);
  185. t_sample add_589 = (mul_591 + mul_592);
  186. t_sample mul_587 = (add_589 * m_fb_4);
  187. t_sample add_590 = (mul_419 + mul_587);
  188. t_sample history_347_next_593 = fixdenorm(add_589);
  189. t_sample tap_605 = m_delay_19.read_linear(add_405);
  190. t_sample gen_384 = tap_605;
  191. t_sample mul_604 = (tap_605 * damp_383);
  192. t_sample mul_606 = (m_history_20 * rsub_597);
  193. t_sample add_602 = (mul_604 + mul_606);
  194. t_sample mul_599 = (add_602 * m_fb_4);
  195. t_sample add_603 = (mul_419 + mul_599);
  196. t_sample history_347_next_600 = fixdenorm(add_602);
  197. t_sample add_407 = ((((((((gen_384 + gen_385) + gen_386) + gen_387) + gen_388) + gen_389) + gen_418) + gen_390) + 0);
  198. t_sample tap_343 = m_delay_21.read_linear(add_392);
  199. t_sample sub_339 = (add_407 - tap_343);
  200. t_sample mul_341 = (tap_343 * mul_408);
  201. t_sample add_340 = (add_407 + mul_341);
  202. t_sample tap_612 = m_delay_22.read_linear(add_406);
  203. t_sample sub_611 = (sub_339 - tap_612);
  204. t_sample mul_609 = (tap_612 * mul_408);
  205. t_sample add_610 = (sub_339 + mul_609);
  206. t_sample tap_618 = m_delay_23.read_linear(add_396);
  207. t_sample sub_617 = (sub_611 - tap_618);
  208. t_sample mul_615 = (tap_618 * mul_408);
  209. t_sample add_616 = (sub_611 + mul_615);
  210. t_sample tap_624 = m_delay_24.read_linear(add_394);
  211. t_sample sub_623 = (sub_617 - tap_624);
  212. t_sample mul_621 = (tap_624 * mul_408);
  213. t_sample add_622 = (sub_617 + mul_621);
  214. t_sample out1 = sub_623;
  215. m_delay_5.write(add_353);
  216. m_delay_24.write(add_622);
  217. m_delay_23.write(add_616);
  218. m_delay_22.write(add_610);
  219. m_delay_21.write(add_340);
  220. m_history_20 = history_347_next_600;
  221. m_delay_19.write(add_603);
  222. m_history_18 = history_347_next_593;
  223. m_delay_17.write(add_590);
  224. m_history_16 = history_347_next_576;
  225. m_delay_15.write(add_579);
  226. m_history_14 = history_347_next_570;
  227. m_delay_13.write(add_566);
  228. m_history_12 = history_347_next_552;
  229. m_delay_11.write(add_555);
  230. m_history_10 = history_347_next_543;
  231. m_delay_9.write(add_544);
  232. m_history_8 = history_347_next_531;
  233. m_delay_7.write(add_532);
  234. m_history_6 = history_347_next_354;
  235. m_delay_5.step();
  236. m_delay_7.step();
  237. m_delay_9.step();
  238. m_delay_11.step();
  239. m_delay_13.step();
  240. m_delay_15.step();
  241. m_delay_17.step();
  242. m_delay_19.step();
  243. m_delay_21.step();
  244. m_delay_22.step();
  245. m_delay_23.step();
  246. m_delay_24.step();
  247. // assign results to output buffer;
  248. (*(__out1++)) = out1;
  249. };
  250. return __exception;
  251. };
  252. inline void set_fb2(t_param _value) {
  253. m_fb_1 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
  254. };
  255. inline void set_spread(t_param _value) {
  256. m_spread_2 = (_value < 0 ? 0 : (_value > 400 ? 400 : _value));
  257. };
  258. inline void set_damp(t_param _value) {
  259. m_damp_3 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
  260. };
  261. inline void set_fb1(t_param _value) {
  262. m_fb_4 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
  263. };
  264. } State;
  265. ///
  266. /// Configuration for the genlib API
  267. ///
  268. /// Number of signal inputs and outputs
  269. int gen_kernel_numins = 1;
  270. int gen_kernel_numouts = 1;
  271. int num_inputs() { return gen_kernel_numins; }
  272. int num_outputs() { return gen_kernel_numouts; }
  273. int num_params() { return 4; }
  274. /// Assistive lables for the signal inputs and outputs
  275. const char *gen_kernel_innames[] = { "in1" };
  276. const char *gen_kernel_outnames[] = { "out1" };
  277. /// Invoke the signal process of a State object
  278. int perform(CommonState *cself, t_sample **ins, long numins, t_sample **outs, long numouts, long n) {
  279. State* self = (State *)cself;
  280. return self->perform(ins, outs, n);
  281. }
  282. /// Reset all parameters and stateful operators of a State object
  283. void reset(CommonState *cself) {
  284. State* self = (State *)cself;
  285. self->reset(cself->sr, cself->vs);
  286. }
  287. /// Set a parameter of a State object
  288. void setparameter(CommonState *cself, long index, t_param value, void *ref) {
  289. State *self = (State *)cself;
  290. switch (index) {
  291. case 0: self->set_damp(value); break;
  292. case 1: self->set_fb1(value); break;
  293. case 2: self->set_fb2(value); break;
  294. case 3: self->set_spread(value); break;
  295. default: break;
  296. }
  297. }
  298. /// Get the value of a parameter of a State object
  299. void getparameter(CommonState *cself, long index, t_param *value) {
  300. State *self = (State *)cself;
  301. switch (index) {
  302. case 0: *value = self->m_damp_3; break;
  303. case 1: *value = self->m_fb_4; break;
  304. case 2: *value = self->m_fb_1; break;
  305. case 3: *value = self->m_spread_2; break;
  306. default: break;
  307. }
  308. }
  309. /// Get the name of a parameter of a State object
  310. const char *getparametername(CommonState *cself, long index) {
  311. if (index >= 0 && index < cself->numparams) {
  312. return cself->params[index].name;
  313. }
  314. return 0;
  315. }
  316. /// Get the minimum value of a parameter of a State object
  317. t_param getparametermin(CommonState *cself, long index) {
  318. if (index >= 0 && index < cself->numparams) {
  319. return cself->params[index].outputmin;
  320. }
  321. return 0;
  322. }
  323. /// Get the maximum value of a parameter of a State object
  324. t_param getparametermax(CommonState *cself, long index) {
  325. if (index >= 0 && index < cself->numparams) {
  326. return cself->params[index].outputmax;
  327. }
  328. return 0;
  329. }
  330. /// Get parameter of a State object has a minimum and maximum value
  331. char getparameterhasminmax(CommonState *cself, long index) {
  332. if (index >= 0 && index < cself->numparams) {
  333. return cself->params[index].hasminmax;
  334. }
  335. return 0;
  336. }
  337. /// Get the units of a parameter of a State object
  338. const char *getparameterunits(CommonState *cself, long index) {
  339. if (index >= 0 && index < cself->numparams) {
  340. return cself->params[index].units;
  341. }
  342. return 0;
  343. }
  344. /// Get the size of the state of all parameters of a State object
  345. size_t getstatesize(CommonState *cself) {
  346. return genlib_getstatesize(cself, &getparameter);
  347. }
  348. /// Get the state of all parameters of a State object
  349. short getstate(CommonState *cself, char *state) {
  350. return genlib_getstate(cself, state, &getparameter);
  351. }
  352. /// set the state of all parameters of a State object
  353. short setstate(CommonState *cself, const char *state) {
  354. return genlib_setstate(cself, state, &setparameter);
  355. }
  356. /// Allocate and configure a new State object and it's internal CommonState:
  357. void *create(t_param sr, long vs) {
  358. State *self = new State;
  359. self->reset(sr, vs);
  360. ParamInfo *pi;
  361. self->__commonstate.inputnames = gen_kernel_innames;
  362. self->__commonstate.outputnames = gen_kernel_outnames;
  363. self->__commonstate.numins = gen_kernel_numins;
  364. self->__commonstate.numouts = gen_kernel_numouts;
  365. self->__commonstate.sr = sr;
  366. self->__commonstate.vs = vs;
  367. self->__commonstate.params = (ParamInfo *)genlib_sysmem_newptr(4 * sizeof(ParamInfo));
  368. self->__commonstate.numparams = 4;
  369. // initialize parameter 0 ("m_damp_3")
  370. pi = self->__commonstate.params + 0;
  371. pi->name = "damp";
  372. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  373. pi->defaultvalue = self->m_damp_3;
  374. pi->defaultref = 0;
  375. pi->hasinputminmax = false;
  376. pi->inputmin = 0;
  377. pi->inputmax = 1;
  378. pi->hasminmax = true;
  379. pi->outputmin = 0;
  380. pi->outputmax = 1;
  381. pi->exp = 0;
  382. pi->units = ""; // no units defined
  383. // initialize parameter 1 ("m_fb_4")
  384. pi = self->__commonstate.params + 1;
  385. pi->name = "fb1";
  386. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  387. pi->defaultvalue = self->m_fb_4;
  388. pi->defaultref = 0;
  389. pi->hasinputminmax = false;
  390. pi->inputmin = 0;
  391. pi->inputmax = 1;
  392. pi->hasminmax = true;
  393. pi->outputmin = 0;
  394. pi->outputmax = 1;
  395. pi->exp = 0;
  396. pi->units = ""; // no units defined
  397. // initialize parameter 2 ("m_fb_1")
  398. pi = self->__commonstate.params + 2;
  399. pi->name = "fb2";
  400. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  401. pi->defaultvalue = self->m_fb_1;
  402. pi->defaultref = 0;
  403. pi->hasinputminmax = false;
  404. pi->inputmin = 0;
  405. pi->inputmax = 1;
  406. pi->hasminmax = true;
  407. pi->outputmin = 0;
  408. pi->outputmax = 1;
  409. pi->exp = 0;
  410. pi->units = ""; // no units defined
  411. // initialize parameter 3 ("m_spread_2")
  412. pi = self->__commonstate.params + 3;
  413. pi->name = "spread";
  414. pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
  415. pi->defaultvalue = self->m_spread_2;
  416. pi->defaultref = 0;
  417. pi->hasinputminmax = false;
  418. pi->inputmin = 0;
  419. pi->inputmax = 1;
  420. pi->hasminmax = true;
  421. pi->outputmin = 0;
  422. pi->outputmax = 400;
  423. pi->exp = 0;
  424. pi->units = ""; // no units defined
  425. return self;
  426. }
  427. /// Release all resources and memory used by a State object:
  428. void destroy(CommonState *cself) {
  429. State *self = (State *)cself;
  430. genlib_sysmem_freeptr(cself->params);
  431. delete self;
  432. }
  433. } // gen_exported::