libcm is a C development framework with an emphasis on audio signal processing applications.
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.

cmDspPgmKrChain2.c 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmFloatTypes.h"
  4. #include "cmRpt.h"
  5. #include "cmErr.h"
  6. #include "cmCtx.h"
  7. #include "cmMem.h"
  8. #include "cmMallocDebug.h"
  9. #include "cmLinkedHeap.h"
  10. #include "cmText.h"
  11. #include "cmFileSys.h"
  12. #include "cmSymTbl.h"
  13. #include "cmJson.h"
  14. #include "cmPrefs.h"
  15. #include "cmDspValue.h"
  16. #include "cmMsgProtocol.h"
  17. #include "cmThread.h"
  18. #include "cmUdpPort.h"
  19. #include "cmUdpNet.h"
  20. #include "cmSerialPort.h"
  21. #include "cmTime.h"
  22. #include "cmAudioSys.h"
  23. #include "cmProcObj.h"
  24. #include "cmDspCtx.h"
  25. #include "cmDspClass.h"
  26. #include "cmDspSys.h"
  27. #include "cmDspPgm.h"
  28. #include "cmAudioFile.h"
  29. #include "cmProcObj.h"
  30. #include "cmProc.h"
  31. #include "cmProc3.h"
  32. #include "cmVectOpsTemplateMain.h"
  33. #include "cmVectOps.h"
  34. #include "cmDspPgmKrChain.h"
  35. #undef KR2
  36. cmDspRC_t krLoadRsrc(cmDspSysH_t h, cmErr_t* err, krRsrc_t* r)
  37. {
  38. cmDspRC_t rc;
  39. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  40. return rc;
  41. cmDspRsrcString(h,&r->tlFn, "timeLineFn", NULL);
  42. cmDspRsrcString(h,&r->tlPrefixPath,"tlPrefixPath", NULL);
  43. cmDspRsrcString(h,&r->scFn, "scoreFn", NULL);
  44. cmDspRsrcString(h,&r->tksbFn, "tksbFn", NULL);
  45. cmDspRsrcString(h,&r->modFn, "modFn", NULL);
  46. cmDspRsrcString(h,&r->measFn, "measFn", NULL);
  47. cmDspRsrcString(h,&r->recordDir, "recordDir", NULL);
  48. cmDspRsrcString(h,&r->midiDevice, "midiDevice", NULL);
  49. cmDspRsrcString(h,&r->midiOutPort, "midiOutPort", NULL);
  50. cmDspRsrcString(h,&r->midiOutPort2,"midiOutPort2", NULL);
  51. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  52. cmErrMsg(err,rc,"A KR DSP resource load failed.");
  53. return rc;
  54. }
  55. const cmChar_t* _mlbl(const cmChar_t* prefix, unsigned ch )
  56. {
  57. static char s[128];
  58. s[127]=0;
  59. snprintf(s,127,"%s%i",prefix,ch);
  60. return s;
  61. }
  62. #define mlbl(a) _mlbl(a,mch)
  63. #define lbl(a) cmDspSysPrintLabel(a,ach)
  64. void _cmDspSys_TlXformChain( cmDspSysH_t h, cmDspTlXform_t* c, unsigned preGrpSymId, unsigned cmpPreGrpSymId, cmDspInst_t* amp, cmDspInst_t* modp, unsigned ach, unsigned mch )
  65. {
  66. int krWndSmpCnt = 2048;
  67. int krHopFact = 4;
  68. unsigned xfadeChCnt = 2;
  69. double xfadeMs = 50;
  70. bool xfadeInitFl = true;
  71. double mixGain = 1.0;
  72. bool cmpBypassFl = false;
  73. double cmpInGain = 3.0;
  74. double cmpThreshDb = -40.0;
  75. double cmpRatio_num = 5.0;
  76. double cmpAtkMs = 20.0;
  77. double cmpRlsMs = 100.0;
  78. double cmpMakeup = 1.0;
  79. double cmpWndMaxMs = 1000.0;
  80. double cmpWndMs = 200.0;
  81. cmDspInst_t* achan = cmDspSysAllocInst(h, "AvailCh", NULL, 1, xfadeChCnt );
  82. // Parameter-> kr routers (routers used to cross-fade between the two kr units)
  83. unsigned paramRtChCnt = 2;
  84. cmDspInst_t* wnd_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  85. cmDspInst_t* hop_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  86. cmDspInst_t* ign_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  87. cmDspInst_t* cel_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  88. cmDspInst_t* exp_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  89. cmDspInst_t* mix_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  90. cmDspInst_t* thr_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  91. cmDspInst_t* upr_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  92. cmDspInst_t* lwr_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  93. cmDspInst_t* wet_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  94. // Audio processors
  95. cmDspInst_t* kr0 = cmDspSysAllocInst(h, "Kr2", NULL, 2, krWndSmpCnt, krHopFact );
  96. cmDspInst_t* kr1 = cmDspSysAllocInst(h, "Kr2", NULL, 2, krWndSmpCnt, krHopFact );
  97. cmDspInst_t* xfad = cmDspSysAllocInst(h, "Xfader", NULL, 3, xfadeChCnt, xfadeMs, xfadeInitFl );
  98. cmDspInst_t* mix = cmDspSysAllocInst(h, "AMix", NULL, 3, xfadeChCnt, mixGain, mixGain );
  99. cmDspInst_t* cmp = cmDspSysAllocInst(h, "Compressor", NULL, 8, cmpBypassFl, cmpThreshDb, cmpRatio_num, cmpAtkMs, cmpRlsMs, cmpMakeup, cmpWndMs, cmpWndMaxMs );
  100. // Internal audio connections
  101. cmDspSysConnectAudio(h, kr0, "out", xfad, "in-0");
  102. cmDspSysConnectAudio(h, kr1, "out", xfad, "in-1");
  103. cmDspSysConnectAudio(h, xfad, "out-0", mix, "in-0");
  104. cmDspSysConnectAudio(h, xfad, "out-1", mix, "in-1");
  105. cmDspSysConnectAudio(h, mix, "out", cmp, "in" );
  106. // active channel <-> cross-fade connections
  107. cmDspSysInstallCb(h, achan, "reset", xfad, "reset", NULL);
  108. cmDspSysInstallCb(h, achan, "gate-0", xfad, "gate-0", NULL );
  109. cmDspSysInstallCb(h, achan, "gate-1", xfad, "gate-1", NULL );
  110. cmDspSysInstallCb(h, xfad, "state-0", achan, "dis-0", NULL );
  111. cmDspSysInstallCb(h, xfad, "state-1", achan, "dis-1", NULL );
  112. // Measurement Number Controls
  113. cmDspInst_t* val_dynm_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Dynm Meas"), 0.0, 10.0, 1.0, 1.0);
  114. cmDspInst_t* val_even_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Even Meas"), 0.0, 3.0, 0.001, 0.5);
  115. cmDspInst_t* val_tmpo_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Tempo Meas"), 0.0, 200.0, 1.0, 100.0);
  116. cmDspInst_t* val_cost_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Cost Meas"), 0.0, 1.0, 0.01, 0.5);
  117. // active measure to measurement UI controls
  118. cmDspSysInstallCb(h, amp, "dyn", val_dynm_ctl, "val", NULL );
  119. cmDspSysInstallCb(h, amp, "even", val_even_ctl, "val", NULL );
  120. cmDspSysInstallCb(h, amp, "tempo", val_tmpo_ctl, "val", NULL );
  121. cmDspSysInstallCb(h, amp, "cost", val_cost_ctl, "val", NULL );
  122. // measurement UI controls to scMod
  123. cmDspSysInstallCb(h, val_dynm_ctl, "val", modp, "dyn", NULL );
  124. cmDspSysInstallCb(h, val_even_ctl, "val", modp, "even", NULL );
  125. cmDspSysInstallCb(h, val_tmpo_ctl, "val", modp, "tempo", NULL );
  126. cmDspSysInstallCb(h, val_cost_ctl, "val", modp, "cost", NULL );
  127. // Parameter number controls
  128. cmDspSysNewColumn(h,0);
  129. cmDspInst_t* wnd_ctl = cmDspSysAllocMsgListP(h,preGrpSymId,NULL, lbl("WndSmpCnt"), NULL, "wndSmpCnt", 2);
  130. cmDspInst_t* hop_ctl = cmDspSysAllocMsgListP(h,preGrpSymId,NULL, lbl("HopFact"), NULL, "hopFact", 2);
  131. cmDspInst_t* ign_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("In Gain"), 0.0, 10.0, 0.001, 1.0 );
  132. cmDspInst_t* cel_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Ceiling"), 0.0, 100.0, 0.1, 30.0 );
  133. cmDspInst_t* exp_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Expo"), -10.0, 10.0, 0.01, 2.0 );
  134. cmDspInst_t* mix_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Mix"), 0.0, 1.0, 0.01, 0.0 );
  135. cmDspInst_t* thr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Threshold"), 0.0, 100.0, 1.0, 60.0 );
  136. cmDspInst_t* upr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Upr slope"), 0.0, 10.0, 0.01, 0.0 );
  137. cmDspInst_t* lwr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Lwr slope"), 0.3, 10.0, 0.01, 2.0 );
  138. cmDspInst_t* wet_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Wet Dry"), 0.0, 1.0, 0.001, 1.0 );
  139. cmDspSysInstallCb(h, wnd_ctl, "out", wnd_rt, "f-in", NULL );
  140. cmDspSysInstallCb(h, achan, "ch", wnd_rt, "sel", NULL ); // ach->rt sel
  141. cmDspSysInstallCb(h, wnd_rt, "f-out-0", kr0, "wndn", NULL ); // wndn->kr
  142. cmDspSysInstallCb(h, wnd_rt, "f-out-1", kr1, "wndn", NULL ); // wndn->kr
  143. cmDspSysInstallCb(h, hop_ctl, "out", hop_rt, "f-in", NULL );
  144. cmDspSysInstallCb(h, achan, "ch", hop_rt, "sel", NULL ); // ach->rt sel
  145. cmDspSysInstallCb(h, hop_rt, "f-out-0", kr0, "hopf", NULL ); // hopf->kr
  146. cmDspSysInstallCb(h, hop_rt, "f-out-1", kr1, "hopf", NULL ); // hopf->kr
  147. cmDspSysInstallCb(h, ign_ctl, "val", ign_rt, "f-in", NULL );
  148. cmDspSysInstallCb(h, achan, "ch", ign_rt, "sel", NULL ); // ach->rt sel
  149. cmDspSysInstallCb(h, ign_rt, "f-out-0", kr0, "igain", NULL ); // ign->kr
  150. cmDspSysInstallCb(h, ign_rt, "f-out-1", kr1, "igain", NULL ); // ign->kr
  151. cmDspSysInstallCb(h, thr_ctl, "val", thr_rt, "f-in", NULL );
  152. cmDspSysInstallCb(h, achan, "ch", thr_rt, "sel", NULL ); // ach->rt sel
  153. cmDspSysInstallCb(h, thr_rt, "f-out-0", kr0, "thrh", NULL ); // thr->kr
  154. cmDspSysInstallCb(h, thr_rt, "f-out-1", kr1, "thrh", NULL ); // thr->kr
  155. cmDspSysInstallCb(h, upr_ctl, "val", upr_rt, "f-in", NULL );
  156. cmDspSysInstallCb(h, achan, "ch", upr_rt, "sel", NULL ); // ach->rt sel
  157. cmDspSysInstallCb(h, upr_rt, "f-out-0", kr0, "uprs", NULL ); // upr->kr
  158. cmDspSysInstallCb(h, upr_rt, "f-out-1", kr1, "uprs", NULL ); // upr->kr
  159. cmDspSysInstallCb(h, lwr_ctl, "val", lwr_rt, "f-in", NULL );
  160. cmDspSysInstallCb(h, achan, "ch", lwr_rt, "sel", NULL ); // ach->rt sel
  161. cmDspSysInstallCb(h, lwr_rt, "f-out-0", kr0, "lwrs", NULL ); // lwr->kr
  162. cmDspSysInstallCb(h, lwr_rt, "f-out-1", kr1, "lwrs", NULL ); // lwr->kr
  163. cmDspSysInstallCb(h, wet_ctl, "val", wet_rt, "f-in", NULL );
  164. cmDspSysInstallCb(h, achan, "ch", wet_rt, "sel", NULL ); // ach->rt sel
  165. cmDspSysInstallCb(h, wet_rt, "f-out-0", kr0, "wet", NULL ); // wet->kr
  166. cmDspSysInstallCb(h, wet_rt, "f-out-1", kr1, "wet", NULL ); // wet->kr
  167. cmDspSysInstallCb(h, cel_ctl, "val", cel_rt, "f-in", NULL );
  168. cmDspSysInstallCb(h, achan, "ch", cel_rt, "sel", NULL ); // ach->rt sel
  169. cmDspSysInstallCb(h, cel_rt, "f-out-0", kr0, "ceil", NULL ); // cel->kr
  170. cmDspSysInstallCb(h, cel_rt, "f-out-1", kr1, "ceil", NULL ); // cel->kr
  171. cmDspSysInstallCb(h, exp_ctl, "val", exp_rt, "f-in", NULL );
  172. cmDspSysInstallCb(h, achan, "ch", exp_rt, "sel", NULL ); // ach->rt sel
  173. cmDspSysInstallCb(h, exp_rt, "f-out-0", kr0, "expo", NULL ); // exp->kr
  174. cmDspSysInstallCb(h, exp_rt, "f-out-1", kr1, "expo", NULL ); // exp->kr
  175. cmDspSysInstallCb(h, mix_ctl, "val", mix_rt, "f-in", NULL );
  176. cmDspSysInstallCb(h, achan, "ch", mix_rt, "sel", NULL ); // ach->rt sel
  177. cmDspSysInstallCb(h, mix_rt, "f-out-0", kr0, "mix", NULL ); // mix->kr
  178. cmDspSysInstallCb(h, mix_rt, "f-out-1", kr1, "mix", NULL ); // mix->kr
  179. cmDspSysNewColumn(h,0);
  180. cmDspInst_t* cmp_byp = cmDspSysAllocCheckP( h, cmpPreGrpSymId, NULL, lbl("Bypass"), 1.0 );
  181. cmDspInst_t* cmp_igain = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("In Gain"), 0.0, 10.0, 0.1, cmpInGain);
  182. cmDspInst_t* cmp_thr = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("ThreshDb"), -100.0, 0.0, 0.1, cmpThreshDb);
  183. cmDspInst_t* cmp_rat = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Ratio"), 0.1, 100, 0.1, cmpRatio_num);
  184. cmDspInst_t* cmp_atk = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Atk Ms"), 0.0, 1000.0, 0.1, cmpAtkMs);
  185. cmDspInst_t* cmp_rls = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Rls Ms"), 0.0, 1000.0, 0.1, cmpRlsMs);
  186. cmDspInst_t* cmp_mkup = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Makeup"), 0.0, 10.0, 0.01, cmpMakeup);
  187. cmDspInst_t* cmp_wnd = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Wnd Ms"), 1.0, cmpWndMaxMs, 1.0, cmpWndMs );
  188. cmDspInst_t* cmp_mtr = cmDspSysAllocInst(h,"Meter",lbl("Env"), 3, 0.0, 0.0, 1.0);
  189. cmDspSysInstallCb(h, cmp_byp, "out", cmp, "bypass", NULL );
  190. cmDspSysInstallCb(h, cmp_igain,"val", cmp, "igain", NULL );
  191. cmDspSysInstallCb(h, cmp_thr, "val", cmp, "thr", NULL );
  192. cmDspSysInstallCb(h, cmp_rat, "val", cmp, "ratio", NULL );
  193. cmDspSysInstallCb(h, cmp_atk, "val", cmp, "atk", NULL );
  194. cmDspSysInstallCb(h, cmp_rls, "val", cmp, "rls", NULL );
  195. cmDspSysInstallCb(h, cmp_mkup, "val", cmp, "ogain", NULL );
  196. cmDspSysInstallCb(h, cmp_wnd, "val", cmp, "wnd", NULL );
  197. cmDspSysInstallCb(h, cmp, "env", cmp_mtr, "in", NULL );
  198. cmDspSysInstallCb(h, modp, mlbl("cbyp"), cmp_byp, "in", NULL );
  199. cmDspSysInstallCb(h, modp, mlbl("cigain"), cmp_igain,"val", NULL );
  200. cmDspSysInstallCb(h, modp, mlbl("cthrsh"), cmp_thr, "val", NULL );
  201. cmDspSysInstallCb(h, modp, mlbl("cratio"), cmp_rat, "val", NULL );
  202. cmDspSysInstallCb(h, modp, mlbl("catkms"), cmp_atk, "val", NULL );
  203. cmDspSysInstallCb(h, modp, mlbl("crlsms"), cmp_rls, "val", NULL );
  204. cmDspSysInstallCb(h, modp, mlbl("cmakeup"), cmp_mkup, "val", NULL );
  205. cmDspSysInstallCb(h, modp, mlbl("cwndms"), cmp_wnd, "val", NULL );
  206. //
  207. cmDspInst_t* xfadMs = cmDspSysAllocInst(h,"Scalar", lbl("Xfade Ms"), 5, kNumberDuiId, 0.0, 1000.0,0.01, 50.0 );
  208. cmDspSysInstallCb(h, xfadMs, "val", xfad, "ms", NULL );
  209. cmDspSysInstallCb(h, modp, mlbl("xfad"), xfadMs, "val", NULL);
  210. //cmDspInst_t* sw_btn = cmDspSysAllocButton( h, lbl("switch"), 0);
  211. //cmDspSysInstallCb( h, sw_btn, "sym", achan, "trig", NULL );
  212. // TODO: FIX THIS: can't send window length (e.g. 1024,2048, ... ) to a 'MsgList' with 4 elements
  213. // since it expects an index betweeen 0 and 3. CRASH!
  214. //cmDspSysInstallCb(h, modp, mlbl("win"), wnd_ctl, "sel", NULL );
  215. cmDspSysInstallCb(h, modp, mlbl("hop"), hop_ctl, "sel", NULL );
  216. cmDspSysInstallCb(h, modp, mlbl("ign"), ign_ctl, "val", NULL );
  217. cmDspSysInstallCb(h, modp, mlbl("ceil"), cel_ctl, "val", NULL );
  218. cmDspSysInstallCb(h, modp, mlbl("expo"), exp_ctl, "val", NULL );
  219. cmDspSysInstallCb(h, modp, mlbl("mix"), mix_ctl, "val", NULL );
  220. cmDspSysInstallCb(h, modp, mlbl("thr"), thr_ctl, "val", NULL );
  221. cmDspSysInstallCb(h, modp, mlbl("upr"), upr_ctl, "val", NULL );
  222. cmDspSysInstallCb(h, modp, mlbl("lwr"), lwr_ctl, "val", NULL );
  223. cmDspSysInstallCb(h, modp, mlbl("wet"), wet_ctl, "val", NULL );
  224. cmDspSysInstallCb(h, modp, mlbl("sw"), achan, "trig", NULL ); // See also: amp.sfloc->achan.trig
  225. c->achan = achan;
  226. c->kr0 = kr0;
  227. c->kr1 = kr1;
  228. c->cmp = cmp;
  229. }