libcm is a C development framework with an emphasis on audio signal processing applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cmDspPgmKrChain2.c 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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* cel_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  87. cmDspInst_t* exp_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  88. cmDspInst_t* mix_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  89. cmDspInst_t* thr_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  90. cmDspInst_t* upr_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  91. cmDspInst_t* lwr_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  92. cmDspInst_t* wet_rt = cmDspSysAllocInst(h, "Router", NULL, 2, paramRtChCnt, paramRtChCnt-1 );
  93. // Audio processors
  94. cmDspInst_t* kr0 = cmDspSysAllocInst(h, "Kr2", NULL, 2, krWndSmpCnt, krHopFact );
  95. cmDspInst_t* kr1 = cmDspSysAllocInst(h, "Kr2", NULL, 2, krWndSmpCnt, krHopFact );
  96. cmDspInst_t* xfad = cmDspSysAllocInst(h, "Xfader", NULL, 3, xfadeChCnt, xfadeMs, xfadeInitFl );
  97. cmDspInst_t* mix = cmDspSysAllocInst(h, "AMix", NULL, 3, xfadeChCnt, mixGain, mixGain );
  98. cmDspInst_t* cmp = cmDspSysAllocInst(h, "Compressor", NULL, 8, cmpBypassFl, cmpThreshDb, cmpRatio_num, cmpAtkMs, cmpRlsMs, cmpMakeup, cmpWndMs, cmpWndMaxMs );
  99. // Internal audio connections
  100. cmDspSysConnectAudio(h, kr0, "out", xfad, "in-0");
  101. cmDspSysConnectAudio(h, kr1, "out", xfad, "in-1");
  102. cmDspSysConnectAudio(h, xfad, "out-0", mix, "in-0");
  103. cmDspSysConnectAudio(h, xfad, "out-1", mix, "in-1");
  104. cmDspSysConnectAudio(h, mix, "out", cmp, "in" );
  105. // active channel <-> cross-fade connections
  106. cmDspSysInstallCb(h, achan, "reset", xfad, "reset", NULL);
  107. cmDspSysInstallCb(h, achan, "gate-0", xfad, "gate-0", NULL );
  108. cmDspSysInstallCb(h, achan, "gate-1", xfad, "gate-1", NULL );
  109. cmDspSysInstallCb(h, xfad, "state-0", achan, "dis-0", NULL );
  110. cmDspSysInstallCb(h, xfad, "state-1", achan, "dis-1", NULL );
  111. // Measurement Number Controls
  112. cmDspInst_t* val_dynm_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Dynm Meas"), 0.0, 10.0, 1.0, 1.0);
  113. cmDspInst_t* val_even_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Even Meas"), 0.0, 3.0, 0.001, 0.5);
  114. cmDspInst_t* val_tmpo_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Tempo Meas"), 0.0, 200.0, 1.0, 100.0);
  115. cmDspInst_t* val_cost_ctl = cmDspSysAllocScalarP( h,preGrpSymId, NULL, lbl("Cost Meas"), 0.0, 1.0, 0.01, 0.5);
  116. // active measure to measurement UI controls
  117. cmDspSysInstallCb(h, amp, "dyn", val_dynm_ctl, "val", NULL );
  118. cmDspSysInstallCb(h, amp, "even", val_even_ctl, "val", NULL );
  119. cmDspSysInstallCb(h, amp, "tempo", val_tmpo_ctl, "val", NULL );
  120. cmDspSysInstallCb(h, amp, "cost", val_cost_ctl, "val", NULL );
  121. // measurement UI controls to scMod
  122. cmDspSysInstallCb(h, val_dynm_ctl, "val", modp, "dyn", NULL );
  123. cmDspSysInstallCb(h, val_even_ctl, "val", modp, "even", NULL );
  124. cmDspSysInstallCb(h, val_tmpo_ctl, "val", modp, "tempo", NULL );
  125. cmDspSysInstallCb(h, val_cost_ctl, "val", modp, "cost", NULL );
  126. // Parameter number controls
  127. cmDspSysNewColumn(h,0);
  128. cmDspInst_t* wnd_ctl = cmDspSysAllocMsgListP(h,preGrpSymId,NULL, lbl("WndSmpCnt"), NULL, "wndSmpCnt", 2);
  129. cmDspInst_t* hop_ctl = cmDspSysAllocMsgListP(h,preGrpSymId,NULL, lbl("HopFact"), NULL, "hopFact", 2);
  130. cmDspInst_t* cel_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Ceiling"), 0.0, 100.0, 0.1, 30.0 );
  131. cmDspInst_t* exp_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Expo"), -10.0, 10.0, 0.01, 2.0 );
  132. cmDspInst_t* mix_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Mix"), 0.0, 1.0, 0.01, 0.0 );
  133. cmDspInst_t* thr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Threshold"), 0.0, 100.0, 1.0, 60.0 );
  134. cmDspInst_t* upr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Upr slope"), 0.0, 10.0, 0.01, 0.0 );
  135. cmDspInst_t* lwr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Lwr slope"), 0.3, 10.0, 0.01, 2.0 );
  136. cmDspInst_t* wet_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Wet Dry"), 0.0, 1.0, 0.001, 1.0 );
  137. cmDspSysInstallCb(h, wnd_ctl, "out", wnd_rt, "f-in", NULL );
  138. cmDspSysInstallCb(h, achan, "ch", wnd_rt, "sel", NULL ); // ach->rt sel
  139. cmDspSysInstallCb(h, wnd_rt, "f-out-0", kr0, "wndn", NULL ); // wndn->kr
  140. cmDspSysInstallCb(h, wnd_rt, "f-out-1", kr1, "wndn", NULL ); // wndn->kr
  141. cmDspSysInstallCb(h, hop_ctl, "out", hop_rt, "f-in", NULL );
  142. cmDspSysInstallCb(h, achan, "ch", hop_rt, "sel", NULL ); // ach->rt sel
  143. cmDspSysInstallCb(h, hop_rt, "f-out-0", kr0, "hopf", NULL ); // hopf->kr
  144. cmDspSysInstallCb(h, hop_rt, "f-out-1", kr1, "hopf", NULL ); // hopf->kr
  145. cmDspSysInstallCb(h, thr_ctl, "val", thr_rt, "f-in", NULL );
  146. cmDspSysInstallCb(h, achan, "ch", thr_rt, "sel", NULL ); // ach->rt sel
  147. cmDspSysInstallCb(h, thr_rt, "f-out-0", kr0, "thrh", NULL ); // thr->kr
  148. cmDspSysInstallCb(h, thr_rt, "f-out-1", kr1, "thrh", NULL ); // thr->kr
  149. cmDspSysInstallCb(h, upr_ctl, "val", upr_rt, "f-in", NULL );
  150. cmDspSysInstallCb(h, achan, "ch", upr_rt, "sel", NULL ); // ach->rt sel
  151. cmDspSysInstallCb(h, upr_rt, "f-out-0", kr0, "uprs", NULL ); // upr->kr
  152. cmDspSysInstallCb(h, upr_rt, "f-out-1", kr1, "uprs", NULL ); // upr->kr
  153. cmDspSysInstallCb(h, lwr_ctl, "val", lwr_rt, "f-in", NULL );
  154. cmDspSysInstallCb(h, achan, "ch", lwr_rt, "sel", NULL ); // ach->rt sel
  155. cmDspSysInstallCb(h, lwr_rt, "f-out-0", kr0, "lwrs", NULL ); // lwr->kr
  156. cmDspSysInstallCb(h, lwr_rt, "f-out-1", kr1, "lwrs", NULL ); // lwr->kr
  157. cmDspSysInstallCb(h, wet_ctl, "val", wet_rt, "f-in", NULL );
  158. cmDspSysInstallCb(h, achan, "ch", wet_rt, "sel", NULL ); // ach->rt sel
  159. cmDspSysInstallCb(h, wet_rt, "f-out-0", kr0, "wet", NULL ); // wet->kr
  160. cmDspSysInstallCb(h, wet_rt, "f-out-1", kr1, "wet", NULL ); // wet->kr
  161. cmDspSysInstallCb(h, cel_ctl, "val", cel_rt, "f-in", NULL );
  162. cmDspSysInstallCb(h, achan, "ch", cel_rt, "sel", NULL ); // ach->rt sel
  163. cmDspSysInstallCb(h, cel_rt, "f-out-0", kr0, "ceil", NULL ); // cel->kr
  164. cmDspSysInstallCb(h, cel_rt, "f-out-1", kr1, "ceil", NULL ); // cel->kr
  165. cmDspSysInstallCb(h, exp_ctl, "val", exp_rt, "f-in", NULL );
  166. cmDspSysInstallCb(h, achan, "ch", exp_rt, "sel", NULL ); // ach->rt sel
  167. cmDspSysInstallCb(h, exp_rt, "f-out-0", kr0, "expo", NULL ); // exp->kr
  168. cmDspSysInstallCb(h, exp_rt, "f-out-1", kr1, "expo", NULL ); // exp->kr
  169. cmDspSysInstallCb(h, mix_ctl, "val", mix_rt, "f-in", NULL );
  170. cmDspSysInstallCb(h, achan, "ch", mix_rt, "sel", NULL ); // ach->rt sel
  171. cmDspSysInstallCb(h, mix_rt, "f-out-0", kr0, "mix", NULL ); // mix->kr
  172. cmDspSysInstallCb(h, mix_rt, "f-out-1", kr1, "mix", NULL ); // mix->kr
  173. cmDspSysNewColumn(h,0);
  174. cmDspInst_t* cmp_byp = cmDspSysAllocCheckP( h, cmpPreGrpSymId, NULL, lbl("Bypass"), 1.0 );
  175. cmDspInst_t* cmp_igain = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("In Gain"), 0.0, 10.0, 0.1, cmpInGain);
  176. cmDspInst_t* cmp_thr = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("ThreshDb"), -100.0, 0.0, 0.1, cmpThreshDb);
  177. cmDspInst_t* cmp_rat = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Ratio"), 0.1, 100, 0.1, cmpRatio_num);
  178. cmDspInst_t* cmp_atk = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Atk Ms"), 0.0, 1000.0, 0.1, cmpAtkMs);
  179. cmDspInst_t* cmp_rls = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Rls Ms"), 0.0, 1000.0, 0.1, cmpRlsMs);
  180. cmDspInst_t* cmp_mkup = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Makeup"), 0.0, 10.0, 0.01, cmpMakeup);
  181. cmDspInst_t* cmp_wnd = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Wnd Ms"), 1.0, cmpWndMaxMs, 1.0, cmpWndMs );
  182. cmDspInst_t* cmp_mtr = cmDspSysAllocInst(h,"Meter",lbl("Env"), 3, 0.0, 0.0, 1.0);
  183. cmDspSysInstallCb(h, cmp_byp, "out", cmp, "bypass", NULL );
  184. cmDspSysInstallCb(h, cmp_igain,"val", cmp, "igain", NULL );
  185. cmDspSysInstallCb(h, cmp_thr, "val", cmp, "thr", NULL );
  186. cmDspSysInstallCb(h, cmp_rat, "val", cmp, "ratio", NULL );
  187. cmDspSysInstallCb(h, cmp_atk, "val", cmp, "atk", NULL );
  188. cmDspSysInstallCb(h, cmp_rls, "val", cmp, "rls", NULL );
  189. cmDspSysInstallCb(h, cmp_mkup, "val", cmp, "ogain", NULL );
  190. cmDspSysInstallCb(h, cmp_wnd, "val", cmp, "wnd", NULL );
  191. cmDspSysInstallCb(h, cmp, "env", cmp_mtr, "in", NULL );
  192. cmDspSysInstallCb(h, modp, mlbl("cbyp"), cmp_byp, "in", NULL );
  193. cmDspSysInstallCb(h, modp, mlbl("cigain"), cmp_igain,"val", NULL );
  194. cmDspSysInstallCb(h, modp, mlbl("cthrsh"), cmp_thr, "val", NULL );
  195. cmDspSysInstallCb(h, modp, mlbl("cratio"), cmp_rat, "val", NULL );
  196. cmDspSysInstallCb(h, modp, mlbl("catkms"), cmp_atk, "val", NULL );
  197. cmDspSysInstallCb(h, modp, mlbl("crlsms"), cmp_rls, "val", NULL );
  198. cmDspSysInstallCb(h, modp, mlbl("cmakeup"), cmp_mkup, "val", NULL );
  199. cmDspSysInstallCb(h, modp, mlbl("cwndms"), cmp_wnd, "val", NULL );
  200. //
  201. cmDspInst_t* xfadMs = cmDspSysAllocInst(h,"Scalar", lbl("Xfade Ms"), 5, kNumberDuiId, 0.0, 1000.0,0.01, 50.0 );
  202. cmDspSysInstallCb(h, xfadMs, "val", xfad, "ms", NULL );
  203. cmDspSysInstallCb(h, modp, mlbl("xfad"), xfadMs, "val", NULL);
  204. //cmDspInst_t* sw_btn = cmDspSysAllocButton( h, lbl("switch"), 0);
  205. //cmDspSysInstallCb( h, sw_btn, "sym", achan, "trig", NULL );
  206. // TODO: FIX THIS: can't send window length (e.g. 1024,2048, ... ) to a 'MsgList' with 4 elements
  207. // since it expects an index betweeen 0 and 3. CRASH!
  208. //cmDspSysInstallCb(h, modp, mlbl("win"), wnd_ctl, "sel", NULL );
  209. cmDspSysInstallCb(h, modp, mlbl("hop"), hop_ctl, "sel", NULL );
  210. cmDspSysInstallCb(h, modp, mlbl("ceil"), cel_ctl, "val", NULL );
  211. cmDspSysInstallCb(h, modp, mlbl("expo"), exp_ctl, "val", NULL );
  212. cmDspSysInstallCb(h, modp, mlbl("mix"), mix_ctl, "val", NULL );
  213. cmDspSysInstallCb(h, modp, mlbl("thr"), thr_ctl, "val", NULL );
  214. cmDspSysInstallCb(h, modp, mlbl("upr"), upr_ctl, "val", NULL );
  215. cmDspSysInstallCb(h, modp, mlbl("lwr"), lwr_ctl, "val", NULL );
  216. cmDspSysInstallCb(h, modp, mlbl("wet"), wet_ctl, "val", NULL );
  217. cmDspSysInstallCb(h, modp, mlbl("sw"), achan, "trig", NULL ); // See also: amp.sfloc->achan.trig
  218. c->achan = achan;
  219. c->kr0 = kr0;
  220. c->kr1 = kr1;
  221. c->cmp = cmp;
  222. }