libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmDspPgmKr.c 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 "cmAudioSys.h"
  21. #include "cmProcObj.h"
  22. #include "cmDspCtx.h"
  23. #include "cmDspClass.h"
  24. #include "cmDspSys.h"
  25. #include "cmDspPgm.h"
  26. #include "cmAudioFile.h"
  27. #include "cmProcObj.h"
  28. #include "cmProc.h"
  29. #include "cmProc3.h"
  30. #include "cmVectOpsTemplateMain.h"
  31. #include "cmVectOps.h"
  32. typedef struct
  33. {
  34. const cmChar_t* tlFn;
  35. const cmChar_t* audPath;
  36. const cmChar_t* scFn;
  37. const cmChar_t* modFn;
  38. } krRsrc_t;
  39. cmDspRC_t krLoadRsrc(cmDspSysH_t h, cmErr_t* err, krRsrc_t* r)
  40. {
  41. cmDspRC_t rc;
  42. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  43. return rc;
  44. cmDspRsrcString(h,&r->tlFn, "timeLineFn", NULL);
  45. cmDspRsrcString(h,&r->audPath,"tlAudioFilePath", NULL);
  46. cmDspRsrcString(h,&r->scFn, "scoreFn", NULL);
  47. cmDspRsrcString(h,&r->modFn, "modFn", NULL);
  48. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  49. cmErrMsg(err,rc,"A KR DSP resource load failed.");
  50. return rc;
  51. }
  52. cmDspRC_t _cmDspSysPgm_TimeLine(cmDspSysH_t h, void** userPtrPtr )
  53. {
  54. cmDspRC_t rc = kOkDspRC;
  55. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  56. cmErr_t err;
  57. krRsrc_t r;
  58. unsigned wtLoopCnt = 1; // 1=play once (-1=loop forever)
  59. unsigned wtInitMode = 0; // initial wt mode is 'silence'
  60. unsigned wtSmpCnt = floor(cmDspSysSampleRate(h)); // wt length == srate
  61. int krWndSmpCnt = 2048;
  62. int krHopFact = 4;
  63. memset(&r,0,sizeof(r));
  64. cmErrSetup(&err,&cmCtx->rpt,"Kr Timeline");
  65. if( krLoadRsrc(h,&err,&r) != kOkDspRC )
  66. return rc;
  67. cmDspInst_t* tlp = cmDspSysAllocInst(h,"TimeLine", "tl", 2, r.tlFn, r.audPath );
  68. cmDspInst_t* scp = cmDspSysAllocInst(h,"Score", "sc", 1, r.scFn );
  69. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 1, cmDspSysSampleRate(h) );
  70. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable", NULL, 4, wtSmpCnt, wtInitMode, NULL, wtLoopCnt );
  71. cmDspInst_t* pts = cmDspSysAllocInst(h,"PortToSym", NULL, 2, "on", "off" );
  72. cmDspInst_t* mfp = cmDspSysAllocInst(h,"MidiFilePlay",NULL, 0 );
  73. cmDspInst_t* sfp = cmDspSysAllocInst(h,"ScFol", NULL, 1, r.scFn );
  74. cmDspInst_t* kr0p = cmDspSysAllocInst(h,"Kr", NULL, 2, krWndSmpCnt, krHopFact );
  75. cmDspInst_t* kr1p = cmDspSysAllocInst(h,"Kr", NULL, 2, krWndSmpCnt, krHopFact );
  76. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 0 );
  77. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 1 );
  78. cmDspSysNewPage(h,"Controls");
  79. cmDspInst_t* onb = cmDspSysAllocInst(h,"Button", "start", 2, kButtonDuiId, 1.0 );
  80. cmDspInst_t* offb = cmDspSysAllocInst(h,"Button", "stop", 2, kButtonDuiId, 1.0 );
  81. cmDspInst_t* prtb = cmDspSysAllocInst(h,"Button", "print", 2, kButtonDuiId, 1.0 );
  82. cmDspInst_t* qtb = cmDspSysAllocInst(h,"Button", "quiet", 2, kButtonDuiId, 1.0 );
  83. cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL, 1, ">" );
  84. cmDspInst_t* prd = cmDspSysAllocInst(h,"Printer", NULL, 1, "DYN:" );
  85. cmDspInst_t* pre = cmDspSysAllocInst(h,"Printer", NULL, 1, "EVEN:" );
  86. cmDspInst_t* prt = cmDspSysAllocInst(h,"Printer", NULL, 1, "TEMPO:");
  87. //cmDspInst_t* prv = cmDspSysAllocInst(h,"Printer", NULL, 1, "Value:");
  88. cmDspSysNewColumn(h,0);
  89. cmDspInst_t* md0p = cmDspSysAllocInst(h,"Scalar", "Mode", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  90. cmDspInst_t* ws0p = cmDspSysAllocInst(h,"MsgList","wndSmpCnt", 3, "wndSmpCnt", NULL, 2);
  91. cmDspInst_t* hf0p = cmDspSysAllocInst(h,"MsgList","hopFact", 3, "hopFact", NULL, 2);
  92. cmDspInst_t* th0p = cmDspSysAllocInst(h,"Scalar", "threshold", 5, kNumberDuiId, 0.0, 100.0, 1.0, 60.0 );
  93. cmDspInst_t* us0p = cmDspSysAllocInst(h,"Scalar", "upr slope", 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  94. cmDspInst_t* ls0p = cmDspSysAllocInst(h,"Scalar", "lwr slope", 5, kNumberDuiId, 0.3, 10.0, 0.01, 2.0 );
  95. cmDspInst_t* of0p = cmDspSysAllocInst(h,"Scalar", "offset", 5, kNumberDuiId, 0.0, 100.0, 0.01, 30.0 );
  96. cmDspInst_t* iv0p = cmDspSysAllocInst(h,"Scalar", "invert", 5, kNumberDuiId, 0.0, 1.0, 1.0, 0.0 );
  97. cmDspSysNewColumn(h,0);
  98. //cmDspInst_t* al1p = cmDspSysAllocInst(h,"MsgList","audFiles", 2, "audFiles",NULL);
  99. //cmDspInst_t* fl1p = cmDspSysAllocInst(h,"MsgList","audFrags1", 2, "audFrags",NULL);
  100. //cmDspInst_t* fn1p = cmDspSysAllocInst(h,"Sprintf","filename", 1, "%s/%s_%02i.wav");
  101. cmDspInst_t* md1p = cmDspSysAllocInst(h,"Scalar", "Mode1", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  102. cmDspInst_t* ws1p = cmDspSysAllocInst(h,"MsgList","wndSmpCnt1", 3, "wndSmpCnt", NULL, 2);
  103. cmDspInst_t* hf1p = cmDspSysAllocInst(h,"MsgList","hopFact1", 3, "hopFact", NULL, 2);
  104. cmDspInst_t* th1p = cmDspSysAllocInst(h,"Scalar", "threshold1", 5, kNumberDuiId, 0.0, 100.0, 1.0, 60.0 );
  105. cmDspInst_t* us1p = cmDspSysAllocInst(h,"Scalar", "upr slope1", 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  106. cmDspInst_t* ls1p = cmDspSysAllocInst(h,"Scalar", "lwr slope1", 5, kNumberDuiId, 0.3, 10.0, 0.01, 2.0 );
  107. cmDspInst_t* of1p = cmDspSysAllocInst(h,"Scalar", "offset1", 5, kNumberDuiId, 0.0, 100.0, 0.01, 30.0 );
  108. cmDspInst_t* iv1p = cmDspSysAllocInst(h,"Scalar", "invert1", 5, kNumberDuiId, 0.0, 1.0, 1.0, 0.0 );
  109. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  110. return rc;
  111. // phasor->wt->aout
  112. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phs -> wt
  113. //cmDspSysConnectAudio(h, wtp, "out", kr0p, "in" ); // wt->kr
  114. //cmDspSysConnectAudio(h, wtp, "out", kr1p, "in" );
  115. //cmDspSysConnectAudio(h, kr0p, "out", ao0p, "in"); // kr->aout- 0
  116. //cmDspSysConnectAudio(h, kr1p, "out", ao1p, "in");
  117. cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" ); // wt -> aout0
  118. cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" ); // wt -> aout1
  119. cmDspSysInstallCb( h, wtp, "fidx",tlp, "curs", NULL);
  120. // start connections
  121. cmDspSysInstallCb(h, onb, "sym", tlp, "reset", NULL );
  122. cmDspSysInstallCb(h, onb, "sym", scp, "send", NULL );
  123. cmDspSysInstallCb(h, onb, "sym", mfp, "sel", NULL );
  124. cmDspSysInstallCb(h, onb, "sym", pts, "on", NULL );
  125. cmDspSysInstallCb(h, pts, "on", wtp, "cmd", NULL );
  126. // stop connections
  127. cmDspSysInstallCb(h, wtp, "done",offb,"in", NULL ); // 'done' from WT simulates pressing Stop btn.
  128. cmDspSysInstallCb(h, tlp, "mfn", pts, "off", NULL ); // Prevents WT start on new audio file from TL.
  129. cmDspSysInstallCb(h, offb, "sym", mfp, "sel", NULL );
  130. cmDspSysInstallCb(h, offb, "sym", pts, "off", NULL );
  131. cmDspSysInstallCb(h, pts, "off", wtp, "cmd", NULL );
  132. // time-line to wave-table selection
  133. cmDspSysInstallCb(h, tlp, "absi", wtp, "beg", NULL );
  134. cmDspSysInstallCb(h, tlp, "aesi", wtp, "end", NULL );
  135. cmDspSysInstallCb(h, tlp, "afn", wtp, "fn", NULL );
  136. // time-line to MIDI file player selection
  137. cmDspSysInstallCb(h, tlp, "mbsi", mfp, "bsi", NULL );
  138. cmDspSysInstallCb(h, tlp, "mesi", mfp, "esi", NULL );
  139. cmDspSysInstallCb(h, tlp, "mfn", mfp, "fn", NULL );
  140. // score to score follower - to set initial search location
  141. cmDspSysInstallCb(h, scp, "sel", sfp, "index", NULL );
  142. // MIDI file player to score-follower and score - the order of connections is the same
  143. // as the msg transmision order from MFP
  144. //cmDspSysInstallCb(h, mfp, "smpidx", scp, "smpidx", NULL );
  145. cmDspSysInstallCb(h, mfp, "smpidx", sfp, "smpidx", NULL );
  146. //cmDspSysInstallCb(h, mfp, "d1", scp, "d1", NULL );
  147. cmDspSysInstallCb(h, mfp, "d1", sfp, "d1", NULL );
  148. //cmDspSysInstallCb(h, mfp, "d0", scp, "d0", NULL );
  149. cmDspSysInstallCb(h, mfp, "d0", sfp, "d0", NULL );
  150. //cmDspSysInstallCb(h, mfp, "status", scp, "status", NULL );
  151. cmDspSysInstallCb(h, mfp, "status", sfp, "status", NULL );
  152. // score follower to score
  153. //cmDspSysInstallCb(h, sfp, "out", modp, "index", NULL );
  154. cmDspSysInstallCb(h, ws0p, "out", kr0p, "wndn", NULL ); // wndSmpCnt->kr
  155. cmDspSysInstallCb(h, hf0p, "out", kr0p, "hopf", NULL ); // hopFact->kr
  156. cmDspSysInstallCb(h, md0p, "val", kr0p, "mode", NULL ); // mode->kr
  157. cmDspSysInstallCb(h, th0p, "val", kr0p, "thrh", NULL ); // thresh->kr
  158. cmDspSysInstallCb(h, ls0p, "val", kr0p, "lwrs", NULL ); // lwrSlope->kr
  159. cmDspSysInstallCb(h, us0p, "val", kr0p, "uprs", NULL ); // uprSlope->kr
  160. cmDspSysInstallCb(h, of0p, "val", kr0p, "offs", NULL ); // offset->kr
  161. cmDspSysInstallCb(h, iv0p, "val", kr0p, "invt", NULL ); // invert->kr
  162. cmDspSysInstallCb(h, ws1p, "out", kr1p, "wndn", NULL ); // wndSmpCnt->kr
  163. cmDspSysInstallCb(h, hf1p, "out", kr1p, "hopf", NULL ); // hopFact->kr
  164. cmDspSysInstallCb(h, md1p, "val", kr1p, "mode", NULL ); // mode->kr
  165. cmDspSysInstallCb(h, th1p, "val", kr1p, "thrh", NULL ); // thresh->kr
  166. cmDspSysInstallCb(h, ls1p, "val", kr1p, "lwrs", NULL ); // lwrSlope->kr
  167. cmDspSysInstallCb(h, us1p, "val", kr1p, "uprs", NULL ); // uprSlope->kr
  168. cmDspSysInstallCb(h, of1p, "val", kr1p, "offs", NULL ); // offset->kr
  169. cmDspSysInstallCb(h, iv1p, "val", kr1p, "invt", NULL ); // invert->kr
  170. // Printer connections
  171. cmDspSysInstallCb(h, tlp, "afn", prp, "in", NULL );
  172. cmDspSysInstallCb(h, tlp, "mfn", prp, "in", NULL );
  173. cmDspSysInstallCb(h, tlp, "sel", prp, "in", NULL );
  174. cmDspSysInstallCb(h, sfp, "out", prp, "in", NULL );
  175. cmDspSysInstallCb(h, sfp, "even", pre, "in", NULL );
  176. cmDspSysInstallCb(h, sfp, "dyn", prd, "in", NULL );
  177. cmDspSysInstallCb(h, sfp, "tempo",prt, "in", NULL );
  178. //cmDspSysInstallCb(h, modp,"v0", prv, "in", NULL );
  179. //cmDspSysInstallCb(h, modp,"v1", prv, "in", NULL );
  180. //cmDspSysInstallCb(h, modp,"v2", prv, "in", NULL );
  181. cmDspSysInstallCb(h, prtb, "sym", sfp, "cmd", NULL );
  182. cmDspSysInstallCb(h, qtb, "sym", sfp, "cmd", NULL );
  183. return rc;
  184. }