libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmDspPgmKrChain2.c 14KB

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