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.

cmDspPgm.c 116KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721
  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 "cmFileSys.h"
  11. #include "cmSymTbl.h"
  12. #include "cmJson.h"
  13. #include "cmPrefs.h"
  14. #include "cmDspValue.h"
  15. #include "cmMsgProtocol.h"
  16. #include "cmThread.h"
  17. #include "cmUdpPort.h"
  18. #include "cmUdpNet.h"
  19. #include "cmTime.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 "cmDspPgmPP.h"
  27. #include "cmDspPgmKr.h"
  28. cmDspRC_t _cmDspSysPgm_SyncRecd( cmDspSysH_t h, void** userPtrPtr )
  29. {
  30. cmDspRC_t rc = kOkDspRC;
  31. unsigned audioFileBits = 24;
  32. cmDspInst_t* ai0p = cmDspSysAllocInst(h,"AudioIn", NULL, 1, 0 );
  33. cmDspInst_t* ai1p = cmDspSysAllocInst(h,"AudioIn", NULL, 1, 1 );
  34. cmDspInst_t* mip = cmDspSysAllocInst(h,"MidiIn", NULL, 0 );
  35. cmDspInst_t* srp = cmDspSysAllocInst(h,"SyncRecd",NULL, 3, "/home/kevin/temp/kr/sr","sr","audio",audioFileBits);
  36. cmDspInst_t* am0p = cmDspSysAllocInst(h,"AMeter", "Left", 0);
  37. cmDspInst_t* am1p = cmDspSysAllocInst(h,"AMeter", "Right",0);
  38. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 0 );
  39. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 1 );
  40. cmDspInst_t* chk = cmDspSysAllocInst(h,"Checkbox","recd", 5, "Recd","open","close", 1.0, 0.0);
  41. cmDspInst_t* gain0 = cmDspSysAllocInst(h,"Scalar", "In Gain-0", 5, kNumberDuiId, 0.0, 10.0,0.01, 1.0 );
  42. cmDspInst_t* gain1 = cmDspSysAllocInst(h,"Scalar", "In Gain-1", 5, kNumberDuiId, 0.0, 10.0,0.01, 1.0 );
  43. // check for allocation errors
  44. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  45. goto errLabel;
  46. cmDspSysInstallCb(h, mip, "status", srp, "status", NULL);
  47. cmDspSysInstallCb(h, mip, "d0", srp, "d0", NULL);
  48. cmDspSysInstallCb(h, mip, "d1", srp, "d1", NULL);
  49. cmDspSysInstallCb(h, mip, "sec", srp, "sec", NULL);
  50. cmDspSysInstallCb(h, mip, "nsec", srp, "nsec", NULL);
  51. cmDspSysInstallCb(h, chk, "sym", srp, "cmd", NULL);
  52. cmDspSysInstallCb(h, gain0, "val", ai0p, "gain", NULL);
  53. cmDspSysInstallCb(h, gain1, "val", ai1p, "gain", NULL);
  54. cmDspSysConnectAudio(h, ai0p, "out", srp, "ain-0");
  55. cmDspSysConnectAudio(h, ai1p, "out", srp, "ain-1");
  56. cmDspSysConnectAudio(h, ai0p, "out", am0p, "in");
  57. cmDspSysConnectAudio(h, ai1p, "out", am1p, "in");
  58. cmDspSysConnectAudio(h, ai0p, "out", ao0p, "in");
  59. cmDspSysConnectAudio(h, ai1p, "out", ao1p, "in");
  60. errLabel:
  61. return rc;
  62. }
  63. cmDspRC_t _cmDspSysPgm_Test_Midi( cmDspSysH_t h, void** userPtrPtr )
  64. {
  65. cmDspRC_t rc = kOkDspRC;
  66. const cmChar_t* deviceName = "Fastlane";
  67. const cmChar_t* portName = "Fastlane MIDI A";
  68. #ifdef OS_OSX
  69. deviceName = "MOTU - FastLane USB";
  70. portName = "Port A";
  71. //deviceName = "RME - Fireface UFX (23148636)";
  72. //portName = "Port 2";
  73. #endif
  74. cmDspInst_t* sendBtn = cmDspSysAllocInst( h,"Button", "Send", 2, kButtonDuiId, 0.0 );
  75. cmDspInst_t* status = cmDspSysAllocInst( h,"Scalar", "Status", 5, kNumberDuiId, 0.0, 127.0, 1.0, 144.0);
  76. cmDspInst_t* d0 = cmDspSysAllocInst( h,"Scalar", "D0", 5, kNumberDuiId, 0.0, 127.0, 1.0, 64.0);
  77. cmDspInst_t* d1 = cmDspSysAllocInst( h,"Scalar", "D1", 5, kNumberDuiId, 0.0, 127.0, 1.0, 64.0);
  78. cmDspInst_t* midiOut = cmDspSysAllocInst( h,"MidiOut", NULL, 2, deviceName, portName);
  79. cmDspInst_t* midiIn = cmDspSysAllocInst( h,"MidiIn", NULL, 0 );
  80. //cmDspInst_t* printer = cmDspSysAllocInst( h,"Printer", NULL, 1, ">" );
  81. cmDspInst_t* prst = cmDspSysAllocInst( h,"Printer", NULL, 1, "st>" );
  82. cmDspInst_t* prd0 = cmDspSysAllocInst( h,"Printer", NULL, 1, "d0>" );
  83. cmDspInst_t* prd1 = cmDspSysAllocInst( h,"Printer", NULL, 1, "d1>" );
  84. // check for allocation errors
  85. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  86. goto errLabel;
  87. cmDspSysInstallCb( h, sendBtn, "out", d1, "send", NULL);
  88. cmDspSysInstallCb( h, sendBtn, "out", d0, "send", NULL);
  89. cmDspSysInstallCb( h, sendBtn, "out", status, "send", NULL);
  90. cmDspSysInstallCb( h, status, "val", midiOut, "status",NULL);
  91. cmDspSysInstallCb( h, d0, "val", midiOut, "d0", NULL);
  92. cmDspSysInstallCb( h, d1, "val", midiOut, "d1", NULL);
  93. cmDspSysInstallCb( h, midiIn, "status", prst, "in", NULL);
  94. cmDspSysInstallCb( h, midiIn, "d0", prd0, "in", NULL);
  95. cmDspSysInstallCb( h, midiIn, "d1", prd1, "in", NULL);
  96. //cmDspSysInstallCb( h, midiIn, "smpidx", printer, "in", NULL);
  97. errLabel:
  98. return rc;
  99. }
  100. cmDspRC_t _cmDspSysPgm_Stereo_Through( cmDspSysH_t h, void** userPtrPtr )
  101. {
  102. bool useBuiltInFl = true;
  103. cmDspInst_t* ignp = cmDspSysAllocInst( h,"Scalar", "In Gain", 5, kNumberDuiId, 0.0, 4.0, 0.01, 1.0);
  104. //cmDspInst_t* ognp = cmDspSysAllocInst( h,"Scalar", "Out Gain", 5, kNumberDuiId, 0.0, 4.0, 0.01, 1.0);
  105. cmDspInst_t* hzp = cmDspSysAllocInst(h,"Scalar", "Hz", 5, kNumberDuiId, 0.0, 10.0, 0.001, 1.0);
  106. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  107. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable",NULL, 2, cmDspSysSampleRate(h), 2 );
  108. cmDspInst_t* ai0p = cmDspSysAllocInst(h,"AudioIn", NULL, 1, useBuiltInFl ? 0 : 2 );
  109. cmDspInst_t* ai1p = cmDspSysAllocInst(h,"AudioIn", NULL, 1, useBuiltInFl ? 1 : 3 );
  110. // MOTU Traveler: Use channels 2&3 (out plugs:3&4) because 0&1 do not show up on plugs 1&2.
  111. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  112. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  113. cmDspInst_t* im0p = cmDspSysAllocInst(h,"AMeter","In 0", 0);
  114. cmDspInst_t* im1p = cmDspSysAllocInst(h,"AMeter","In 1", 0);
  115. cmDspInst_t* om0p = cmDspSysAllocInst(h,"AMeter","Out 0", 0);
  116. cmDspInst_t* om1p = cmDspSysAllocInst(h,"AMeter","Out 1",0);
  117. //cmDspSysConnectAudio(h, ai0p, "out", ao0p, "in");
  118. //cmDspSysConnectAudio(h, ai1p, "out", ao1p, "in");
  119. cmDspSysConnectAudio(h, ai0p, "out", im0p, "in"); //ain0 -> imtr0
  120. cmDspSysConnectAudio(h, ai1p, "out", im1p, "in"); //ain1 -> imtr1
  121. if(0)
  122. {
  123. cmDspSysInstallCb( h, hzp, "val", php, "mult", NULL); // hz -> phs
  124. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phs -> wt
  125. cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" ); // wt -> aout0
  126. cmDspSysConnectAudio(h, wtp, "out", om0p, "in" ); // wt -> omtr0
  127. }
  128. else
  129. {
  130. cmDspSysInstallCb( h, ignp,"val", ai0p, "gain", NULL); // igain -> ain0
  131. cmDspSysConnectAudio(h, ai0p,"out", ao0p, "in" ); // ain0 -> aout0
  132. cmDspSysConnectAudio(h, ai0p,"out", om0p, "in" ); // ain0 -> omtr0
  133. }
  134. cmDspSysInstallCb( h, ignp,"val", ai1p, "gain", NULL); // igain -> ain1
  135. cmDspSysConnectAudio(h, ai1p,"out", ao1p, "in" ); // ain1 -> aout1
  136. cmDspSysConnectAudio(h, ai1p,"out", om1p, "in" ); // ain1 -> omtr1
  137. return kOkDspRC;
  138. }
  139. cmDspRC_t _cmDspSysPgm_Stereo_Fx( cmDspSysH_t h, void** userPtrPtr )
  140. {
  141. bool useBuiltInFl = true;
  142. cmDspInst_t* ignp = cmDspSysAllocInst( h,"Scalar", "In Gain", 5, kNumberDuiId, 0.0, 4.0, 0.01, 1.0);
  143. cmDspInst_t* ognp = cmDspSysAllocInst( h,"Scalar", "Out Gain", 5, kNumberDuiId, 0.0, 4.0, 0.01, 1.0);
  144. //cmDspInst_t* fb0p = cmDspSysAllocInst( h,"Scalar", "Feeback 0", 5, kNumberDuiId, 0.0, 1.0, 0.001, 0.0);
  145. //cmDspInst_t* fb1p = cmDspSysAllocInst( h,"Scalar", "Feedback 1", 5, kNumberDuiId, 0.0, 1.0, 0.001, 0.0);
  146. //cmDspInst_t* tm0p = cmDspSysAllocInst( h,"Scalar", "Time 0", 5, kNumberDuiId, 0.0, 1000.0, 0.0001, 10.0);
  147. //cmDspInst_t* tm1p = cmDspSysAllocInst( h,"Scalar", "Time 1", 5, kNumberDuiId, 0.0, 1000.0, 0.0001, 10.0);
  148. cmDspInst_t* rt0p = cmDspSysAllocInst( h,"Scalar", "Ratio 0", 5, kNumberDuiId, 0.01, 10.0, 0.01, 1.0);
  149. cmDspInst_t* rt1p = cmDspSysAllocInst( h,"Scalar", "Ratio 1", 5, kNumberDuiId, 0.01, 10.0, 0.01, 1.0);
  150. cmDspInst_t* ai0p = cmDspSysAllocInst(h,"AudioIn", NULL, 1, useBuiltInFl ? 0 : 2 );
  151. cmDspInst_t* ai1p = cmDspSysAllocInst(h,"AudioIn", NULL, 1, useBuiltInFl ? 1 : 3 );
  152. cmDspInst_t* om0p = cmDspSysAllocInst(h,"AMeter","Out Left", 0);
  153. cmDspInst_t* om1p = cmDspSysAllocInst(h,"AMeter","Out Right",0);
  154. //cmDspInst_t* dy0p = cmDspSysAllocInst(h,"Delay", NULL, 2, 1000.0, 0.5 );
  155. //cmDspInst_t* dy1p = cmDspSysAllocInst(h,"Delay", NULL, 2, 2000.0, 0.7 );
  156. cmDspInst_t* ps0p = cmDspSysAllocInst(h,"PShift", NULL, 0 );
  157. cmDspInst_t* ps1p = cmDspSysAllocInst(h,"PShift", NULL, 0 );
  158. // MOTU Traveler: Use channels 2&3 (out plugs:3&4) because 0&1 do not show up on plugs 1&2.
  159. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  160. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  161. cmDspSysConnectAudio(h, ai0p,"out", om0p, "in" ); // input meter connection
  162. cmDspSysConnectAudio(h, ai1p,"out", om1p, "in" );
  163. //cmDspSysConnectAudio(h, ai0p,"out", dy0p, "in" ); // input -> delay
  164. //cmDspSysConnectAudio(h, ai1p,"out", dy1p, "in" );
  165. cmDspSysConnectAudio(h, ai0p,"out", ps0p, "in" ); // delay -> pshift
  166. cmDspSysConnectAudio(h, ai1p,"out", ps1p, "in" );
  167. cmDspSysConnectAudio(h, ps0p,"out", ao0p, "in" ); // pshift -> output
  168. cmDspSysConnectAudio(h, ps1p,"out", ao1p, "in" );
  169. //cmDspSysConnectAudio(h, dy0p,"out", ao0p, "in" ); // delay -> output
  170. //cmDspSysConnectAudio(h, dy1p,"out", ao1p, "in" );
  171. cmDspSysInstallCb( h, ignp,"val", ai0p, "gain", NULL); // input gain
  172. cmDspSysInstallCb( h, ignp,"val", ai1p, "gain", NULL);
  173. cmDspSysInstallCb( h, ognp, "val", ao0p, "gain", NULL); // output gain
  174. cmDspSysInstallCb( h, ognp, "val", ao1p, "gain", NULL);
  175. //cmDspSysInstallCb( h, fb0p, "val", dy0p, "fb", NULL); // feedback
  176. //cmDspSysInstallCb( h, fb1p, "val", dy1p, "fb", NULL);
  177. //cmDspSysInstallCb( h, tm0p, "val", dy0p, "time", NULL); // delay time
  178. //cmDspSysInstallCb( h, tm1p, "val", dy1p, "time", NULL);
  179. cmDspSysInstallCb( h, rt0p, "val", ps0p, "ratio", NULL); // pitch ratio
  180. cmDspSysInstallCb( h, rt1p, "val", ps1p, "ratio", NULL);
  181. return kOkDspRC;
  182. }
  183. cmDspRC_t _cmDspSysPgm_PlaySine( cmDspSysH_t h, void** userPtrPtr )
  184. {
  185. bool useBuiltInFl = true;
  186. double frqHz = 440.0;
  187. cmDspInst_t* chp = cmDspSysAllocInst( h,"Scalar", "Channel", 5, kNumberDuiId, 0.0, 100.0, 1.0, 0.0);
  188. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 2, cmDspSysSampleRate(h), frqHz );
  189. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable", NULL, 2, ((int)cmDspSysSampleRate(h)), 4);
  190. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, useBuiltInFl ? 0 : 2 );
  191. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, useBuiltInFl ? 1 : 3 );
  192. cmDspInst_t* om0p = cmDspSysAllocInst(h,"AMeter","Out", 0);
  193. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phasor -> wave table
  194. cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" ); // wave table -> audio out
  195. cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" ); //
  196. cmDspSysConnectAudio(h, wtp, "out", om0p, "in" );
  197. cmDspSysInstallCb( h, chp, "val", ao0p, "ch", NULL);
  198. return kOkDspRC;
  199. }
  200. cmDspRC_t _cmDspSysPgm_PlayFile( cmDspSysH_t h, void** userPtrPtr )
  201. {
  202. bool useBuiltInFl = true;
  203. const char* fn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  204. //int beg = 6900826;
  205. //int end = 13512262;
  206. const cmChar_t* fn = cmFsMakeFn(cmFsUserDir(),fn0,NULL,NULL );
  207. cmDspInst_t* ofp = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  208. cmDspInst_t* fnp = cmDspSysAllocInst(h,"Fname", NULL, 3, false,"Audio Files (*.wav,*.aiff,*.aif)\tAudio Files (*.{wav,aiff,aif})",fn);
  209. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  210. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable",NULL, 2, ((int)cmDspSysSampleRate(h)), 1 );
  211. //cmDspInst_t* afp = cmDspSysAllocInst(h,"AudioFileOut",NULL,2,"/home/kevin/temp/record0.aif",1);
  212. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  213. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  214. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phasor -> wave table
  215. cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" ); // wave table -> audio out
  216. cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" ); //
  217. //cmDspSysConnectAudio(h, wtp, "out", afp, "in0");
  218. cmDspSysInstallCb(h, ofp, "val", wtp, "beg", NULL );
  219. cmDspSysInstallCb(h, fnp, "out", wtp, "fn", NULL);
  220. return kOkDspRC;
  221. }
  222. cmDspRC_t _cmDspSysPgm_MultiOut( cmDspSysH_t h, void** userPtrPtr )
  223. {
  224. cmDspRC_t rc = kOkDspRC;
  225. double frqHz = 440.0;
  226. unsigned chCnt = 8;
  227. unsigned oneOfN_chCnt = 2;
  228. double offs = 34612504;
  229. cmDspInst_t* aout[chCnt];
  230. unsigned i;
  231. const char* fn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_23.wav";
  232. const cmChar_t* fn = cmFsMakeFn(cmFsUserDir(),fn0,NULL,NULL );
  233. cmDspInst_t* f_phs = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  234. cmDspInst_t* f_wt = cmDspSysAllocInst(h,"WaveTable",NULL, 2, ((int)cmDspSysSampleRate(h)), 1 );
  235. cmDspInst_t* f_mtr = cmDspSysAllocInst(h,"AMeter", "File Out", 0);
  236. cmDspInst_t* f_rew = cmDspSysAllocInst(h,"Button", "Rewind", 2, kButtonDuiId, 1.0 );
  237. cmDspInst_t* f_pts = cmDspSysAllocInst(h,"PortToSym", NULL, 1, "on" );
  238. cmDspInst_t* f_beg = cmDspSysAllocInst(h,"Scalar", "File Begin", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*6000.0, 1.0, offs);
  239. cmDspInst_t* f_nam = cmDspSysAllocInst(h,"Fname", NULL, 3, false,"Audio Files (*.wav,*.aiff,*.aif)\tAudio Files (*.{wav,aiff,aif})",fn);
  240. cmDspInst_t* s_phs = cmDspSysAllocInst(h,"Phasor", NULL, 2, cmDspSysSampleRate(h), frqHz );
  241. cmDspInst_t* s_wt = cmDspSysAllocInst(h,"WaveTable", NULL, 2, ((int)cmDspSysSampleRate(h)), 4);
  242. cmDspInst_t* s_mtr = cmDspSysAllocInst(h,"AMeter", "Tone Out", 0);
  243. cmDspInst_t* swtch = cmDspSysAllocInst(h,"1ofN", NULL, 2, oneOfN_chCnt, 0 );
  244. for(i=0; i<chCnt; ++i)
  245. aout[i] = cmDspSysAllocInst(h,"AudioOut",NULL, 1, i );
  246. cmDspInst_t* chck = cmDspSysAllocInst(h,"Checkbox", "Source", 5, "Tone","file","tone", 0.0, 1.0);
  247. cmDspInst_t** vol = cmDspSysAllocInstArray(h,chCnt,"Scalar", "Gain", NULL, 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  248. // check for allocation errors
  249. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  250. goto errLabel;
  251. cmDspSysConnectAudio( h, s_phs, "out", s_wt, "phs" ); // sine phasor -> wave table
  252. cmDspSysConnectAudio( h, s_wt, "out", s_mtr, "in" ); // sine wave table -> meter
  253. cmDspSysConnectAudio( h, s_wt, "out", swtch, "a-in-1");
  254. cmDspSysConnectAudio( h, f_phs, "out", f_wt, "phs" ); // file phasor -> wave table
  255. cmDspSysConnectAudio( h, f_wt, "out", f_mtr, "in" ); // file wave table -> meter
  256. cmDspSysConnectAudio( h, f_wt, "out", swtch, "a-in-0");
  257. cmDspSysConnectAudio11N1( h, swtch, "a-out", aout, "in", chCnt );
  258. cmDspSysInstallCbN1N1( h, vol, "val", aout, "gain", chCnt );
  259. cmDspSysInstallCb( h, chck, "out", swtch, "chidx", NULL );
  260. cmDspSysInstallCb( h, f_nam, "out", f_wt, "fn", NULL );
  261. cmDspSysInstallCb( h, f_beg, "val", f_wt, "beg", NULL );
  262. cmDspSysInstallCb( h, f_rew, "out", f_pts, "on", NULL );
  263. cmDspSysInstallCb( h, f_pts, "on", f_beg, "send", NULL );
  264. cmDspSysInstallCb( h, f_pts, "on", f_nam, "send", NULL );
  265. cmDspSysInstallCb( h, f_pts, "on", f_wt, "cmd", NULL );
  266. errLabel:
  267. return rc;
  268. }
  269. cmDspRC_t _cmDspSysPgm_MultiIn(cmDspSysH_t h, void** userPtrPtr)
  270. {
  271. int chCnt = 8;
  272. cmDspInst_t* a[chCnt];
  273. int i;
  274. for(i=0; i<chCnt; ++i)
  275. a[i] = cmDspSysAllocInst( h, "AudioIn", NULL, 1, i );
  276. cmDspInst_t* mxp = cmDspSysAllocInst( h, "AMix", NULL, chCnt+1, chCnt, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
  277. cmDspInst_t* afp = cmDspSysAllocInst( h, "AudioFileOut", NULL, 2,"/home/kevin/temp/at/test_in.aif",1);
  278. cmDspInst_t* aop = cmDspSysAllocInst( h, "AudioOut", NULL, 1, 0 );
  279. // AudioFileOut needs an open message to create the output file
  280. cmDspInst_t* btn = cmDspSysAllocInst( h, "Button", "open", 2, kButtonDuiId, 1.0 );
  281. cmDspSysAssignInstAttrSymbolStr(h, btn, "_reset" );
  282. cmDspInst_t* pts = cmDspSysAllocInst(h,"PortToSym", NULL, 1, "open" );
  283. cmDspSysConnectAudioN11N(h, a, "out", mxp, "in", chCnt );
  284. cmDspSysConnectAudio( h, mxp, "out", afp, "in0" );
  285. cmDspSysConnectAudio( h, mxp, "out", aop, "in" );
  286. cmDspSysInstallCb( h, btn, "sym", pts, "open", NULL );
  287. cmDspSysInstallCb( h, pts, "open", afp, "sel", NULL );
  288. return kOkDspRC;
  289. }
  290. cmDspRC_t _cmDspSysPgm_GateDetect( cmDspSysH_t h, void** userPtrPtr )
  291. {
  292. bool useBuiltInFl = true;
  293. //const char* fn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  294. //int beg = 6900826;
  295. //int end = 13512262;
  296. //const char* fn0 = "media/audio/McGill-3/1 Audio Track.aiff";
  297. const char* fn0 = "temp/gate_detect0.aif";
  298. int beg = 0;
  299. int end = -1;
  300. const cmChar_t* fn = cmFsMakeFn(cmFsUserDir(),fn0,NULL,NULL );
  301. const cmChar_t* tfn = "/home/kevin/temp/test0.txt";
  302. cmDspInst_t* ofp = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  303. //cmDspInst_t* fnp = cmDspSysAllocInst(h,"Fname", NULL, 3, false,"Audio Files (*.wav,*.aiff,*.aif)\tAudio Files (*.{wav,aiff,aif})",fn);
  304. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  305. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable", NULL, 6, ((int)cmDspSysSampleRate(h)), 1, fn, -1, beg, end );
  306. cmDspInst_t* gdp = cmDspSysAllocInst(h,"GateDetect",NULL, 1, 20.0);
  307. cmDspInst_t* gmp = cmDspSysAllocInst(h,"Meter", NULL, 3, 0.0, 0.0, 1.0);
  308. cmDspInst_t* rmp = cmDspSysAllocInst(h,"Meter", NULL, 3, -100.0, -100.0, 0.0);
  309. cmDspInst_t* txp = cmDspSysAllocInst(h,"TextFile", NULL, 2, 3, tfn);
  310. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  311. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  312. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phasor -> wave table
  313. cmDspSysConnectAudio(h, wtp, "out", ao0p, "in" ); // wave table -> audio out
  314. cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" ); //
  315. cmDspSysConnectAudio(h, wtp, "out", gdp, "in" );
  316. cmDspSysInstallCb(h, ofp, "val", wtp, "beg", NULL );
  317. cmDspSysInstallCb(h, gdp, "gate", gmp, "in", NULL );
  318. cmDspSysInstallCb(h, gdp, "rms", rmp, "in", NULL );
  319. cmDspSysInstallCb(h, gdp, "gate", txp, "in-0", NULL);
  320. cmDspSysInstallCb(h, gdp, "rms", txp, "in-1", NULL);
  321. cmDspSysInstallCb(h, gdp, "mean", txp, "in-2", NULL);
  322. return kOkDspRC;
  323. }
  324. cmDspRC_t _cmDspSysPgm_Record(cmDspSysH_t h, void** userPtrPtr)
  325. {
  326. int chCnt = 8;
  327. cmDspInst_t* a[chCnt];
  328. int i;
  329. for(i=0; i<chCnt; ++i)
  330. a[i] = cmDspSysAllocInst( h, "AudioIn", NULL, 1, i );
  331. cmDspInst_t* mxp = cmDspSysAllocInst( h, "AMix", NULL, chCnt+1, chCnt, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 );
  332. cmDspInst_t* afp = cmDspSysAllocInst( h, "AudioFileOut", NULL, 2,"/home/kevin/temp/gate_detect.aif",1);
  333. cmDspInst_t* aop = cmDspSysAllocInst( h, "AudioOut", NULL, 1, 0 );
  334. cmDspInst_t* txp = cmDspSysAllocInst( h, "TextFile", NULL, 2, 1, "/home/kevin/temp/gate_detect.txt");
  335. cmDspInst_t* chp = cmDspSysAllocInst( h, "Scalar", "Channel", 5, kNumberDuiId, 0.0, 7.0, 1.0, 0.0);
  336. // AudioFileOut needs an open message to create the output file
  337. cmDspInst_t* btn = cmDspSysAllocInst( h, "Button", "open", 2, kButtonDuiId, 1.0 );
  338. cmDspSysAssignInstAttrSymbolStr(h, btn, "_reset" );
  339. cmDspInst_t* pts = cmDspSysAllocInst(h,"PortToSym", NULL, 1, "open" );
  340. for(i=0; i<chCnt; ++i)
  341. {
  342. cmChar_t lbl[15];
  343. snprintf(lbl,15,"in-%i",i);
  344. cmDspSysConnectAudio(h,a[i], "out", mxp, lbl);
  345. }
  346. cmDspSysConnectAudio(h, mxp, "out", afp, "in0" );
  347. cmDspSysConnectAudio(h, mxp, "out", aop, "in" );
  348. cmDspSysInstallCb(h, chp, "out", txp, "in-0", NULL);
  349. cmDspSysInstallCb( h, btn, "sym", pts, "open", NULL );
  350. cmDspSysInstallCb( h, pts, "open", afp, "sel", NULL );
  351. return kOkDspRC;
  352. }
  353. cmDspRC_t _cmDspSysPgm_PitchShiftFile( cmDspSysH_t h, void** userPtrPtr )
  354. {
  355. bool useBuiltInFl = true;
  356. const cmChar_t* fn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  357. const cmChar_t* fn1 = "temp/record0.aif";
  358. int beg = 6900826;
  359. int end = 13512262;
  360. const cmChar_t* fn = cmFsMakeFn(cmFsUserDir(),fn0,NULL,NULL );
  361. const cmChar_t* ofn = cmFsMakeFn(cmFsUserDir(),fn1,NULL,NULL );
  362. cmDspInst_t* rt0p = cmDspSysAllocInst(h,"Scalar", "Ratio 0", 5, kNumberDuiId, 0.01, 10.0, 0.01, 1.0);
  363. cmDspInst_t* rt1p = cmDspSysAllocInst(h,"Scalar", "Ratio 1", 5, kNumberDuiId, 0.01, 10.0, 0.01, 1.0);
  364. cmDspInst_t* ofp = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  365. //cmDspInst_t* fnp = cmDspSysAllocInst(h,"Fname", NULL, 3, false,"Audio Files (*.wav,*.aiff,*.aif)\tAudio Files (*.{wav,aiff,aif})",fn);
  366. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  367. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable",NULL, 6, ((int)cmDspSysSampleRate(h)), 1, fn, -1, beg, end );
  368. cmDspInst_t* afp = cmDspSysAllocInst(h,"AudioFileOut",NULL,2,ofn,1);
  369. cmDspInst_t* ps0p = cmDspSysAllocInst(h,"PShift", NULL, 0 );
  370. cmDspInst_t* ps1p = cmDspSysAllocInst(h,"PShift", NULL, 0 );
  371. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  372. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  373. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phasor -> wave table
  374. cmDspSysConnectAudio(h, wtp, "out", ps0p, "in" ); // wave table -> shift
  375. cmDspSysConnectAudio(h, wtp, "out", ps1p, "in" ); //
  376. cmDspSysConnectAudio(h, ps0p, "out", ao0p, "in" ); // shift -> audio out
  377. cmDspSysConnectAudio(h, ps1p, "out", ao1p, "in" ); //
  378. cmDspSysConnectAudio(h, ps0p, "out", afp, "in0"); //
  379. cmDspSysInstallCb(h, ofp, "val", wtp, "beg", NULL );
  380. //cmDspSysInstallCb(h, fnp, "out", wtp, "fn", NULL);
  381. cmDspSysInstallCb(h, rt0p, "val", ps0p, "ratio", NULL);
  382. cmDspSysInstallCb(h, rt1p, "val", ps1p, "ratio", NULL);
  383. return kOkDspRC;
  384. }
  385. cmDspRC_t _cmDspSysPgm_LoopRecd( cmDspSysH_t h, void** userPtrPtr )
  386. {
  387. bool useBuiltInFl = true;
  388. const cmChar_t* fn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  389. const cmChar_t* fn = cmFsMakeFn(cmFsUserDir(),fn0,NULL,NULL );
  390. int beg = 6900826;
  391. int end = 13512262;
  392. cmDspInst_t* rfl = cmDspSysAllocInst(h,"Button", "Recd", 2, kCheckDuiId, 0.0 );
  393. cmDspInst_t* pfl = cmDspSysAllocInst(h,"Button", "Play", 2, kButtonDuiId, 1.0 );
  394. cmDspInst_t* rtp = cmDspSysAllocInst(h,"Scalar", "Ratio", 5, kNumberDuiId, 0.0, 10.0, 0.01, 1.0 );
  395. cmDspInst_t* ofp = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  396. //cmDspInst_t* fnp = cmDspSysAllocInst(h,"Fname", NULL, 3, false,"Audio Files (*.wav,*.aiff,*.aif)\tAudio Files (*.{wav,aiff,aif})",fn);
  397. cmDspInst_t* php = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  398. cmDspInst_t* wtp = cmDspSysAllocInst(h,"WaveTable",NULL, 6, ((int)cmDspSysSampleRate(h)), 1, fn, -1, beg, end );
  399. //cmDspInst_t* afp = cmDspSysAllocInst(h,"AudioFileOut",NULL,2,"/home/kevin/temp/record0.aif",1);
  400. cmDspInst_t* lrp = cmDspSysAllocInst(h,"LoopRecd", NULL, 0 );
  401. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  402. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  403. cmDspSysConnectAudio(h, php, "out", wtp, "phs" ); // phasor -> wave table
  404. cmDspSysConnectAudio(h, wtp, "out", lrp, "in" ); // wave table -> shift
  405. cmDspSysConnectAudio(h, lrp, "out", ao0p, "in" ); // shift -> audio out
  406. cmDspSysConnectAudio(h, wtp, "out", ao1p, "in" );
  407. cmDspSysInstallCb(h, ofp, "val", wtp, "beg", NULL );
  408. //cmDspSysInstallCb(h, fnp, "out", wtp, "fn", NULL);
  409. cmDspSysInstallCb(h, rfl, "out", lrp, "recd", NULL);
  410. cmDspSysInstallCb(h, pfl, "out", lrp, "play", NULL);
  411. cmDspSysInstallCb(h, rtp, "val", lrp, "ratio",NULL);
  412. return kOkDspRC;
  413. }
  414. cmDspRC_t _cmDspSysPgm_UiTest(cmDspSysH_t h, void** userPtrPtr )
  415. {
  416. cmDspRC_t rc = kOkDspRC;
  417. cmDspInst_t* mdp = cmDspSysAllocInst(h,"Scalar", "Mode", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  418. cmDspInst_t* wsp = cmDspSysAllocInst(h,"MsgList","wndSmpCnt", 3, "wndSmpCnt", NULL, 2);
  419. cmDspInst_t* hfp = cmDspSysAllocInst(h,"MsgList","hopFact", 3, "hopFact", NULL, 2);
  420. cmDspInst_t* thp = cmDspSysAllocInst(h,"Scalar", "threshold", 5, kNumberDuiId, 0.0, 1.0, 0.01, 0.5 );
  421. cmDspInst_t* trp = cmDspSysAllocInst(h,"Scalar", "target", 5, kNumberDuiId, 0.0, 1.0, 0.01, 0.5 );
  422. cmDspInst_t* btn = cmDspSysAllocInst(h,"Button", "btn", 2, kButtonDuiId, 12.3 );
  423. cmDspInst_t* chk = cmDspSysAllocInst(h,"Button", "check", 2, kCheckDuiId, 0 );
  424. cmDspInst_t* chb = cmDspSysAllocInst(h,"Checkbox","checkbox", 5, "Checker","up","down", 2.0, 1.0);
  425. cmDspInst_t* txt = cmDspSysAllocInst(h,"Text", "text", 1, "Hello" );
  426. cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL, 1, ">" );
  427. cmDspInst_t* mtp = cmDspSysAllocInst(h,"Meter", "meter", 3, 0.0, 0.0, 4.0);
  428. cmDspInst_t* ctp = cmDspSysAllocInst(h,"Counter", NULL, 3, 0.0, 10.0, 1.0 );
  429. cmDspSysAllocInst(h,"Label", "label1", 1, "label2");
  430. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  431. return rc;
  432. cmDspSysInstallCb(h, mdp, "val", thp, "val", NULL );
  433. cmDspSysInstallCb(h, mdp, "val", prp, "in", NULL );
  434. cmDspSysInstallCb(h, wsp, "out", prp, "in", NULL );
  435. cmDspSysInstallCb(h, hfp, "out", prp, "in", NULL );
  436. cmDspSysInstallCb(h, trp, "val", prp, "in", NULL );
  437. cmDspSysInstallCb(h, btn, "out", prp, "in", NULL );
  438. cmDspSysInstallCb(h, chk, "out", prp, "in", NULL );
  439. cmDspSysInstallCb(h, ctp, "out", prp, "in", NULL );
  440. cmDspSysInstallCb(h, mdp, "val", btn, "in", NULL );
  441. cmDspSysInstallCb(h, thp, "val", mtp, "in", NULL );
  442. cmDspSysInstallCb(h, thp, "val", trp, "val", NULL );
  443. cmDspSysInstallCb(h, btn, "sym", prp, "in", NULL );
  444. cmDspSysInstallCb(h, btn, "out", ctp, "next", NULL );
  445. cmDspSysInstallCb(h, txt, "val", prp, "in", NULL );
  446. cmDspSysInstallCb(h, chb, "out", prp, "in", NULL );
  447. cmDspSysInstallCb(h, chb, "sym", prp, "in", NULL );
  448. return rc;
  449. }
  450. cmDspRC_t _cmDspSysPgm_Xfade( cmDspSysH_t h, void** userPtrPtr )
  451. {
  452. cmDspRC_t rc = kOkDspRC;
  453. unsigned leftChIdx = 0;
  454. unsigned rightChIdx = 1;
  455. unsigned chCnt = 2;
  456. double xfadeMs = 1000; // cross fade time
  457. double sgHz = 500;
  458. unsigned sgShapeId = 1;
  459. double sgGain = 0.5;
  460. cmDspInst_t* sg = cmDspSysAllocInst( h, "SigGen", NULL, 3, sgHz, sgShapeId, sgGain );
  461. cmDspInst_t* xfp = cmDspSysAllocInst(h,"Xfader", NULL, 2, chCnt, xfadeMs );
  462. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, leftChIdx );
  463. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, rightChIdx );
  464. cmDspInst_t* im0p = cmDspSysAllocInst(h,"AMeter","In 0", 0);
  465. cmDspInst_t* im1p = cmDspSysAllocInst(h,"AMeter","In 1", 0);
  466. cmDspInst_t* om0p = cmDspSysAllocInst(h,"AMeter","Out 0", 0);
  467. cmDspInst_t* om1p = cmDspSysAllocInst(h,"AMeter","Out 1", 0);
  468. cmDspInst_t* mstr = cmDspSysAllocInst(h,"Button", "Mstr", 2, kCheckDuiId, 0.0 );
  469. cmDspInst_t* btn0 = cmDspSysAllocInst(h,"Button", "Fade 0", 2, kCheckDuiId, 0.0 );
  470. cmDspInst_t* btn1 = cmDspSysAllocInst(h,"Button", "Fade 1", 2, kCheckDuiId, 1.0 );
  471. cmDspInst_t* gm0p = cmDspSysAllocInst(h,"Meter","Gain 0", 3, 0.0, 0.0, 1.0);
  472. cmDspInst_t* gm1p = cmDspSysAllocInst(h,"Meter","Gain 1", 3, 0.0, 0.0, 1.0);
  473. cmDspInst_t* pon = cmDspSysAllocInst(h,"Printer", NULL, 1, "on:" );
  474. cmDspInst_t* pof = cmDspSysAllocInst(h,"Printer", NULL, 1, "off:" );
  475. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  476. return rc;
  477. cmDspSysConnectAudio(h, sg, "out", im0p, "in"); // ain -> meter
  478. cmDspSysConnectAudio(h, sg, "out", im1p, "in"); //
  479. cmDspSysConnectAudio(h, sg, "out", xfp, "in-0"); // ain -> xfader
  480. cmDspSysConnectAudio(h, sg, "out", xfp, "in-1");
  481. cmDspSysConnectAudio(h, xfp, "out-0", om0p, "in" ); // xfade -> meter
  482. cmDspSysConnectAudio(h, xfp, "out-1", om1p, "in" ); //
  483. cmDspSysConnectAudio(h, xfp, "out-0", ao0p, "in" ); // xfade -> aout
  484. cmDspSysConnectAudio(h, xfp, "out-1", ao1p, "in" ); //
  485. cmDspSysInstallCb(h, btn0, "out", xfp, "gate-0", NULL ); // check -> xfade gate
  486. cmDspSysInstallCb(h, btn1, "out", xfp, "gate-1", NULL );
  487. cmDspSysInstallCb(h, mstr, "out", xfp, "mgate", NULL );
  488. cmDspSysInstallCb(h, xfp, "gain-0", gm0p, "in", NULL );
  489. cmDspSysInstallCb(h, xfp, "gain-1", gm1p, "in", NULL );
  490. cmDspSysInstallCb(h, xfp, "on", pon, "in", NULL );
  491. cmDspSysInstallCb(h, xfp, "off", pof, "in", NULL );
  492. return cmDspSysLastRC(h);
  493. }
  494. cmDspRC_t _cmDspSysPgm6( cmDspSysH_t h, void* audioDir )
  495. {
  496. cmDspRC_t rc = kOkDspRC;
  497. int wndSmpCnt = 2048;
  498. int hopFact = 4;
  499. //const char* afDir = "/Volumes/LaTetra0/media/audio/20110723-Kriesberg/Audio Files";
  500. //const char* afDir = "/Users/administrator/Documents/kc";
  501. const char* afDir = "/home/kevin/media/audio/20110723-Kriesberg/Audio Files";
  502. cmDspInst_t* ph0p = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  503. cmDspInst_t* wt0p = cmDspSysAllocInst(h,"WaveTable",NULL, 0 );
  504. cmDspInst_t* ro0p = cmDspSysAllocInst(h,"Reorder", NULL, 5, 3, 2, 0, 1, 2 );
  505. cmDspInst_t* kr0p = cmDspSysAllocInst(h,"Kr", NULL, 2, wndSmpCnt, hopFact );
  506. cmDspInst_t* kr1p = cmDspSysAllocInst(h,"Kr", NULL, 2, wndSmpCnt, hopFact );
  507. cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL, 0 );
  508. bool useBuiltInFl = true;
  509. // MOTU Traveler: Use channels 2&3 (out plugs:3&4) because 0&1 do not show up on plugs 1&2.
  510. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  511. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  512. // BUG: If audio inputs are not connected a 'not an audio buffer' msg is generated.
  513. // This is a problem with type determination in the cmDspClass related code : see cmDspClass.c 833
  514. // for a place that this error would be thrown in the following audio outputs were not connected
  515. // to audio sources.
  516. cmDspInst_t* ao2p = NULL;
  517. cmDspInst_t* ao3p = NULL;
  518. if( !useBuiltInFl )
  519. {
  520. ao2p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 4 );
  521. ao3p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 5 );
  522. }
  523. cmDspInst_t* al0p = cmDspSysAllocInst(h,"MsgList","audFiles", 2, "audFiles",NULL);
  524. cmDspInst_t* fl0p = cmDspSysAllocInst(h,"MsgList","audFragsA", 2, "audFrags",NULL);
  525. cmDspInst_t* fn0p = cmDspSysAllocInst(h,"Sprintf","filename", 1, "%s/%s_%02i.wav");
  526. cmDspInst_t* md0p = cmDspSysAllocInst(h,"Scalar", "Mode", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  527. cmDspInst_t* ws0p = cmDspSysAllocInst(h,"MsgList","wndSmpCnt", 3, "wndSmpCnt", NULL, 2);
  528. cmDspInst_t* hf0p = cmDspSysAllocInst(h,"MsgList","hopFact", 3, "hopFact", NULL, 2);
  529. cmDspInst_t* th0p = cmDspSysAllocInst(h,"Scalar", "threshold", 5, kNumberDuiId, 0.0, 100.0, 1.0, 60.0 );
  530. cmDspInst_t* us0p = cmDspSysAllocInst(h,"Scalar", "upr slope", 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  531. cmDspInst_t* ls0p = cmDspSysAllocInst(h,"Scalar", "lwr slope", 5, kNumberDuiId, 0.3, 10.0, 0.01, 2.0 );
  532. cmDspInst_t* of0p = cmDspSysAllocInst(h,"Scalar", "offset", 5, kNumberDuiId, 0.0, 100.0, 0.01, 30.0 );
  533. cmDspInst_t* iv0p = cmDspSysAllocInst(h,"Scalar", "invert", 5, kNumberDuiId, 0.0, 1.0, 1.0, 0.0 );
  534. cmDspSysNewColumn(h,0);
  535. //cmDspInst_t* al1p = cmDspSysAllocInst(h,"MsgList","audFiles", 2, "audFiles",NULL);
  536. //cmDspInst_t* fl1p = cmDspSysAllocInst(h,"MsgList","audFrags1", 2, "audFrags",NULL);
  537. //cmDspInst_t* fn1p = cmDspSysAllocInst(h,"Sprintf","filename", 1, "%s/%s_%02i.wav");
  538. cmDspInst_t* md1p = cmDspSysAllocInst(h,"Scalar", "Mode", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  539. cmDspInst_t* ws1p = cmDspSysAllocInst(h,"MsgList","wndSmpCnt", 3, "wndSmpCnt", NULL, 2);
  540. cmDspInst_t* hf1p = cmDspSysAllocInst(h,"MsgList","hopFact", 3, "hopFact", NULL, 2);
  541. cmDspInst_t* th1p = cmDspSysAllocInst(h,"Scalar", "threshold", 5, kNumberDuiId, 0.0, 100.0, 1.0, 60.0 );
  542. cmDspInst_t* us1p = cmDspSysAllocInst(h,"Scalar", "upr slope", 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  543. cmDspInst_t* ls1p = cmDspSysAllocInst(h,"Scalar", "lwr slope", 5, kNumberDuiId, 0.3, 10.0, 0.01, 2.0 );
  544. cmDspInst_t* of1p = cmDspSysAllocInst(h,"Scalar", "offset", 5, kNumberDuiId, 0.0, 100.0, 0.01, 30.0 );
  545. cmDspInst_t* iv1p = cmDspSysAllocInst(h,"Scalar", "invert", 5, kNumberDuiId, 0.0, 1.0, 1.0, 0.0 );
  546. cmDspSysNewColumn(h,0);
  547. cmDspInst_t* dnp = cmDspSysAllocInst(h,"Fname", "audDir", 3, true,NULL,afDir);
  548. cmDspInst_t* mtp = cmDspSysAllocInst(h,"Meter","MyMeter", 3, 50.0, 0.0, 100.0);
  549. cmDspInst_t* atp = cmDspSysAllocInst(h,"AMeter","Audio Meter",0);
  550. if( (rc = cmDspSysLastRC(h)) != kOkDspRC )
  551. return rc;
  552. cmDspSysConnectAudio(h, ph0p, "out", wt0p, "phs"); // phasor->wt:phs
  553. cmDspSysConnectAudio(h, wt0p, "out", kr0p, "in"); // wt->kr
  554. cmDspSysConnectAudio(h, kr0p, "out", ao0p, "in"); // kr->aout- 0
  555. cmDspSysConnectAudio(h, wt0p, "out", kr1p, "in"); // wt->kr
  556. cmDspSysConnectAudio(h, kr1p, "out", ao1p, "in"); // kr->aout - 1
  557. if( ao2p != NULL )
  558. cmDspSysConnectAudio(h, wt0p,"out", ao2p, "in"); // wt->aout - 2
  559. if( ao3p != NULL )
  560. cmDspSysConnectAudio(h, wt0p,"out", ao3p, "in"); // wt->aout - 3
  561. cmDspSysConnectAudio(h, wt0p,"out", atp, "in"); // wt->meter
  562. cmDspSysInstallCb(h, ws0p, "out", kr0p, "wndn", NULL ); // wndSmpCnt->kr
  563. cmDspSysInstallCb(h, hf0p, "out", kr0p, "hopf", NULL ); // hopFact->kr
  564. cmDspSysInstallCb(h, md0p, "val", kr0p, "mode", NULL ); // mode->kr
  565. cmDspSysInstallCb(h, th0p, "val", kr0p, "thrh", NULL ); // thresh->kr
  566. cmDspSysInstallCb(h, ls0p, "val", kr0p, "lwrs", NULL ); // lwrSlope->kr
  567. cmDspSysInstallCb(h, us0p, "val", kr0p, "uprs", NULL ); // uprSlope->kr
  568. cmDspSysInstallCb(h, of0p, "val", kr0p, "offs", NULL ); // offset->kr
  569. cmDspSysInstallCb(h, iv0p, "val", kr0p, "invt", NULL ); // invert->kr
  570. cmDspSysInstallCb(h, th0p, "val", mtp, "in", NULL );
  571. cmDspSysInstallCb(h, ws1p, "out", kr1p, "wndn", NULL ); // wndSmpCnt->kr
  572. cmDspSysInstallCb(h, hf1p, "out", kr1p, "hopf", NULL ); // hopFact->kr
  573. cmDspSysInstallCb(h, md1p, "val", kr1p, "mode", NULL ); // mode->kr
  574. cmDspSysInstallCb(h, th1p, "val", kr1p, "thrh", NULL ); // thresh->kr
  575. cmDspSysInstallCb(h, ls1p, "val", kr1p, "lwrs", NULL ); // lwrSlope->kr
  576. cmDspSysInstallCb(h, us1p, "val", kr1p, "uprs", NULL ); // uprSlope->kr
  577. cmDspSysInstallCb(h, of1p, "val", kr1p, "offs", NULL ); // offset->kr
  578. cmDspSysInstallCb(h, iv1p, "val", kr1p, "invt", NULL ); // invert->kr
  579. cmDspSysInstallCb(h, dnp, "out", fn0p, "in-0", NULL); // dir->fn:0
  580. cmDspSysInstallCb(h, al0p, "out", fn0p, "in-1", NULL ); // fn->fn:1
  581. cmDspSysInstallCb(h, fl0p, "take", fn0p, "in-2", NULL ); // take->fn:2
  582. cmDspSysInstallCb(h, fn0p, "out", ro0p, "in-0", NULL); // fn->print
  583. cmDspSysInstallCb(h, fl0p, "beg", ro0p, "in-1", NULL); //
  584. cmDspSysInstallCb(h, fl0p, "end", ro0p, "in-2", NULL); //
  585. cmDspSysInstallCb(h, ro0p, "out-0", wt0p, "fn", NULL ); // fn->wt:fn
  586. cmDspSysInstallCb(h, ro0p, "out-1", wt0p, "beg", NULL ); // beg->wt:beg
  587. cmDspSysInstallCb(h, ro0p, "out-2", wt0p, "end", NULL ); // end->wt:end
  588. cmDspSysInstallCb(h, ro0p, "out-1", prp, "in", NULL ); //
  589. //cmDspSysInstallCb(h, dnp, "out", fn1p, "in-0", NULL); // dir->fn:0
  590. //cmDspSysInstallCb(h, al1p, "out", fn1p, "in-1", NULL ); // fn->fn:1
  591. //cmDspSysInstallCb(h, fl1p, "take", fn1p, "in-2", NULL ); // take->fn:2
  592. //cmDspSysInstallCb(h, fn1p, "out", ro1p, "in-0", NULL); // fn->print
  593. //cmDspSysInstallCb(h, fl1p, "beg", ro1p, "in-1", NULL); //
  594. //cmDspSysInstallCb(h, fl1p, "end", ro1p, "in-2", NULL); //
  595. //cmDspSysInstallCb(h, ro1p, "out-0", wt1p, "fn", NULL ); // fn->wt:fn
  596. //cmDspSysInstallCb(h, ro1p, "out-1", wt1p, "beg", NULL ); // beg->wt:beg
  597. //cmDspSysInstallCb(h, ro1p, "out-2", wt1p, "end", NULL ); // end->wt:end
  598. return cmDspSysLastRC(h);
  599. }
  600. cmDspRC_t _cmDspSysPgmGuitar( cmDspSysH_t h, void** userPtrPtr )
  601. {
  602. cmDspRC_t rc = kOkDspRC;
  603. int wndSmpCnt = 2048;
  604. int hopFact = 4;
  605. const char* afDir = "/Volumes/LaTetra0/media/audio/20110723-Kriesberg/Audio Files";
  606. //const char* afDir = "/Users/administrator/Documents/kc";
  607. cmDspInst_t* ph0p = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  608. cmDspInst_t* wt0p = cmDspSysAllocInst(h,"WaveTable",NULL, 0 );
  609. cmDspInst_t* ro0p = cmDspSysAllocInst(h,"Reorder", NULL, 5, 3, 2, 0, 1, 2 );
  610. cmDspInst_t* kr0p = cmDspSysAllocInst(h,"Kr", NULL, 2, wndSmpCnt, hopFact );
  611. cmDspInst_t* kr1p = cmDspSysAllocInst(h,"Kr", NULL, 2, wndSmpCnt, hopFact );
  612. cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL, 0 );
  613. bool useBuiltInFl = true;
  614. // MOTU Traveler: Use channels 2&3 (out plugs:3&4) because 0&1 do not show up on plugs 1&2.
  615. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 0 : 2 );
  616. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, useBuiltInFl ? 1 : 3 );
  617. // BUG: If audio inputs are not connected a 'not an audio buffer' msg is generated.
  618. // This is a problem with type determination in the cmDspClass related code : see cmDspClass.c 833
  619. // for a place that this error would be thrown in the following audio outputs were not connected
  620. // to audio sources.
  621. cmDspInst_t* ao2p = NULL;
  622. cmDspInst_t* ao3p = NULL;
  623. if( !useBuiltInFl )
  624. {
  625. ao2p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 4 );
  626. ao3p = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 5 );
  627. }
  628. cmDspInst_t* al0p = cmDspSysAllocInst(h,"MsgList","audFiles", 2, "audFiles",NULL);
  629. cmDspInst_t* fl0p = cmDspSysAllocInst(h,"MsgList","audFragsA", 2, "audFrags",NULL);
  630. cmDspInst_t* fn0p = cmDspSysAllocInst(h,"Sprintf","filename", 1, "%s/%s_%02i.wav");
  631. cmDspInst_t* md0p = cmDspSysAllocInst(h,"Scalar", "Mode", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  632. cmDspInst_t* ws0p = cmDspSysAllocInst(h,"MsgList","wndSmpCnt", 3, "wndSmpCnt", NULL, 2);
  633. cmDspInst_t* hf0p = cmDspSysAllocInst(h,"MsgList","hopFact", 3, "hopFact", NULL, 2);
  634. cmDspInst_t* th0p = cmDspSysAllocInst(h,"Scalar", "threshold", 5, kNumberDuiId, 0.0, 100.0, 1.0, 60.0 );
  635. cmDspInst_t* us0p = cmDspSysAllocInst(h,"Scalar", "upr slope", 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  636. cmDspInst_t* ls0p = cmDspSysAllocInst(h,"Scalar", "lwr slope", 5, kNumberDuiId, 0.3, 10.0, 0.01, 2.0 );
  637. cmDspInst_t* of0p = cmDspSysAllocInst(h,"Scalar", "offset", 5, kNumberDuiId, 0.0, 100.0, 0.01, 30.0 );
  638. cmDspInst_t* iv0p = cmDspSysAllocInst(h,"Scalar", "invert", 5, kNumberDuiId, 0.0, 1.0, 1.0, 0.0 );
  639. cmDspSysNewColumn(h,0);
  640. //cmDspInst_t* al1p = cmDspSysAllocInst(h,"MsgList","audFiles", 2, "audFiles",NULL);
  641. //cmDspInst_t* fl1p = cmDspSysAllocInst(h,"MsgList","audFrags1", 2, "audFrags",NULL);
  642. //cmDspInst_t* fn1p = cmDspSysAllocInst(h,"Sprintf","filename", 1, "%s/%s_%02i.wav");
  643. cmDspInst_t* md1p = cmDspSysAllocInst(h,"Scalar", "Mode", 5, kNumberDuiId, 0.0, 4.0, 1.0, 1.0);
  644. cmDspInst_t* ws1p = cmDspSysAllocInst(h,"MsgList","wndSmpCnt", 3, "wndSmpCnt", NULL, 2);
  645. cmDspInst_t* hf1p = cmDspSysAllocInst(h,"MsgList","hopFact", 3, "hopFact", NULL, 2);
  646. cmDspInst_t* th1p = cmDspSysAllocInst(h,"Scalar", "threshold", 5, kNumberDuiId, 0.0, 100.0, 1.0, 60.0 );
  647. cmDspInst_t* us1p = cmDspSysAllocInst(h,"Scalar", "upr slope", 5, kNumberDuiId, 0.0, 10.0, 0.01, 0.0 );
  648. cmDspInst_t* ls1p = cmDspSysAllocInst(h,"Scalar", "lwr slope", 5, kNumberDuiId, 0.3, 10.0, 0.01, 2.0 );
  649. cmDspInst_t* of1p = cmDspSysAllocInst(h,"Scalar", "offset", 5, kNumberDuiId, 0.0, 100.0, 0.01, 30.0 );
  650. cmDspInst_t* iv1p = cmDspSysAllocInst(h,"Scalar", "invert", 5, kNumberDuiId, 0.0, 1.0, 1.0, 0.0 );
  651. cmDspSysNewColumn(h,0);
  652. cmDspInst_t* dnp = cmDspSysAllocInst(h,"Fname", "audDir", 3, true,NULL,afDir);
  653. cmDspInst_t* mtp = cmDspSysAllocInst(h,"Meter","MyMeter", 3, 50.0, 0.0, 100.0);
  654. cmDspInst_t* atp = cmDspSysAllocInst(h,"AMeter","Audio Meter",0);
  655. if( (rc = cmDspSysLastRC(h)) != kOkDspRC )
  656. return rc;
  657. cmDspSysConnectAudio(h, ph0p, "out", wt0p, "phs"); // phasor->wt:phs
  658. cmDspSysConnectAudio(h, wt0p, "out", kr0p, "in"); // wt->kr
  659. cmDspSysConnectAudio(h, kr0p, "out", ao0p, "in"); // kr->aout- 0
  660. cmDspSysConnectAudio(h, wt0p, "out", kr1p, "in"); // wt->kr
  661. cmDspSysConnectAudio(h, kr1p, "out", ao1p, "in"); // kr->aout - 1
  662. if( ao2p != NULL )
  663. cmDspSysConnectAudio(h, wt0p,"out", ao2p, "in"); // wt->aout - 2
  664. if( ao3p != NULL )
  665. cmDspSysConnectAudio(h, wt0p,"out", ao3p, "in"); // wt->aout - 3
  666. cmDspSysConnectAudio(h, wt0p,"out", atp, "in"); // wt->meter
  667. cmDspSysInstallCb(h, ws0p, "out", kr0p, "wndn", NULL ); // wndSmpCnt->kr
  668. cmDspSysInstallCb(h, hf0p, "out", kr0p, "hopf", NULL ); // hopFact->kr
  669. cmDspSysInstallCb(h, md0p, "val", kr0p, "mode", NULL ); // mode->kr
  670. cmDspSysInstallCb(h, th0p, "val", kr0p, "thrh", NULL ); // thresh->kr
  671. cmDspSysInstallCb(h, ls0p, "val", kr0p, "lwrs", NULL ); // lwrSlope->kr
  672. cmDspSysInstallCb(h, us0p, "val", kr0p, "uprs", NULL ); // uprSlope->kr
  673. cmDspSysInstallCb(h, of0p, "val", kr0p, "offs", NULL ); // offset->kr
  674. cmDspSysInstallCb(h, iv0p, "val", kr0p, "invt", NULL ); // invert->kr
  675. cmDspSysInstallCb(h, th0p, "val", mtp, "in", NULL );
  676. cmDspSysInstallCb(h, ws1p, "out", kr1p, "wndn", NULL ); // wndSmpCnt->kr
  677. cmDspSysInstallCb(h, hf1p, "out", kr1p, "hopf", NULL ); // hopFact->kr
  678. cmDspSysInstallCb(h, md1p, "val", kr1p, "mode", NULL ); // mode->kr
  679. cmDspSysInstallCb(h, th1p, "val", kr1p, "thrh", NULL ); // thresh->kr
  680. cmDspSysInstallCb(h, ls1p, "val", kr1p, "lwrs", NULL ); // lwrSlope->kr
  681. cmDspSysInstallCb(h, us1p, "val", kr1p, "uprs", NULL ); // uprSlope->kr
  682. cmDspSysInstallCb(h, of1p, "val", kr1p, "offs", NULL ); // offset->kr
  683. cmDspSysInstallCb(h, iv1p, "val", kr1p, "invt", NULL ); // invert->kr
  684. cmDspSysInstallCb(h, dnp, "out", fn0p, "in-0", NULL); // dir->fn:0
  685. cmDspSysInstallCb(h, al0p, "out", fn0p, "in-1", NULL ); // fn->fn:1
  686. cmDspSysInstallCb(h, fl0p, "take", fn0p, "in-2", NULL ); // take->fn:2
  687. cmDspSysInstallCb(h, fn0p, "out", ro0p, "in-0", NULL); // fn->print
  688. cmDspSysInstallCb(h, fl0p, "beg", ro0p, "in-1", NULL); //
  689. cmDspSysInstallCb(h, fl0p, "end", ro0p, "in-2", NULL); //
  690. cmDspSysInstallCb(h, ro0p, "out-0", wt0p, "fn", NULL ); // fn->wt:fn
  691. cmDspSysInstallCb(h, ro0p, "out-1", wt0p, "beg", NULL ); // beg->wt:beg
  692. cmDspSysInstallCb(h, ro0p, "out-2", wt0p, "end", NULL ); // end->wt:end
  693. cmDspSysInstallCb(h, ro0p, "out-1", prp, "in", NULL ); //
  694. //cmDspSysInstallCb(h, dnp, "out", fn1p, "in-0", NULL); // dir->fn:0
  695. //cmDspSysInstallCb(h, al1p, "out", fn1p, "in-1", NULL ); // fn->fn:1
  696. //cmDspSysInstallCb(h, fl1p, "take", fn1p, "in-2", NULL ); // take->fn:2
  697. //cmDspSysInstallCb(h, fn1p, "out", ro1p, "in-0", NULL); // fn->print
  698. //cmDspSysInstallCb(h, fl1p, "beg", ro1p, "in-1", NULL); //
  699. //cmDspSysInstallCb(h, fl1p, "end", ro1p, "in-2", NULL); //
  700. //cmDspSysInstallCb(h, ro1p, "out-0", wt1p, "fn", NULL ); // fn->wt:fn
  701. //cmDspSysInstallCb(h, ro1p, "out-1", wt1p, "beg", NULL ); // beg->wt:beg
  702. //cmDspSysInstallCb(h, ro1p, "out-2", wt1p, "end", NULL ); // end->wt:end
  703. return cmDspSysLastRC(h);
  704. }
  705. cmDspRC_t _cmDspSysPgm_Pickups0( cmDspSysH_t h, void** userPtrPtr )
  706. {
  707. unsigned i;
  708. unsigned chCnt = 8;
  709. double delayFb = 0.0;
  710. double delayMaxMs = 1000.0;
  711. cmDspInst_t* chArray[chCnt];
  712. cmDspInst_t* m_mxWet = cmDspSysAllocInst(h,"Scalar", "Mstr Wet", 5, kNumberDuiId, 0.0, 2.0, 0.01, 1.0 );
  713. cmDspInst_t* m_mxDry = cmDspSysAllocInst(h,"Scalar", "Mstr Dry", 5, kNumberDuiId, 0.0, 2.0, 0.01, 1.0 );
  714. cmDspSysNewColumn(h,0);
  715. cmDspInst_t* m_lpByp = cmDspSysAllocInst(h,"Button", "Mstr Lp Byps", 2, kCheckDuiId, 0.0 );
  716. cmDspInst_t* m_lpRcd = cmDspSysAllocInst(h,"Button", "Mstr Lp Recd", 2, kCheckDuiId, 0.0 );
  717. cmDspInst_t* m_lpRat = cmDspSysAllocInst(h,"Scalar", "Mstr Lp Ratio", 5, kNumberDuiId, 0.0, 10.0, 0.01, 1.0 );
  718. cmDspSysNewColumn(h,0);
  719. cmDspInst_t* m_dlyByp = cmDspSysAllocInst(h,"Button", "Mstr Dly Byps", 2, kCheckDuiId, 0.0 );
  720. cmDspInst_t* m_dlyMs = cmDspSysAllocInst(h,"Scalar", "Mstr Dly Time", 5, kNumberDuiId, 0.0, delayMaxMs, 1.0, 0.0 );
  721. cmDspInst_t* m_dlyFb = cmDspSysAllocInst(h,"Scalar", "Mstr Dly Fb", 5, kNumberDuiId, 0.0, 0.999, 0.01, 0.0 );
  722. cmDspSysNewColumn(h,0);
  723. cmDspInst_t* m_psByp = cmDspSysAllocInst(h,"Button", "Mstr PS Byps", 2, kCheckDuiId, 0.0 );
  724. cmDspInst_t* m_psRat = cmDspSysAllocInst(h,"Scalar", "Mstr PS Ratio", 5, kNumberDuiId, 0.0, 10.0, 0.01, 1.0 );
  725. cmDspSysNewColumn(h,0);
  726. cmDspInst_t* m_rcByp = cmDspSysAllocInst(h,"Button", "Mstr Rect Byps", 2, kCheckDuiId, 0.0 );
  727. cmDspSysInsertHorzBorder(h);
  728. for(i=0; i<chCnt; ++i)
  729. {
  730. int chIdx = i;
  731. cmDspInst_t* mxWet = cmDspSysAllocInst(h,"Scalar", "Wet", 5, kNumberDuiId, 0.0, 2.0, 0.01, 1.0 );
  732. cmDspInst_t* mxDry = cmDspSysAllocInst(h,"Scalar", "Dry", 5, kNumberDuiId, 0.0, 2.0, 0.01, 1.0 );
  733. cmDspInst_t* lpByp = cmDspSysAllocInst(h,"Button", "Lp Byps", 2, kCheckDuiId, 0.0 );
  734. cmDspInst_t* lpRcd = cmDspSysAllocInst(h,"Button", "Lp Recd", 2, kCheckDuiId, 0.0 );
  735. cmDspInst_t* lpRat = cmDspSysAllocInst(h,"Scalar", "Lp Ratio", 5, kNumberDuiId, 0.0, 10.0, 0.01, 1.0 );
  736. cmDspInst_t* dlyByp = cmDspSysAllocInst(h,"Button", "Delay Byps", 2, kCheckDuiId, 0.0 );
  737. cmDspInst_t* dlyMs = cmDspSysAllocInst(h,"Scalar", "Delay Time", 5, kNumberDuiId, 0.0, delayMaxMs, 1.0, 0.0 );
  738. cmDspInst_t* dlyFb = cmDspSysAllocInst(h,"Scalar", "Delay Fb", 5, kNumberDuiId, 0.0, 0.999, 0.01, 0.0 );
  739. cmDspInst_t* psByp = cmDspSysAllocInst(h,"Button", "PS Byps", 2, kCheckDuiId, 0.0 );
  740. cmDspInst_t* psRat = cmDspSysAllocInst(h,"Scalar", "PS Ratio", 5, kNumberDuiId, 0.0, 10.0, 0.01, 1.0 );
  741. cmDspInst_t* rcByp = cmDspSysAllocInst(h,"Button", "Rect Byps", 2, kCheckDuiId, 0.0 );
  742. cmDspInst_t* ain = cmDspSysAllocInst(h, "AudioIn", NULL, 1, chIdx );
  743. cmDspInst_t* loop = cmDspSysAllocInst(h, "LoopRecd", NULL, 0 );
  744. cmDspInst_t* dely = cmDspSysAllocInst(h, "Delay", NULL, 2, delayMaxMs, delayFb );
  745. cmDspInst_t* pshf = cmDspSysAllocInst(h, "PShift", NULL, 0 );
  746. cmDspInst_t* rect = cmDspSysAllocInst(h, "Rectify", NULL, 0 );
  747. cmDspInst_t* amix = cmDspSysAllocInst(h, "AMix", NULL, 1, 2 );
  748. //cmDspInst_t* aout = cmDspSysAllocInst(h, "AudioOut", NULL, 1, chIdx );
  749. chArray[i] = amix;
  750. cmDspSysNewColumn(h,0);
  751. cmDspSysConnectAudio(h, ain, "out", loop, "in"); // ain -> loop
  752. cmDspSysConnectAudio(h, loop, "out", dely, "in"); // loop -> delay
  753. cmDspSysConnectAudio(h, dely, "out", pshf, "in"); // delay -> pshf
  754. cmDspSysConnectAudio(h, pshf, "out", rect, "in"); // pshf -> rect
  755. cmDspSysConnectAudio(h, rect, "out", amix, "in-0"); // rect -> mix_wet
  756. cmDspSysConnectAudio(h, ain, "out", amix, "in-1"); // ain -> mix_dry
  757. //cmDspSysConnectAudio(h, amix, "out", aout, "in"); // mix -> out
  758. cmDspSysInstallCb(h, mxWet, "val", amix, "gain-0", NULL );
  759. cmDspSysInstallCb(h, mxDry, "val", amix, "gain-1", NULL );
  760. cmDspSysInstallCb(h, lpByp, "out", loop, "bypass", NULL );
  761. cmDspSysInstallCb(h, lpRcd, "out", loop, "recd", NULL );
  762. cmDspSysInstallCb(h, lpRat, "val", loop, "ratio", NULL );
  763. cmDspSysInstallCb(h, dlyByp,"val", dely, "bypass", NULL );
  764. cmDspSysInstallCb(h, dlyMs, "val", dely, "time", NULL );
  765. cmDspSysInstallCb(h, dlyFb, "out", dely, "fb", NULL );
  766. cmDspSysInstallCb(h, psByp, "out", pshf, "bypass", NULL );
  767. cmDspSysInstallCb(h, psRat, "val", pshf, "ratio", NULL );
  768. cmDspSysInstallCb(h, rcByp, "out", rect, "bypass", NULL );
  769. cmDspSysInstallCb(h, m_mxWet, "val", mxWet, "in", NULL );
  770. cmDspSysInstallCb(h, m_mxDry, "val", mxDry, "in", NULL );
  771. cmDspSysInstallCb(h, m_lpByp, "out", lpByp, "in", NULL );
  772. cmDspSysInstallCb(h, m_lpRcd, "out", lpRcd, "in", NULL );
  773. cmDspSysInstallCb(h, m_lpRat, "val", lpRat, "in", NULL );
  774. cmDspSysInstallCb(h, m_dlyByp,"out", dlyByp,"in", NULL );
  775. cmDspSysInstallCb(h, m_dlyMs, "val", dlyMs, "in", NULL );
  776. cmDspSysInstallCb(h, m_dlyFb, "val", dlyFb, "in", NULL );
  777. cmDspSysInstallCb(h, m_psByp, "out", psByp, "in", NULL );
  778. cmDspSysInstallCb(h, m_psRat, "val", psRat, "in", NULL );
  779. cmDspSysInstallCb(h, m_rcByp, "out", rcByp, "in", NULL );
  780. }
  781. double dfltGain = 0.5;
  782. cmDspInst_t* omix = cmDspSysAllocInst(h, "AMix", NULL, 9, 8, dfltGain, dfltGain, dfltGain, dfltGain, dfltGain, dfltGain, dfltGain, dfltGain );
  783. cmDspInst_t* aout0 = cmDspSysAllocInst(h, "AudioOut", NULL, 1, 0 );
  784. cmDspInst_t* aout1 = cmDspSysAllocInst(h, "AudioOut", NULL, 1, 1 );
  785. cmDspInst_t* aout2 = cmDspSysAllocInst(h, "AudioOut", NULL, 1, 2 );
  786. cmDspInst_t* aout3 = cmDspSysAllocInst(h, "AudioOut", NULL, 1, 3 );
  787. for(i=0; i<chCnt; ++i)
  788. {
  789. char label[32];
  790. snprintf(label,32,"in-%i",i);
  791. cmDspSysConnectAudio(h, chArray[i], "out", omix, label);
  792. }
  793. cmDspSysConnectAudio(h, omix, "out", aout0, "in");
  794. cmDspSysConnectAudio(h, omix, "out", aout1, "in");
  795. cmDspSysConnectAudio(h, omix, "out", aout2, "in");
  796. cmDspSysConnectAudio(h, omix, "out", aout3, "in");
  797. return kOkDspRC;
  798. }
  799. #include "cmAudioFile.h"
  800. #include "cmProcObj.h"
  801. #include "cmProc.h"
  802. #include "cmProc3.h"
  803. // Usage:
  804. // 1) Push 'start'.
  805. // 2) Select the first element in the Ch Cfg List UI.
  806. // 3) Play several examples of the note.
  807. // 4) Select the next element in the Ch Cfg List UI.
  808. // 5) Go to 3) until all ch's have been played.
  809. // 6) Push 'proc'. A new set of gains will be calc'd and sent to the audio input channels.
  810. // Note that if a mistake is made while playing a set of notes in 3) then
  811. // push select the same element from the list again and replay.
  812. // The order the notes are played in does not make any difference.
  813. cmDspRC_t _cmDspSysPgm_AutoGain( cmDspSysH_t h, void** userPtrPtr )
  814. {
  815. cmDspRC_t rc = kOkDspRC;
  816. unsigned i;
  817. //unsigned j;
  818. cmErr_t err;
  819. const cmChar_t* errLabelPtr = NULL;
  820. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  821. unsigned chCnt = 0;
  822. unsigned nsChCnt = 0;
  823. const cmChar_t* chCfgFn = NULL;
  824. const cmChar_t* chCfgPath = NULL;
  825. unsigned agMedCnt = 5;
  826. unsigned agAvgCnt = 9;
  827. unsigned agSuprCnt = 3;
  828. unsigned agOffCnt = 3;
  829. cmReal_t agSuprCoeff = 1.4;
  830. cmReal_t agOnThreshDb = -53.0;
  831. cmReal_t agOffThreshDb = -80.0;
  832. cmReal_t agHopMs = 25;
  833. //cmReal_t cdMaxTimeSpanMs = 50;
  834. //cmReal_t cdMinNoteCnt = 3;
  835. unsigned labelCharCnt = 31;
  836. char label0[ labelCharCnt + 1];
  837. cmErrSetup(&err,&cmCtx->rpt,"Auto-gain");
  838. // get the name of channel cfg file
  839. if( cmJsonPathValues( cmDspSysPgmRsrcHandle(h),"cfg/",NULL,&errLabelPtr,
  840. "chCfgFn", kStringTId, &chCfgFn,
  841. "agParms/hopMs", kRealTId, &agHopMs,
  842. "agParms/medCnt", kIntTId, &agMedCnt,
  843. "agParms/avgCnt", kIntTId, &agAvgCnt,
  844. "agParms/suprCnt", kIntTId, &agSuprCnt,
  845. "agParms/offCnt", kIntTId, &agOffCnt,
  846. "agParms/suprCoeff", kRealTId, &agSuprCoeff,
  847. "agParms/onThreshDb", kRealTId, &agOnThreshDb,
  848. "agParms/offThreshDb", kRealTId, &agOffThreshDb,
  849. NULL) != kOkJsRC )
  850. {
  851. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"An error occurred while reading the required auto-tune JSON parameters.");
  852. goto errLabel;
  853. }
  854. // get the count of channels from the ch. cfg. array
  855. if(( chCnt = cmChCfgChannelCount(cmCtx,chCfgFn,&nsChCnt)) == 0 )
  856. {
  857. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"Unable to obtain the channel count from '%s'.",cmStringNullGuard(chCfgFn));
  858. goto errLabel;
  859. }
  860. // prepend the prefs directory to the ch. cfg filename
  861. chCfgPath = cmFsMakeFn(cmFsPrefsDir(),chCfgFn,NULL,NULL);
  862. if( rc == kOkDspRC )
  863. {
  864. //mDspInst_t* ain[chCnt];
  865. cmDspInst_t* ef[chCnt];
  866. cmDspInst_t* mtr[chCnt];
  867. cmDspInst_t* amtr[chCnt];
  868. cmDspInst_t* on[chCnt];
  869. cmDspInst_t* off[chCnt];
  870. cmDspInst_t* rms[chCnt];
  871. ///cmDspInst_t* fdr0[chCnt];
  872. ///cmDspInst_t* fdr1[chCnt];
  873. ///cmDspInst_t* fdr2[chCnt];
  874. // allocate the audio inputs
  875. //for(i=0; i<chCnt; ++i)
  876. // ain[i] = cmDspSysAllocAudioIn(h,i,1.0);
  877. unsigned inChCnt;
  878. cmDspInst_t** ain = cmDspSysAllocAudioInAR( h, "audioInMap", 1.0, &inChCnt );
  879. // allocate the auto-gain calibration object
  880. cmDspInst_t* ag = cmDspSysAllocInst( h, "AutoGain", NULL, 9, chCnt, agHopMs,agMedCnt,agAvgCnt,agSuprCnt,agOffCnt,agSuprCoeff,agOnThreshDb,agOffThreshDb );
  881. // allocate the command buttons
  882. cmDspInst_t* start = cmDspSysAllocButton(h, "start", 0);
  883. cmDspInst_t* proc = cmDspSysAllocButton(h, "proc", 0);
  884. cmDspInst_t* cancel = cmDspSysAllocButton(h, "cancel", 0);
  885. cmDspInst_t* write = cmDspSysAllocButton(h, "write", 0);
  886. cmDspInst_t* print = cmDspSysAllocButton(h, "print", 0);
  887. cmDspInst_t* chMenu = cmDspSysAllocMsgList(h, chCfgPath, "ch_array", 0 );
  888. cmDspInst_t* onThr = cmDspSysAllocScalar(h,"On Thresh",-100.0,0.0,0.1,-45.0);
  889. cmDspInst_t* offThr = cmDspSysAllocScalar(h,"Off Thresh",-100.0,0.0,0.1,-80.0);
  890. //cmDspInst_t* prt = cmDspSysAllocInst(h,"Printer",NULL,1,"ag>");
  891. cmDspInst_t* sub = cmDspSysAllocInst(h,"ScalarOp",NULL,6,2,"+","in-0",0.0,"in-1",-1.0);
  892. cmDspSysNewColumn(h,200);
  893. cmDspSysAllocLabel(h,"EF Gate",kLeftAlignDuiId);
  894. // allocate the envelope followers and meters
  895. for(i=0; i<chCnt; ++i )
  896. {
  897. snprintf(label0,labelCharCnt,"%2i",i);
  898. ef[i] = cmDspSysAllocInst( h, "EnvFollow", NULL, 0 );
  899. mtr[i] = cmDspSysAllocInst( h, "Meter",label0, 3, 0.0, 0.0, 1.0 );
  900. }
  901. cmDspSysNewColumn(h,200);
  902. cmDspSysAllocLabel(h,"Audio",kLeftAlignDuiId);
  903. // allocate the envelope followers and meters
  904. for(i=0; i<chCnt; ++i )
  905. {
  906. amtr[i] = cmDspSysAllocInst( h, "AMeter", NULL, 0 );
  907. }
  908. // chord detector, note selector, mix0, mix1, mix2
  909. ///cmDspInst_t* cdp = cmDspSysAllocInst(h, "ChordDetect", NULL, 1, "cdSel" );
  910. ///cmDspInst_t* nsp = cmDspSysAllocInst(h, "NoteSelect", NULL, 1, chCnt );
  911. // onset count display
  912. cmDspSysNewColumn(h,150);
  913. cmDspSysAllocLabel(h,"Onsets",kLeftAlignDuiId);
  914. for(i=0; i<chCnt; ++i)
  915. on[i] = cmDspSysAllocScalar(h,NULL,0,1,0,0);
  916. // offset count display
  917. cmDspSysNewColumn(h,150);
  918. cmDspSysAllocLabel(h,"Offsets",kLeftAlignDuiId);
  919. for(i=0; i<chCnt; ++i)
  920. off[i] = cmDspSysAllocScalar(h,NULL,0,1,0,0);
  921. // offset count display
  922. cmDspSysNewColumn(h,150);
  923. cmDspSysAllocLabel(h,"RMS",kLeftAlignDuiId);
  924. for(i=0; i<chCnt; ++i)
  925. rms[i] = cmDspSysAllocScalar(h,NULL,0,1,0,0);
  926. /*
  927. // note select gate meters
  928. for(j=0; j<3; ++j)
  929. {
  930. snprintf(label0,labelCharCnt,"Set %i",j);
  931. cmDspSysNewColumn(h,50);
  932. cmDspSysAllocLabel(h,label0,kLeftAlignDuiId );
  933. for(i=0; i<chCnt; ++i)
  934. {
  935. cmDspInst_t* m = cmDspSysAllocInst(h, "Meter", NULL, 3, 0.0, 0.0, 1.0 );
  936. switch(j)
  937. {
  938. case 0: fdr0[i] = m; break;
  939. case 1: fdr1[i] = m; break;
  940. case 2: fdr2[i] = m; break;
  941. }
  942. }
  943. }
  944. // chord detector parameters
  945. cmDspSysNewColumn(h,150);
  946. cmDspSysAllocLabel(h,"Chord Detector",kLeftAlignDuiId);
  947. cmDspInst_t* cdSpanMs = cmDspSysAllocScalar(h,"Span Ms", 10.0,1000.0,1.0,cdMaxTimeSpanMs);
  948. cmDspInst_t* cdNoteCnt = cmDspSysAllocScalar(h,"Note Cnt", 1.0, 100.0,1.0,cdMinNoteCnt );
  949. cmDspInst_t* cdCount = cmDspSysAllocScalar(h,"Ch. Count", 0,1,0,0);
  950. */
  951. // allocate an audio mixer and two audio output channels
  952. cmDspInst_t* amix = cmDspSysAllocInst( h, "AMix", NULL, 1, chCnt);
  953. cmDspInst_t* ao0 = cmDspSysAllocAudioOut(h,0,1.0);
  954. cmDspInst_t* ao1 = cmDspSysAllocAudioOut(h,1,1.0);
  955. // alloc chCfg last so that it's default outputs are applied to connected objects
  956. cmDspInst_t* chCfg = cmDspSysAllocInst( h, "ChCfg", NULL, 1, chCfgFn );
  957. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  958. goto errLabel;
  959. cmDspSysConnectAudioN11N(h,ain, "out", ag, "in", chCnt); // ain -> auto gain
  960. cmDspSysConnectAudioN11N(h,ain, "out", amix, "in", chCnt); // ain -> amix
  961. cmDspSysConnectAudioN1N1(h,ain, "out", ef, "in", chCnt); // ain -> EF
  962. cmDspSysConnectAudioN1N1(h, ain, "out", amtr, "in",chCnt);
  963. cmDspSysInstallCb1N1N(h, ag, "gain", chCfg, "gain", chCnt ); // ag -> chCfg (gain)
  964. cmDspSysInstallCb1NN1(h, chCfg, "gain", ain, "gain", chCnt ); // cgCfg -> ain (gain)
  965. cmDspSysInstallCb1NN1(h, chCfg, "ch", ain, "ch", chCnt ); // cgCfg -> ain (ch)
  966. cmDspSysInstallCbN1N1(h, ef, "gate", mtr, "in", chCnt ); // EF gate -> meter
  967. cmDspSysInstallCb11N1(h, onThr, "val", ef, "ondb", chCnt ); //
  968. cmDspSysInstallCb11N1(h, offThr, "val", ef, "offdb", chCnt ); //
  969. cmDspSysInstallCbN1N1(h, ef, "ons", on, "val", chCnt ); // EF -> onset count
  970. cmDspSysInstallCbN1N1(h, ef, "offs", off, "val", chCnt ); // EF -> offset count
  971. cmDspSysInstallCbN1N1(h, ef, "rms", rms, "val", chCnt );
  972. ///cmDspSysInstallCbN11N(h, ef, "gate", cdp, "gate", chCnt ); // EF -> CD gate
  973. ///cmDspSysInstallCbN11N(h, ef, "rms", cdp, "rms", chCnt ); // EF -> CD rms
  974. ///cmDspSysInstallCb1N1N(h, cdp, "gate", nsp, "gate", chCnt ); // CD -> NS gate
  975. ///cmDspSysInstallCb1N1N(h, cdp, "rms", nsp, "rms", chCnt ); // CD -> NS rms
  976. ///cmDspSysInstallCb1NN1(h, nsp, "gate-0",fdr0, "in", chCnt ); // NS -> Fader 0 gate
  977. ///cmDspSysInstallCb1NN1(h, nsp, "gate-1",fdr1, "in", chCnt ); // NS -> Fader 1 gate
  978. ///cmDspSysInstallCb1NN1(h, nsp, "gate-2",fdr2, "in", chCnt ); // NS -> Fader 2 gate
  979. cmDspSysConnectAudio(h, amix, "out", ao0, "in"); // amix -> aout 0
  980. cmDspSysConnectAudio(h, amix, "out", ao1, "in"); // amix -> aout 1
  981. //cmDspSysInstallCb(h, chMenu, "ch", ag, "id", NULL );
  982. cmDspSysInstallCb(h, chMenu, "sel", sub, "in-0", NULL );
  983. cmDspSysInstallCb(h, sub, "out", ag, "id", NULL );
  984. cmDspSysInstallCb(h, start, "sym", ag, "sel", NULL );
  985. cmDspSysInstallCb(h, proc, "sym", ag, "sel", NULL );
  986. cmDspSysInstallCb(h, cancel, "sym", ag, "sel", NULL );
  987. cmDspSysInstallCb(h, print, "sym", ag, "sel", NULL );
  988. cmDspSysInstallCb(h, print, "sym", chCfg, "sel", NULL );
  989. cmDspSysInstallCb(h, write, "sym", chCfg, "sel", NULL );
  990. /*
  991. cmDspSysInstallCb(h, cdSpanMs, "val", cdp, "span", NULL );
  992. cmDspSysInstallCb(h, cdNoteCnt, "val", cdp, "notes", NULL );
  993. cmDspSysInstallCb(h, cdp, "count", cdCount, "val", NULL );
  994. cmDspSysInstallCb(h, cdp, "detect", nsp, "trig", NULL );
  995. */
  996. }
  997. errLabel:
  998. cmFsFreeFn(chCfgPath);
  999. return rc;
  1000. }
  1001. cmDspRC_t _cmDspSysPgm_PickupFxFile( cmDspSysH_t h, void** userPtrPtr )
  1002. {
  1003. cmDspRC_t rc = kOkDspRC;
  1004. cmErr_t err;
  1005. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  1006. unsigned chCnt = 0;
  1007. unsigned nsChCnt = 0;
  1008. const cmChar_t* chCfgPath = NULL;
  1009. const cmChar_t* chCfgFn = "pick_chs8.js";
  1010. double cfMinHz = 20.0;
  1011. double cfAlpha = 0.9;
  1012. bool cfFbFl = true;
  1013. unsigned sgShapeId = 2;
  1014. const cmChar_t* afn = "/home/kevin/media/audio/gate_detect/gate_detect0.aif";
  1015. unsigned abeg[] = { 9.842046, 18.838291, 27.007957, 35.562079, 45.461793, 52.920218, 60.436312, 68.913543};
  1016. unsigned aend[] = {11.399088, 20.645229, 28.891786, 37.311349, 47.287954, 54.131251, 62.473923, 72.142964};
  1017. bool cfBypassFl = false;
  1018. unsigned i;
  1019. cmErrSetup(&err,&cmCtx->rpt,"Pickup Effects");
  1020. // prepend the prefs directory to the ch. cfg filename
  1021. chCfgPath = cmFsMakeFn(cmFsPrefsDir(),chCfgFn,NULL,NULL);
  1022. // get the count of channels from the ch. cfg. array
  1023. if(( chCnt = cmChCfgChannelCount(cmCtx,chCfgFn,&nsChCnt)) == 0 )
  1024. {
  1025. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"Unable to obtain the channel count from '%s'.",cmStringNullGuard(chCfgFn));
  1026. goto errLabel;
  1027. }
  1028. if( rc == kOkDspRC )
  1029. {
  1030. cmDspInst_t* af[chCnt];
  1031. //cmDspInst_t* aout[chCnt];
  1032. cmDspInst_t* ef[chCnt];
  1033. cmDspInst_t* cf[chCnt];
  1034. cmDspInst_t* sg[chCnt];
  1035. cmDspInst_t* mtr[chCnt];
  1036. cmDspInst_t* mute[chCnt];
  1037. cmDspInst_t* phs = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  1038. // allocate the audio inputs
  1039. for(i=0; i<chCnt; ++i)
  1040. {
  1041. unsigned labelCharCnt = 31;
  1042. cmChar_t label[labelCharCnt+1];
  1043. snprintf(label,labelCharCnt,"%i",i);
  1044. int sbeg = floor(abeg[i] * cmDspSysSampleRate(h));
  1045. int send = floor(aend[i] * cmDspSysSampleRate(h));
  1046. //ain[i] = cmDspSysAllocAudioIn( h,i,1.0);
  1047. af[i] = cmDspSysAllocInst(h,"WaveTable",NULL, 6, ((int)cmDspSysSampleRate(h)), 1, afn, -1, sbeg, send );
  1048. //aout[i] = cmDspSysAllocAudioOut(h,i,1.0);
  1049. ef[i] = cmDspSysAllocInst(h, "EnvFollow", NULL, 0 );
  1050. sg[i] = cmDspSysAllocInst(h, "SigGen", NULL, 2, 1000.0, sgShapeId );
  1051. cf[i] = cmDspSysAllocInst(h, "CombFilt", NULL, 5, cfBypassFl, cfMinHz, cfFbFl, cfMinHz, cfAlpha );
  1052. mtr[i] = cmDspSysAllocInst( h, "Meter",label, 3, 0.0, 0.0, 1.0 );
  1053. }
  1054. // allocate the ch cfg last so that it's default outputs initialize connected objects
  1055. cmDspInst_t* chCfg = cmDspSysAllocInst( h, "ChCfg", NULL, 1, chCfgFn );
  1056. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL, 1, chCnt );
  1057. cmDspSysNewColumn(h,50);
  1058. for(i=0; i<chCnt; ++i)
  1059. mute[i] = cmDspSysAllocCheck(h,"",0);
  1060. // checkk for allocation errors
  1061. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1062. goto errLabel;
  1063. //
  1064. //cmDspSysConnectAudioN1N1(h, ain, "out", aout, "in", chCnt );
  1065. cmDspSysConnectAudio11N1(h, phs, "out", af, "phs", chCnt );
  1066. cmDspSysConnectAudioN1N1(h, af, "out", ef, "in", chCnt ); // af -> EF
  1067. cmDspSysConnectAudioN1N1(h, sg, "out", cf, "in", chCnt ); // sg -> CF
  1068. cmDspSysConnectAudioN11N(h, cf, "out", mix, "in", chCnt ); // CF -> mix
  1069. //cmDspSysInstallCb1NN1( h, chCfg, "gain", ain, "gain", chCnt ); // chCfg -> ain gain
  1070. cmDspSysInstallCb1NN1( h, chCfg, "hz", cf, "hz", chCnt ); // chCfg -> CF Hz
  1071. //cmDspSysInstallCbN1N1( h, ef, "rms", aout, "gain", chCnt ); // EF -> aout gain
  1072. cmDspSysInstallCbN1N1( h, ef, "rms", mtr, "in", chCnt ); // EF -> meter RMS
  1073. cmDspSysInstallCbN11N( h, ef, "rms", mix, "gain", chCnt );
  1074. cmDspSysInstallCbN11N( h, mute, "out", mix, "mute", chCnt ); // mute -> mix
  1075. }
  1076. errLabel:
  1077. cmFsFreeFn(chCfgPath);
  1078. return rc;
  1079. }
  1080. cmDspRC_t _cmDspSysPgm_NoiseTails( cmDspSysH_t h, void** userPtrPtr )
  1081. {
  1082. cmDspRC_t rc = kOkDspRC;
  1083. cmErr_t err;
  1084. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  1085. unsigned chCnt = 0;
  1086. unsigned nsChCnt = 0;
  1087. const cmChar_t* chCfgPath = NULL;
  1088. const cmChar_t* chCfgFn = "pick_chs8.js";
  1089. double cfMinHz = 20.0;
  1090. double cfHz = 500;
  1091. double cfAlpha = 0.9;
  1092. bool cfFbFl = true;
  1093. bool cfBypassFl= false;
  1094. unsigned sgShapeId = 3;
  1095. double dfltDelayMs = 100;
  1096. unsigned i;
  1097. cmErrSetup(&err,&cmCtx->rpt,"Noise Tails");
  1098. // prepend the prefs directory to the ch. cfg filename
  1099. chCfgPath = cmFsMakeFn(cmFsPrefsDir(),chCfgFn,NULL,NULL);
  1100. // get the count of channels from the ch. cfg. array
  1101. if(( chCnt = cmChCfgChannelCount(cmCtx,chCfgFn,&nsChCnt)) == 0 )
  1102. {
  1103. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"Unable to obtain the channel count from '%s'.",cmStringNullGuard(chCfgFn));
  1104. goto errLabel;
  1105. }
  1106. if( rc == kOkDspRC )
  1107. {
  1108. cmDspInst_t* ain[chCnt];
  1109. cmDspInst_t* ef[chCnt];
  1110. cmDspInst_t* cf[chCnt];
  1111. cmDspInst_t* sg[chCnt];
  1112. cmDspInst_t* mtr[chCnt];
  1113. cmDspInst_t* add[chCnt];
  1114. cmDspInst_t* mul[chCnt];
  1115. cmDspInst_t* dly[chCnt];
  1116. // allocate the audio inputs
  1117. for(i=0; i<chCnt; ++i)
  1118. {
  1119. unsigned labelCharCnt = 31;
  1120. cmChar_t label[labelCharCnt+1];
  1121. snprintf(label,labelCharCnt,"%i",i);
  1122. ain[i] = cmDspSysAllocAudioIn( h, i, 1.0);
  1123. ef[i] = cmDspSysAllocInst( h, "EnvFollow", NULL, 0 );
  1124. sg[i] = cmDspSysAllocInst( h, "SigGen", NULL, 2, 1000.0, sgShapeId );
  1125. cf[i] = cmDspSysAllocInst( h, "CombFilt", NULL, 5, cfBypassFl, cfMinHz, cfFbFl, cfHz, cfAlpha );
  1126. mtr[i] = cmDspSysAllocInst( h, "Meter",label, 3, 0.0, 0.0, 1.0 );
  1127. add[i] = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "+", "in-0", 0.0, "in-1", 0.0);
  1128. mul[i] = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "*", "in-0", 0.0, "in-1", 0.99);
  1129. dly[i] = cmDspSysAllocInst( h, "MsgDelay", NULL, 2, 1000, dfltDelayMs );
  1130. }
  1131. // allocate the ch cfg last so that it's default outputs initialize connected objects
  1132. cmDspInst_t* chCfg = cmDspSysAllocInst( h, "ChCfg", NULL, 1, chCfgFn );
  1133. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL, 1, chCnt );
  1134. cmDspInst_t* ao0 = cmDspSysAllocAudioOut( h, 0, 1.0 );
  1135. cmDspInst_t* ao1 = cmDspSysAllocAudioOut( h, 1, 1.0 );
  1136. cmDspInst_t* alpha = cmDspSysAllocScalar( h, "alpha", -1.0, 1.0, 0.001, cfAlpha );
  1137. cmDspInst_t* decay = cmDspSysAllocScalar( h, "decay", -1.0, 1.0, 0.001, 0.5);
  1138. cmDspInst_t* delay = cmDspSysAllocScalar( h, "delay", 0.0, 1000.0, 1.0, dfltDelayMs );
  1139. cmDspInst_t* zero = cmDspSysAllocScalar( h, "zero", 0.0, 0.0, 0.0, 0.0);
  1140. // check for allocation errors
  1141. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1142. goto errLabel;
  1143. cmDspSysConnectAudioN1N1( h, ain, "out", ef, "in", chCnt ); // ain -> EF
  1144. cmDspSysConnectAudioN1N1( h, sg, "out", cf, "in", chCnt ); // sg -> CF
  1145. cmDspSysConnectAudioN11N( h, cf, "out", mix, "in", chCnt ); // cf -> mix
  1146. cmDspSysConnectAudio( h, mix, "out", ao0, "in"); // mix -> aout L
  1147. cmDspSysConnectAudio( h, mix, "out", ao1, "in"); // mix -> aout R
  1148. cmDspSysInstallCb1NN1( h, chCfg, "gain", ain, "gain", chCnt ); // chCfg -> ain gain
  1149. cmDspSysInstallCb1NN1( h, chCfg, "hz", cf, "hz", chCnt ); // chCfg -> CF Hz
  1150. cmDspSysInstallCbN1N1( h, ef, "rms", add, "in-0", chCnt ); // EF -> mul 0
  1151. cmDspSysInstallCbN1N1( h, mul, "out", add, "in-1", chCnt ); // mul -> add
  1152. cmDspSysInstallCbN1N1( h, add, "out", dly, "in", chCnt ); // add -> delay
  1153. cmDspSysInstallCbN11N( h, dly, "out", mix, "gain", chCnt ); // delay -> mix gain
  1154. cmDspSysInstallCbN1N1( h, add, "out", mul, "in-0", chCnt); // add -> mul (feedback)
  1155. cmDspSysInstallCb11N1( h, decay, "val", mul, "in-1", chCnt ); // decay ctl
  1156. cmDspSysInstallCbN1N1( h, ef, "gate", mtr, "in", chCnt ); // EF -> meter RMS
  1157. cmDspSysInstallCb11N1( h, alpha, "val", cf, "alpha",chCnt ); // CF alpha
  1158. cmDspSysInstallCb11N1( h, delay, "val", dly, "delay",chCnt ); // Delay ctl
  1159. cmDspSysInstallCb111N( h, zero, "val", mix, "in", chCnt ); //
  1160. }
  1161. errLabel:
  1162. cmFsFreeFn(chCfgPath);
  1163. return rc;
  1164. }
  1165. cmDspRC_t _cmDspSysPgm_NoiseTails2( cmDspSysH_t h, void** userPtrPtr )
  1166. {
  1167. cmDspRC_t rc = kOkDspRC;
  1168. cmErr_t err;
  1169. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  1170. unsigned chCnt = 0;
  1171. unsigned nsChCnt = 0;
  1172. const cmChar_t* chCfgPath = NULL;
  1173. const cmChar_t* chCfgFn = "pick_chs8.js";
  1174. double cfMinHz = 20.0;
  1175. double cfHz = 500;
  1176. double cfAlpha = 0.9;
  1177. bool cfFbFl = true;
  1178. bool cfBypassFl = false;
  1179. unsigned sgShapeId = 3;
  1180. double adsrMaxMs = 10000;
  1181. double adsrMinMs = 0;
  1182. double adsrIncMs = 1;
  1183. double adsrMaxLevel = 100.0;
  1184. double adsrSusLevel = 100.0;
  1185. double adsrMinLevel = 0.0;
  1186. double adsrIncLevel = 0.001;
  1187. bool eqBypassFl = false;
  1188. unsigned eqModeSymId = cmSymTblRegisterStaticSymbol(cmDspSysSymbolTable(h),"LP");
  1189. double eqF0hz = 250;
  1190. double eqQ = 1.0;
  1191. double eqFgain = 1.0;
  1192. bool mtBypassFl = false;
  1193. double mtTimeScale= 1.0;
  1194. double mtFeedback = 0.0;
  1195. unsigned i;
  1196. cmErrSetup(&err,&cmCtx->rpt,"Noise Tails");
  1197. // prepend the prefs directory to the ch. cfg filename
  1198. chCfgPath = cmFsMakeFn(cmFsPrefsDir(),chCfgFn,NULL,NULL);
  1199. // get the count of channels from the ch. cfg. array
  1200. if(( chCnt = cmChCfgChannelCount(cmCtx,chCfgFn,&nsChCnt)) == 0 )
  1201. {
  1202. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"Unable to obtain the channel count from '%s'.",cmStringNullGuard(chCfgFn));
  1203. goto errLabel;
  1204. }
  1205. if( rc == kOkDspRC )
  1206. {
  1207. cmDspInst_t* ain[chCnt];
  1208. cmDspInst_t* ef[chCnt];
  1209. cmDspInst_t* cf[chCnt];
  1210. cmDspInst_t* sg[chCnt];
  1211. cmDspInst_t* mtr[chCnt];
  1212. cmDspInst_t* add[chCnt];
  1213. cmDspInst_t* mul[chCnt];
  1214. cmDspInst_t* env[chCnt];
  1215. cmDspInst_t* d2l[chCnt];
  1216. cmDspInst_t* eq[chCnt];
  1217. cmDspInst_t* mt[chCnt];
  1218. // allocate the audio inputs
  1219. for(i=0; i<chCnt; ++i)
  1220. {
  1221. unsigned labelCharCnt = 31;
  1222. cmChar_t label[labelCharCnt+1];
  1223. snprintf(label,labelCharCnt,"%i",i);
  1224. ain[i] = cmDspSysAllocAudioIn( h, i, 1.0);
  1225. ef[i] = cmDspSysAllocInst( h, "EnvFollow", NULL, 0 );
  1226. sg[i] = cmDspSysAllocInst( h, "SigGen", NULL, 2, 1000.0, sgShapeId );
  1227. cf[i] = cmDspSysAllocInst( h, "CombFilt", NULL, 5, cfBypassFl, cfMinHz, cfFbFl, cfHz, cfAlpha );
  1228. mtr[i] = cmDspSysAllocInst( h, "Meter",label, 3, 0.0, 0.0, 1.0 );
  1229. env[i] = cmDspSysAllocInst( h, "Adsr", NULL, 2, true, adsrMinLevel );
  1230. d2l[i] = cmDspSysAllocInst( h, "DbToLin", NULL, 0 );
  1231. add[i] = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "+", "in-0", 0.0, "in-1", 0.0);
  1232. mul[i] = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "*", "in-0", 0.0, "in-1", 0.99);
  1233. eq[i] = cmDspSysAllocInst( h, "BiQuadEq", NULL, 5, eqBypassFl, eqModeSymId, eqF0hz, eqQ, eqFgain );
  1234. mt[i] = cmDspSysAllocInst( h, "MtDelay", NULL, 9, mtBypassFl, mtTimeScale, mtFeedback, 20.0, 0.8, 15.0, 0.9, 12.0, 0.9 );
  1235. }
  1236. // allocate the ch cfg last so that it's default outputs initialize connected objects
  1237. cmDspInst_t* chCfg = cmDspSysAllocInst( h, "ChCfg", NULL, 1, chCfgFn );
  1238. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL, 1, chCnt );
  1239. cmDspInst_t* ao0 = cmDspSysAllocAudioOut( h, 0, 1.0 );
  1240. cmDspInst_t* ao1 = cmDspSysAllocAudioOut( h, 1, 1.0 );
  1241. cmDspInst_t* alpha = cmDspSysAllocScalar( h, "alpha", -1.0, 1.0, 0.001, cfAlpha );
  1242. cmDspInst_t* decay = cmDspSysAllocScalar( h, "decay", -1.0, 1.0, 0.001, 0.5);
  1243. cmDspInst_t* zero = cmDspSysAllocScalar( h, "zero", 0.0, 0.0, 0.0, 0.0);
  1244. // cmDspInst_t* print = cmDspSysAllocButton( h, "print", 0 );
  1245. cmDspSysNewColumn(h,200);
  1246. cmDspInst_t* dly = cmDspSysAllocScalar( h, "Dly Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 0.0);
  1247. cmDspInst_t* atk = cmDspSysAllocScalar( h, "Atk Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 2000.0);
  1248. cmDspInst_t* dcy = cmDspSysAllocScalar( h, "Dcy Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 100.0);
  1249. cmDspInst_t* hold = cmDspSysAllocScalar( h, "Hold Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 100.0);
  1250. cmDspInst_t* rls = cmDspSysAllocScalar( h, "Rls Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 4000.0);
  1251. cmDspInst_t* alvl = cmDspSysAllocScalar( h, "AdsrMax", adsrMinLevel,adsrMaxLevel,adsrIncLevel, adsrMaxLevel);
  1252. cmDspInst_t* sus = cmDspSysAllocScalar( h, "Sustain", adsrMinLevel,adsrMaxLevel,adsrIncLevel, adsrSusLevel );
  1253. cmDspSysNewColumn(h,200);
  1254. cmDspInst_t* onThr = cmDspSysAllocScalar(h,"On Thresh",-100.0,0.0,0.1,-55.0);
  1255. cmDspInst_t* offThr = cmDspSysAllocScalar(h,"Off Thresh",-100.0,0.0,0.1,-80.0);
  1256. cmDspInst_t* eqbyp = cmDspSysAllocCheck( h, "Eq Byp", 0 );
  1257. cmDspInst_t* eqmode = cmDspSysAllocInst( h, "MsgList","Mode", 1, "biQuadEqMode");
  1258. cmDspInst_t* eqq = cmDspSysAllocScalar( h, "Q", -100.0, 100.0, 0.1, eqQ);
  1259. cmDspInst_t* eqfgn = cmDspSysAllocScalar( h, "Filt Gain", 0.0, 1.0, 0.1, eqFgain);
  1260. cmDspInst_t* mtfb = cmDspSysAllocScalar( h, "Mt Feedback", 0.0, 1.0, 0.01, mtFeedback);
  1261. cmDspInst_t* mtscale= cmDspSysAllocScalar( h, "Mt Time Scale", 0.01, 10.0, 0.01, mtTimeScale);
  1262. // check for allocation errors
  1263. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1264. goto errLabel;
  1265. cmDspSysConnectAudioN1N1( h, ain, "out", ef, "in", chCnt ); // ain -> EF
  1266. cmDspSysConnectAudioN1N1( h, sg, "out", cf, "in", chCnt ); // sg -> CF
  1267. cmDspSysConnectAudioN1N1( h, cf, "out", eq, "in", chCnt );
  1268. cmDspSysConnectAudioN1N1( h, eq, "out", mt, "in", chCnt );
  1269. cmDspSysConnectAudioN11N( h, mt, "out", mix, "in", chCnt ); // cf -> mix
  1270. cmDspSysConnectAudio( h, mix, "out", ao0, "in"); // mix -> aout L
  1271. cmDspSysConnectAudio( h, mix, "out", ao1, "in"); // mix -> aout R
  1272. cmDspSysInstallCb1NN1( h, chCfg, "gain", ain, "gain", chCnt ); // chCfg -> ain gain
  1273. cmDspSysInstallCb1NN1( h, chCfg, "hz", cf, "hz", chCnt ); // chCfg -> CF Hz
  1274. cmDspSysInstallCb1NN1( h, chCfg, "hz", eq, "f0", chCnt ); // chCfg -> Eq Hz
  1275. cmDspSysInstallCbN1N1( h, mul, "out", add, "in-1", chCnt ); // mul -> add
  1276. cmDspSysInstallCbN1N1( h, ef, "gate", env, "gate", chCnt ); // EF -> adsr (gate)
  1277. cmDspSysInstallCbN1N1( h, ef, "rms", env, "rms", chCnt ); // EF ->adsr (rms)
  1278. //cmDspSysInstallCb11N1( h, print, "out", env, "cmd", chCnt );
  1279. cmDspSysInstallCbN1N1( h, env, "out", d2l, "in", chCnt );
  1280. cmDspSysInstallCbN11N( h, d2l, "out", mix, "gain", chCnt );
  1281. cmDspSysInstallCbN1N1( h, add, "out", mul, "in-0", chCnt ); // add -> mul (feedback)
  1282. cmDspSysInstallCb11N1( h, decay, "val", mul, "in-1", chCnt ); // decay ctl
  1283. cmDspSysInstallCbN1N1( h, ef, "gate", mtr, "in", chCnt ); // EF -> meter RMS
  1284. cmDspSysInstallCb11N1( h, alpha, "val", cf, "alpha",chCnt ); // CF alpha
  1285. cmDspSysInstallCb111N( h, zero, "val", mix, "in", chCnt ); //
  1286. cmDspSysInstallCb11N1( h, dly, "val", env, "dly", chCnt );
  1287. cmDspSysInstallCb11N1( h, atk, "val", env, "atk", chCnt );
  1288. cmDspSysInstallCb11N1( h, dcy, "val", env, "dcy", chCnt );
  1289. cmDspSysInstallCb11N1( h, hold, "val", env, "hold", chCnt );
  1290. cmDspSysInstallCb11N1( h, rls, "val", env, "rls", chCnt );
  1291. cmDspSysInstallCb11N1( h, alvl, "val", env, "alvl", chCnt );
  1292. cmDspSysInstallCb11N1( h, sus, "val", env, "sus", chCnt );
  1293. cmDspSysInstallCb11N1( h, onThr, "val", ef, "ondb", chCnt ); //
  1294. cmDspSysInstallCb11N1( h, offThr, "val", ef, "offdb", chCnt ); //
  1295. cmDspSysInstallCb11N1( h, eqbyp, "out", eq, "bypass", chCnt );
  1296. cmDspSysInstallCb11N1( h, eqmode, "mode", eq, "mode", chCnt );
  1297. cmDspSysInstallCb11N1( h, eqq, "val", eq, "Q", chCnt );
  1298. cmDspSysInstallCb11N1( h, eqfgn, "val", eq, "gain", chCnt );
  1299. cmDspSysInstallCb11N1( h, mtfb, "val", mt, "fb", chCnt );
  1300. cmDspSysInstallCb11N1( h, mtscale, "val", mt, "scale", chCnt );
  1301. }
  1302. errLabel:
  1303. cmFsFreeFn(chCfgPath);
  1304. return rc;
  1305. }
  1306. cmDspRC_t _cmDspSysPgm_CombFilt( cmDspSysH_t h, void** userPtrPtr )
  1307. {
  1308. cmDspRC_t rc = kOkDspRC;
  1309. double cfMinHz = 20.0;
  1310. double cfAlpha = 0.9;
  1311. bool cfFbFl = true;
  1312. bool cfBypassFl= false;
  1313. unsigned sgShapeId = 2;
  1314. cmDspInst_t* ao = cmDspSysAllocAudioOut( h, 0, 1.0 );
  1315. cmDspInst_t* sg = cmDspSysAllocInst( h, "SigGen", NULL, 2, 1000.0, sgShapeId );
  1316. cmDspInst_t* cf = cmDspSysAllocInst( h, "CombFilt", NULL, 5, cfBypassFl, cfMinHz, cfFbFl, cfMinHz, cfAlpha );
  1317. cmDspInst_t* hz = cmDspSysAllocScalar( h, "Hz", 25, 10000, 1, 1000 );
  1318. cmDspInst_t* a = cmDspSysAllocScalar( h, "Alpha", 0.0, 2.0, 0.001, cfAlpha);
  1319. // check for allocation errors
  1320. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1321. goto errLabel;
  1322. cmDspSysConnectAudio(h, sg, "out", cf, "in");
  1323. cmDspSysConnectAudio(h, cf, "out", ao, "in");
  1324. cmDspSysInstallCb( h, hz, "val", cf, "hz", NULL);
  1325. cmDspSysInstallCb( h, a, "val", cf, "alpha", NULL);
  1326. errLabel:
  1327. return rc;
  1328. }
  1329. cmDspRC_t _cmDspSysPgm_ScalarOp( cmDspSysH_t h, void** userPtrPtr )
  1330. {
  1331. cmDspRC_t rc;
  1332. cmDspInst_t* add = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "+", "in-0", 0.0, "in-1", 0.0 );
  1333. cmDspInst_t* mul0 = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
  1334. cmDspInst_t* mul1 = cmDspSysAllocInst( h, "ScalarOp", NULL, 6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
  1335. cmDspInst_t* in = cmDspSysAllocScalar( h, "Input", 0.0, 10.0, 0.001, 0.0);
  1336. cmDspInst_t* in_m = cmDspSysAllocScalar( h, "Input_M", 0.0, 10.0, 0.001, 0.0);
  1337. cmDspInst_t* fb = cmDspSysAllocScalar( h, "Feedback", 0.0, 10.0, 0.001, 0.0);
  1338. cmDspInst_t* fb_m = cmDspSysAllocScalar( h, "Feedback_M", 0.0, 10.0, 0.001, 0.0);
  1339. cmDspInst_t* out = cmDspSysAllocScalar( h, "Out", 0.0, 10.0, 0.001, 0.0);
  1340. // check for allocation errors
  1341. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1342. goto errLabel;
  1343. cmDspSysInstallCb( h, in, "val", mul0, "in-0", NULL );
  1344. cmDspSysInstallCb( h, in_m, "val", mul0, "in-1", NULL );
  1345. cmDspSysInstallCb( h, fb, "val", mul1, "in-0", NULL );
  1346. cmDspSysInstallCb( h, fb_m, "val", mul1, "in-1", NULL );
  1347. cmDspSysInstallCb( h, mul0, "out", add, "in-0", NULL );
  1348. cmDspSysInstallCb( h, mul1, "out", add, "in-1", NULL );
  1349. cmDspSysInstallCb( h, add, "out", fb, "val", NULL );
  1350. cmDspSysInstallCb( h, add, "out", out, "val", NULL );
  1351. errLabel:
  1352. return rc;
  1353. }
  1354. cmDspRC_t _cmDspSysPgm_RingMod( cmDspSysH_t h, void** userPtrPtr )
  1355. {
  1356. cmDspRC_t rc = kOkDspRC;
  1357. cmErr_t err;
  1358. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  1359. unsigned chCnt = 0;
  1360. unsigned nsChCnt = 0;
  1361. const cmChar_t* chCfgPath = NULL;
  1362. const cmChar_t* chCfgFn = "pick_chs8.js";
  1363. unsigned groupCnt = 3;
  1364. unsigned chsPerGroup = 2;
  1365. cmReal_t fadeTimeMs = 25;
  1366. unsigned i,j,k;
  1367. cmErrSetup(&err,&cmCtx->rpt,"Pickup Effects");
  1368. // prepend the prefs directory to the ch. cfg filename
  1369. chCfgPath = cmFsMakeFn(cmFsPrefsDir(),chCfgFn,NULL,NULL);
  1370. // get the count of channels from the ch. cfg. array
  1371. if(( chCnt = cmChCfgChannelCount(cmCtx,chCfgFn,&nsChCnt)) == 0 )
  1372. {
  1373. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"Unable to obtain the channel count from '%s'.",cmStringNullGuard(chCfgFn));
  1374. goto errLabel;
  1375. }
  1376. if( rc == kOkDspRC )
  1377. {
  1378. cmDspInst_t* ain[chCnt];
  1379. cmDspInst_t* ef[chCnt];
  1380. cmDspInst_t* mtr[chCnt];
  1381. cmDspInst_t* nom[groupCnt];
  1382. cmDspInst_t* rm[groupCnt];
  1383. cmDspInst_t* nm_mtr[groupCnt*chsPerGroup];
  1384. unsigned labelCharCnt = 31;
  1385. cmChar_t label[labelCharCnt+1];
  1386. // allocate the audio inputs and envelope followers
  1387. for(i=0; i<chCnt; ++i)
  1388. {
  1389. snprintf(label,labelCharCnt,"%i",i);
  1390. ain[i] = cmDspSysAllocAudioIn( h, i, 1.0);
  1391. ef[i] = cmDspSysAllocInst( h, "EnvFollow", NULL, 0 );
  1392. mtr[i] = cmDspSysAllocInst( h, "Meter", label, 3, 0.0, 0.0, 1.0 );
  1393. }
  1394. cmDspInst_t* gs = cmDspSysAllocInst( h, "GroupSel", NULL, 3, chCnt, groupCnt, chsPerGroup );
  1395. for(i=0; i<groupCnt; ++i)
  1396. {
  1397. nom[i] = cmDspSysAllocInst(h, "AudioNofM", NULL, 3, chCnt, chsPerGroup, fadeTimeMs );
  1398. rm[i] = cmDspSysAllocInst(h, "RingMod", NULL, 1, chsPerGroup );
  1399. }
  1400. for(i=0,k=0; i<groupCnt; ++i)
  1401. {
  1402. cmDspSysNewColumn(h,50);
  1403. snprintf(label,labelCharCnt,"%i",i);
  1404. cmDspSysAllocLabel(h,label,kLeftAlignDuiId );
  1405. for(j=0; j<chsPerGroup; ++j,++k)
  1406. {
  1407. snprintf(label,labelCharCnt,"%i",j);
  1408. nm_mtr[k] = cmDspSysAllocInst(h, "Meter", label, 3, 0.0, 0.0, 1.0 );
  1409. }
  1410. }
  1411. assert(k==groupCnt*chsPerGroup);
  1412. // allocate the ch cfg last so that it's default outputs initialize connected objects
  1413. //cmDspInst_t* chCfg = cmDspSysAllocInst( h, "ChCfg", NULL, 1, chCfgFn );
  1414. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL, 1, groupCnt );
  1415. cmDspInst_t* ao0 = cmDspSysAllocAudioOut( h, 0, 1.0 );
  1416. cmDspInst_t* ao1 = cmDspSysAllocAudioOut( h, 1, 1.0 );
  1417. // check for allocation errors
  1418. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1419. goto errLabel;
  1420. cmDspSysConnectAudioN1N1( h, ain, "out", ef, "in", chCnt ); // ain -> EF
  1421. for(i=0; i<groupCnt; ++i)
  1422. {
  1423. cmDspSysConnectAudioN11N( h, ain, "out", nom[i], "in", chCnt );
  1424. cmDspSysConnectAudio1N1N( h, nom[i], "out", rm[i], "in", chsPerGroup);
  1425. snprintf(label,labelCharCnt,"gate-%i",i);
  1426. cmDspSysInstallCb1N1N( h, gs, label, nom[i], "gate", chCnt );
  1427. cmDspSysInstallCb1NN1( h, nom[i], "gain", nm_mtr + i * chsPerGroup, "in", chsPerGroup);
  1428. }
  1429. cmDspSysConnectAudioN11N( h, rm, "out", mix, "in", groupCnt );
  1430. cmDspSysConnectAudio( h, mix, "out", ao0, "in"); // mix -> aout L
  1431. cmDspSysConnectAudio( h, mix, "out", ao1, "in"); // mix -> aout R
  1432. cmDspSysInstallCbN11N( h, ef, "gate", gs, "gate", chCnt ); // EF -> grp_sel gate
  1433. cmDspSysInstallCbN11N( h, ef, "rms", gs, "rms", chCnt ); // EF -> grp_sel RMS
  1434. cmDspSysInstallCbN1N1( h, ef, "gate", mtr, "in", chCnt );
  1435. }
  1436. errLabel:
  1437. cmFsFreeFn(chCfgPath);
  1438. return rc;
  1439. }
  1440. cmDspRC_t _cmDspSysPgm_RingMod2( cmDspSysH_t h, void** userPtrPtr )
  1441. {
  1442. cmDspRC_t rc = kOkDspRC;
  1443. cmErr_t err;
  1444. cmCtx_t* cmCtx = cmDspSysPgmCtx(h);
  1445. unsigned iChCnt = 0;
  1446. unsigned oChCnt = 0;
  1447. unsigned nsChCnt = 0;
  1448. const cmChar_t* chCfgPath = NULL;
  1449. const cmChar_t* chCfgFn = "pick_chs8.js";
  1450. unsigned i;
  1451. cmErrSetup(&err,&cmCtx->rpt,"Pickup Effects");
  1452. // prepend the prefs directory to the ch. cfg filename
  1453. chCfgPath = cmFsMakeFn(cmFsPrefsDir(),chCfgFn,NULL,NULL);
  1454. // get the count of channels from the ch. cfg. array
  1455. if(( iChCnt = cmChCfgChannelCount(cmCtx,chCfgFn,&nsChCnt)) == 0 )
  1456. {
  1457. rc = cmErrMsg(&err,kPgmCfgFailDspRC,"Unable to obtain the channel count from '%s'.",cmStringNullGuard(chCfgFn));
  1458. goto errLabel;
  1459. }
  1460. if( rc == kOkDspRC && iChCnt > 0 )
  1461. {
  1462. if( iChCnt % 2 )
  1463. iChCnt -= 1;
  1464. oChCnt = iChCnt/2;
  1465. cmDspInst_t* ain[iChCnt];
  1466. cmDspInst_t* ef[iChCnt];
  1467. cmDspInst_t* mtr[iChCnt];
  1468. cmDspInst_t* rm[oChCnt];
  1469. unsigned labelCharCnt = 31;
  1470. cmChar_t label[labelCharCnt+1];
  1471. // allocate the audio inputs and envelope followers
  1472. for(i=0; i<iChCnt; ++i)
  1473. {
  1474. snprintf(label,labelCharCnt,"%i",i);
  1475. ain[i] = cmDspSysAllocAudioIn( h, i, 1.0);
  1476. ef[i] = cmDspSysAllocInst( h, "EnvFollow", NULL, 0 );
  1477. mtr[i] = cmDspSysAllocInst( h, "Meter", label, 3, 0.0, 0.0, 1.0 );
  1478. }
  1479. for(i=0; i<oChCnt; ++i)
  1480. {
  1481. rm[i] = cmDspSysAllocInst( h, "RingMod", NULL, 1, 2 );
  1482. }
  1483. cmDspInst_t* gain = cmDspSysAllocScalar( h, "RM Gain", 0.0, 10.0, 0.001, 1.0);
  1484. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL, 1, oChCnt );
  1485. cmDspInst_t* ao0 = cmDspSysAllocAudioOut( h, 0, 1.0 );
  1486. cmDspInst_t* ao1 = cmDspSysAllocAudioOut( h, 1, 1.0 );
  1487. // check for allocation errors
  1488. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1489. goto errLabel;
  1490. cmDspSysConnectAudioN1N1( h, ain, "out", ef, "in", iChCnt ); // ain -> EF
  1491. cmDspSysInstallCbN1N1( h, ef, "gate", mtr, "in", iChCnt ); // EF -> mtr (gate)
  1492. for(i=0; i<oChCnt; ++i)
  1493. {
  1494. cmDspSysConnectAudio( h, ain[i*2+0], "out", rm[i], "in-0"); // ain -> rm 0
  1495. cmDspSysConnectAudio( h, ain[i*2+1], "out", rm[i], "in-1"); // ain -> rm 1
  1496. snprintf(label,labelCharCnt,"in-%i",i);
  1497. cmDspSysConnectAudio( h, rm[i], "out", mix, label); // rm -> mix
  1498. cmDspSysInstallCb(h, gain, "val", rm[i], "gain", NULL ); // gain -> rm gain
  1499. }
  1500. cmDspSysConnectAudio( h, mix, "out", ao0, "in"); // mix -> aout L
  1501. cmDspSysConnectAudio( h, mix, "out", ao1, "in"); // mix -> aout R
  1502. }
  1503. errLabel:
  1504. cmFsFreeFn(chCfgPath);
  1505. return rc;
  1506. }
  1507. cmDspRC_t _cmDspSysPgm_MsgDelay( cmDspSysH_t h, void** userPtrPtr )
  1508. {
  1509. cmDspRC_t rc = kOkDspRC;
  1510. double dfltDelayTimeMs = 100.0;
  1511. double maxDelayTimeMs = 10000.0;
  1512. cmDspInst_t* ctl = cmDspSysAllocScalar( h, "Delay", 0.0, maxDelayTimeMs, 1.0, dfltDelayTimeMs );
  1513. cmDspInst_t* dly = cmDspSysAllocInst( h, "MsgDelay", NULL, 2, 1000, dfltDelayTimeMs );
  1514. cmDspInst_t* print = cmDspSysAllocInst( h, "Printer", NULL, 1, ">");
  1515. if( (rc = cmDspSysLastRC(h)) != kOkDspRC )
  1516. return rc;
  1517. cmDspSysInstallCb( h, ctl, "val", dly, "delay", NULL );
  1518. cmDspSysInstallCb( h, ctl, "val", dly, "in", NULL );
  1519. cmDspSysInstallCb( h, dly, "out", print, "in", NULL );
  1520. return rc;
  1521. }
  1522. cmDspRC_t _cmDspSysPgm_Adsr( cmDspSysH_t h, void** userPtrPtr )
  1523. {
  1524. cmDspRC_t rc;
  1525. bool trigModeFl = true;
  1526. double adsrMaxMs = 5000;
  1527. double adsrMinMs = 0;
  1528. double adsrIncMs = 1;
  1529. double adsrMaxLevel = 100.0; //1.0;
  1530. double adsrSusLevel = 80.0; //0.8;
  1531. double adsrMinLevel = 0.0; //0.0;
  1532. double adsrIncLevel = 0.001;
  1533. const cmChar_t* fn = "/home/kevin/temp/adsr1.bin";
  1534. cmDspInst_t* adsr = cmDspSysAllocInst(h, "Adsr", NULL, 2, trigModeFl, adsrMinLevel );
  1535. cmDspInst_t* chck = cmDspSysAllocCheck(h,"Gate",0);
  1536. cmDspInst_t* mtr = cmDspSysAllocInst(h,"Meter","Out", 3, adsrMinLevel, adsrMinLevel, adsrMaxLevel );
  1537. cmDspInst_t* bmf = cmDspSysAllocInst(h,"BinMtxFile", NULL, 2, 1, fn );
  1538. cmDspInst_t* dly = cmDspSysAllocScalar( h, "Dly Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 0.0);
  1539. cmDspInst_t* atk = cmDspSysAllocScalar( h, "Atk Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 1000.0);
  1540. cmDspInst_t* dcy = cmDspSysAllocScalar( h, "Dcy Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 300.0);
  1541. cmDspInst_t* hold = cmDspSysAllocScalar( h, "Hold Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 500.0);
  1542. cmDspInst_t* rls = cmDspSysAllocScalar( h, "Rls Ms", adsrMinMs, adsrMaxMs, adsrIncMs, 1000.0);
  1543. cmDspInst_t* alvl = cmDspSysAllocScalar( h, "AdsrMax", adsrMinLevel,adsrMaxLevel,adsrIncLevel, adsrMaxLevel);
  1544. cmDspInst_t* sus = cmDspSysAllocScalar( h, "Sustain", adsrMinLevel,adsrMaxLevel,adsrIncLevel, adsrSusLevel);
  1545. // check for allocation errors
  1546. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1547. goto errLabel;
  1548. cmDspSysInstallCb( h, dly, "val", adsr, "dly", NULL );
  1549. cmDspSysInstallCb( h, atk, "val", adsr, "atk", NULL );
  1550. cmDspSysInstallCb( h, dcy, "val", adsr, "dcy", NULL );
  1551. cmDspSysInstallCb( h, hold, "val", adsr, "hold", NULL );
  1552. cmDspSysInstallCb( h, rls, "val", adsr, "rls", NULL );
  1553. cmDspSysInstallCb( h, alvl, "val", adsr, "alvl", NULL );
  1554. cmDspSysInstallCb( h, sus, "val", adsr, "sus", NULL );
  1555. cmDspSysInstallCb( h, chck, "out", adsr, "gate", NULL );
  1556. cmDspSysInstallCb( h, adsr, "out", mtr, "in", NULL );
  1557. cmDspSysInstallCb( h, adsr, "out", bmf, "in", NULL );
  1558. errLabel:
  1559. return rc;
  1560. }
  1561. cmDspRC_t _cmDspSysPgm_Compressor( cmDspSysH_t h, void** userPtrPtr )
  1562. {
  1563. cmDspRC_t rc;
  1564. const cmChar_t* ofn = "/home/kevin/temp/adsr0.bin";
  1565. const char* afn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  1566. int beg = 6900826;
  1567. int end = 13512262;
  1568. const cmChar_t* afn = cmFsMakeFn(cmFsUserDir(),afn0,NULL,NULL );
  1569. bool bypassFl = false;
  1570. double inGain = 1.0;
  1571. double threshDb = -40.0;
  1572. double ratio_num = 4.0;
  1573. double atkMs = 100.0;
  1574. double rlsMs = 100.0;
  1575. double makeup = 1.0;
  1576. double wndMaxMs = 1000.0;
  1577. double wndMs = 200.0;
  1578. cmDspInst_t* off = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  1579. cmDspInst_t* phs = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  1580. cmDspInst_t* wt = cmDspSysAllocInst(h,"WaveTable",NULL, 6, ((int)cmDspSysSampleRate(h)), 1, afn, -1, beg, end );
  1581. cmDspInst_t* cmp = cmDspSysAllocInst(h,"Compressor",NULL, 8, bypassFl, threshDb, ratio_num, atkMs, rlsMs, makeup, wndMs, wndMaxMs );
  1582. cmDspInst_t* ao0 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 0 );
  1583. cmDspInst_t* ao1 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 1 );
  1584. cmDspInst_t* bmf = cmDspSysAllocInst(h,"BinMtxFile", NULL, 2, 1, ofn );
  1585. cmDspInst_t* mtr = cmDspSysAllocInst(h,"Meter","Env", 3, 0.0, 0.0, 1.0);
  1586. cmDspInst_t* igain = cmDspSysAllocScalar( h, "In Gain", 0.0, 10.0, 0.1, inGain);
  1587. cmDspInst_t* thr = cmDspSysAllocScalar( h, "ThreshDb", -100.0, 0.0, 0.1, threshDb);
  1588. cmDspInst_t* rat = cmDspSysAllocScalar( h, "Ratio", 0.1, 100, 0.1, ratio_num);
  1589. cmDspInst_t* atk = cmDspSysAllocScalar( h, "Atk Ms", 0.0, 1000.0, 0.1, atkMs);
  1590. cmDspInst_t* rls = cmDspSysAllocScalar( h, "Rls Ms", 0.0, 1000.0, 0.1, rlsMs);
  1591. cmDspInst_t* mkup = cmDspSysAllocScalar( h, "Makeup", 0.0, 10.0, 0.01, makeup);
  1592. cmDspInst_t* wnd = cmDspSysAllocScalar( h, "Wnd Ms", 1.0, wndMaxMs, 1.0, wndMs );
  1593. // check for allocation errors
  1594. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1595. goto errLabel;
  1596. cmDspSysConnectAudio(h, phs, "out", wt, "phs" ); // phasor -> wave table
  1597. cmDspSysConnectAudio(h, wt, "out", cmp, "in" ); // wave table -> cmp in
  1598. cmDspSysConnectAudio(h, cmp, "out", ao0, "in" ); // comp -> aout
  1599. cmDspSysConnectAudio(h, cmp, "out", ao1, "in" ); //
  1600. cmDspSysInstallCb(h, off, "val", wt, "beg", NULL );
  1601. cmDspSysInstallCb(h, igain,"val", cmp, "igain", NULL );
  1602. cmDspSysInstallCb(h, thr, "val", cmp, "thr", NULL );
  1603. cmDspSysInstallCb(h, rat, "val", cmp, "ratio", NULL );
  1604. cmDspSysInstallCb(h, atk, "val", cmp, "atk", NULL );
  1605. cmDspSysInstallCb(h, rls, "val", cmp, "rls", NULL );
  1606. cmDspSysInstallCb(h, mkup, "val", cmp, "ogain", NULL );
  1607. cmDspSysInstallCb(h, wnd, "val", cmp, "wnd", NULL );
  1608. cmDspSysInstallCb(h, cmp, "env", bmf, "in", NULL );
  1609. cmDspSysInstallCb(h, cmp, "env", mtr, "in", NULL );
  1610. errLabel:
  1611. return rc;
  1612. }
  1613. cmDspRC_t _cmDspSysPgm_BiQuadEq( cmDspSysH_t h, void** userPtrPtr )
  1614. {
  1615. cmDspRC_t rc = kOkDspRC;
  1616. const char* afn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  1617. int beg = 6900826;
  1618. int end = 13512262;
  1619. const cmChar_t* afn = cmFsMakeFn(cmFsUserDir(),afn0,NULL,NULL );
  1620. bool bypassFl = false;
  1621. unsigned modeSymId = cmSymTblRegisterStaticSymbol(cmDspSysSymbolTable(h),"LP");
  1622. double f0hz = 264.0;
  1623. double Q = 1.0;
  1624. double fgain = 1.0;
  1625. cmDspInst_t* off = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  1626. cmDspInst_t* phs = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  1627. cmDspInst_t* wt = cmDspSysAllocInst(h,"WaveTable",NULL, 6, ((int)cmDspSysSampleRate(h)), 1, afn, -1, beg, end );
  1628. cmDspInst_t* flt = cmDspSysAllocInst(h,"BiQuadEq",NULL, 5, bypassFl, modeSymId,f0hz, Q, fgain );
  1629. cmDspInst_t* ao0 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 0 );
  1630. cmDspInst_t* ao1 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 1 );
  1631. cmDspInst_t* mode = cmDspSysAllocInst( h, "MsgList","Mode", 1, "biQuadEqMode");
  1632. cmDspInst_t* fhz = cmDspSysAllocScalar( h, "Fc Hz", 0.0, 15000.0, 0.1, f0hz);
  1633. cmDspInst_t* q = cmDspSysAllocScalar( h, "Q", -100.0, 100, 0.1, Q);
  1634. cmDspInst_t* fgn = cmDspSysAllocScalar( h, "Filt Gain", 0.0, 1.0, 0.1, fgain);
  1635. // check for allocation errors
  1636. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1637. goto errLabel;
  1638. cmDspSysConnectAudio(h, phs, "out", wt, "phs" ); // phasor -> wave table
  1639. cmDspSysConnectAudio(h, wt, "out", flt, "in" ); // wave table -> cmp in
  1640. cmDspSysConnectAudio(h, flt, "out", ao0, "in" ); // filter -> aout
  1641. cmDspSysConnectAudio(h, flt, "out", ao1, "in" ); //
  1642. cmDspSysInstallCb(h, off, "val", wt, "beg", NULL );
  1643. cmDspSysInstallCb(h, mode,"mode",flt, "mode", NULL );
  1644. cmDspSysInstallCb(h, fhz, "val", flt, "f0", NULL );
  1645. cmDspSysInstallCb(h, q, "val", flt, "Q", NULL );
  1646. cmDspSysInstallCb(h, fgn, "val", flt, "gain", NULL );
  1647. errLabel:
  1648. return rc;
  1649. }
  1650. cmDspRC_t _cmDspSysPgm_DistDs( cmDspSysH_t h, void** userPtrPtr )
  1651. {
  1652. cmDspRC_t rc = kOkDspRC;
  1653. const char* afn0 = "media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  1654. int beg = 6900826;
  1655. int end = 13512262;
  1656. const cmChar_t* afn = cmFsMakeFn(cmFsUserDir(),afn0,NULL,NULL );
  1657. bool bypassFl = false;
  1658. double inGain = 1.0;
  1659. double dsrate = 44100.0;
  1660. double bits = 24.0;
  1661. bool rectifyFl = false;
  1662. bool fullRectFl = false;
  1663. double clipDb = -10.0;
  1664. cmDspInst_t* off = cmDspSysAllocInst(h,"Scalar", "Offset", 5, kNumberDuiId, 0.0, cmDspSysSampleRate(h)*600.0, 1.0, 0.0);
  1665. cmDspInst_t* phs = cmDspSysAllocInst(h,"Phasor", NULL, 0 );
  1666. cmDspInst_t* wt = cmDspSysAllocInst(h,"WaveTable",NULL, 6, ((int)cmDspSysSampleRate(h)), 1, afn, -1, beg, end );
  1667. cmDspInst_t* dst = cmDspSysAllocInst(h,"DistDs",NULL, 3, bypassFl, inGain, dsrate, bits );
  1668. cmDspInst_t* ao0 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 0 );
  1669. cmDspInst_t* ao1 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 1 );
  1670. cmDspInst_t* ign = cmDspSysAllocScalar( h, "In Gain", 0.0, 10.0, 0.01, 1.0);
  1671. cmDspInst_t* rct = cmDspSysAllocCheck( h, "Rectify", rectifyFl);
  1672. cmDspInst_t* ful = cmDspSysAllocCheck( h, "Full/Half", fullRectFl);
  1673. cmDspInst_t* dsr = cmDspSysAllocScalar( h, "Srate", 0.0, 96000, 1.0, dsrate);
  1674. cmDspInst_t* dbt = cmDspSysAllocScalar( h, "bits", 2.0, 32.0, 1.0, bits);
  1675. cmDspInst_t* clip = cmDspSysAllocScalar( h, "Clip dB", -100.0, 0.0, 0.1, clipDb);
  1676. cmDspInst_t* ogn = cmDspSysAllocScalar( h, "Out Gain", 0.0, 10.0, 0.01, 1.0);
  1677. // check for allocation errors
  1678. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1679. goto errLabel;
  1680. cmDspSysConnectAudio(h, phs, "out", wt, "phs" ); // phasor -> wave table
  1681. cmDspSysConnectAudio(h, wt, "out", dst, "in" ); // wave table -> cmp in
  1682. cmDspSysConnectAudio(h, dst, "out", ao0, "in" ); // filter -> aout
  1683. cmDspSysConnectAudio(h, dst, "out", ao1, "in" ); //
  1684. cmDspSysInstallCb(h, off, "val", wt, "beg", NULL );
  1685. cmDspSysInstallCb(h, ign, "val", dst, "igain", NULL );
  1686. cmDspSysInstallCb(h, dsr, "val", dst, "srate", NULL );
  1687. cmDspSysInstallCb(h, dbt, "val", dst, "bits", NULL );
  1688. cmDspSysInstallCb(h, rct, "out", dst, "rect", NULL );
  1689. cmDspSysInstallCb(h, ful, "out", dst, "full", NULL );
  1690. cmDspSysInstallCb(h, clip, "val", dst, "clip", NULL );
  1691. cmDspSysInstallCb(h, ogn, "val", dst, "ogain", NULL );
  1692. errLabel:
  1693. return rc;
  1694. }
  1695. cmDspRC_t _cmDspSysPgm_Seq( cmDspSysH_t h, void** userPtrPtr )
  1696. {
  1697. cmDspRC_t rc;
  1698. double min = 1.0;
  1699. double max = 10.0;
  1700. double incr = 1.0;
  1701. cmDspInst_t* btn = cmDspSysAllocButton( h, "smack", 0);
  1702. cmDspInst_t* cnt = cmDspSysAllocInst( h, "Counter", NULL, 3, min, max, incr );
  1703. cmDspInst_t* lst = cmDspSysAllocInst( h, "MsgList","Seq", 1, "seqTest");
  1704. cmDspInst_t* prt = cmDspSysAllocInst( h, "Printer", NULL, 1, ">");
  1705. cmDspSysInstallCb(h, lst, "cnt", cnt, "max", NULL );
  1706. cmDspSysInstallCb(h, btn, "out", cnt, "next", NULL );
  1707. cmDspSysInstallCb(h, cnt, "out", lst, "sel", NULL );
  1708. cmDspSysInstallCb(h, lst, "midi", prt, "in", NULL );
  1709. // check for allocation errors
  1710. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1711. goto errLabel;
  1712. errLabel:
  1713. return rc;
  1714. }
  1715. cmDspRC_t _cmDspSysPgm_ThunkNet( cmDspSysH_t h, void** userPtrPtr )
  1716. {
  1717. cmDspRC_t rc;
  1718. cmDspInst_t* add = cmDspSysAllocInst( h, "ScalarOp", "adder-0", 6, 2, "+", "in-0", 0.0, "in-1", 0.0 );
  1719. cmDspInst_t* in = cmDspSysAllocScalar( h, "Input", 0.0, 10.0, 0.001, 0.0);
  1720. cmDspInst_t* out = cmDspSysAllocScalar( h, "Out", 0.0, 10.0, 0.001, 0.0);
  1721. // check for allocation errors
  1722. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1723. goto errLabel;
  1724. cmDspSysInstallCb( h, in, "val", add, "in-1", NULL );
  1725. cmDspSysInstallCb( h, add, "out", out, "val", NULL );
  1726. errLabel:
  1727. return rc;
  1728. }
  1729. cmDspRC_t _cmDspSysPgm_WhirlNet( cmDspSysH_t h, void** userPtrPtr )
  1730. {
  1731. cmDspRC_t rc;
  1732. cmDspInst_t* in = cmDspSysAllocScalar( h, "Input", 0.0, 10.0, 0.001, 0.0);
  1733. // check for allocation errors
  1734. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1735. goto errLabel;
  1736. cmDspSysInstallNetCb( h, in, "val", "thunk", "adder-0", "in-0" );
  1737. errLabel:
  1738. return rc;
  1739. }
  1740. cmDspRC_t _cmDspSysPgm_NofM( cmDspSysH_t h, void** userPtrPtr )
  1741. {
  1742. cmDspRC_t rc;
  1743. unsigned iChCnt = 3;
  1744. unsigned oChCnt = 2;
  1745. unsigned sgShapeId = 0;
  1746. double sgGain = 0.4;
  1747. double xfadeMs = 1000;
  1748. cmDspInst_t* onBtn = cmDspSysAllocButton( h, "on", 0 );
  1749. cmDspInst_t* offBtn = cmDspSysAllocButton(h, "off", 0 );
  1750. cmDspInst_t* sg0 = cmDspSysAllocInst( h, "SigGen", NULL, 3, 500.0, sgShapeId, sgGain );
  1751. cmDspInst_t* sg1 = cmDspSysAllocInst( h, "SigGen", NULL, 3, 1000.0, sgShapeId, sgGain );
  1752. cmDspInst_t* sg2 = cmDspSysAllocInst( h, "SigGen", NULL, 3, 2000.0, sgShapeId, sgGain );
  1753. cmDspInst_t* nom = cmDspSysAllocInst( h,"NofM", NULL, 3, iChCnt, oChCnt, xfadeMs );
  1754. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL, 1, oChCnt );
  1755. cmDspInst_t* ao = cmDspSysAllocAudioOut(h, 0, 1.0 );
  1756. cmDspInst_t* btn = cmDspSysAllocButton( h, "cfg", 0);
  1757. cmDspInst_t* sel0 = cmDspSysAllocCheck(h,"Sel-0",0);
  1758. cmDspInst_t* sel1 = cmDspSysAllocCheck(h,"Sel-1",0);
  1759. cmDspInst_t* sel2 = cmDspSysAllocCheck(h,"Sel-2",0);
  1760. cmDspInst_t* in0 = cmDspSysAllocScalar( h, "In-0", 0.0, 10.0, 0.001, 0.0);
  1761. cmDspInst_t* in1 = cmDspSysAllocScalar( h, "In-1", 0.0, 10.0, 0.001, 0.0);
  1762. cmDspInst_t* in2 = cmDspSysAllocScalar( h, "In-2", 0.0, 10.0, 0.001, 0.0);
  1763. cmDspInst_t* out0 = cmDspSysAllocScalar( h, "Out-0", 0.0, 10.0, 0.001, 0.0);
  1764. cmDspInst_t* out1 = cmDspSysAllocScalar( h, "Out-1", 0.0, 10.0, 0.001, 0.0);
  1765. // check for allocation errors
  1766. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1767. goto errLabel;
  1768. cmDspSysConnectAudio( h, sg0, "out", nom, "a-in-0" );
  1769. cmDspSysConnectAudio( h, sg1, "out", nom, "a-in-1" );
  1770. cmDspSysConnectAudio( h, sg2, "out", nom, "a-in-2" );
  1771. cmDspSysConnectAudio( h, nom, "a-out-0", mix, "in-0" );
  1772. cmDspSysConnectAudio( h, nom, "a-out-1", mix, "in-1" );
  1773. cmDspSysConnectAudio( h, mix, "out", ao, "in" );
  1774. cmDspSysInstallCb( h, btn, "sym", nom, "cmd", NULL );
  1775. cmDspSysInstallCb( h, sel0, "out", nom, "sel-0", NULL );
  1776. cmDspSysInstallCb( h, sel1, "out", nom, "sel-1", NULL );
  1777. cmDspSysInstallCb( h, sel2, "out", nom, "sel-2", NULL );
  1778. cmDspSysInstallCb( h, in0, "val", nom, "f-in-0", NULL );
  1779. cmDspSysInstallCb( h, in1, "val", nom, "f-in-1", NULL );
  1780. cmDspSysInstallCb( h, in2, "val", nom, "f-in-2", NULL );
  1781. cmDspSysInstallCb( h, nom, "f-out-0", out0, "val", NULL );
  1782. cmDspSysInstallCb( h, nom, "f-out-1", out1, "val", NULL );
  1783. cmDspSysInstallCb( h, onBtn, "sym", nom, "cmd", NULL );
  1784. cmDspSysInstallCb( h, offBtn, "sym", nom, "cmd", NULL );
  1785. errLabel:
  1786. return rc;
  1787. }
  1788. cmDspRC_t _cmDspSysPgm_1ofN( cmDspSysH_t h, void** userPtrPtr )
  1789. {
  1790. cmDspRC_t rc;
  1791. unsigned inCnt = 3;
  1792. unsigned initSel = 0;
  1793. cmDspInst_t* oom = cmDspSysAllocInst(h,"1ofN", NULL, 2, inCnt, initSel );
  1794. cmDspInst_t* sel = cmDspSysAllocScalar( h, "Sel", 0, inCnt-1, 0.001, 0.0);
  1795. cmDspInst_t* in0 = cmDspSysAllocScalar( h, "In-0", 0.0, 10.0, 0.001, 0.0);
  1796. cmDspInst_t* in1 = cmDspSysAllocScalar( h, "In-1", 0.0, 10.0, 0.001, 0.0);
  1797. cmDspInst_t* in2 = cmDspSysAllocScalar( h, "In-2", 0.0, 10.0, 0.001, 0.0);
  1798. cmDspInst_t* out = cmDspSysAllocScalar( h, "Out", 0.0, 10.0, 0.001, 0.0);
  1799. // check for allocation errors
  1800. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1801. goto errLabel;
  1802. cmDspSysInstallCb( h, sel, "val", oom, "chidx", NULL );
  1803. cmDspSysInstallCb( h, in0, "val", oom, "f-in-0", NULL );
  1804. cmDspSysInstallCb( h, in1, "val", oom, "f-in-1", NULL );
  1805. cmDspSysInstallCb( h, in2, "val", oom, "f-in-2", NULL );
  1806. cmDspSysInstallCb( h, oom, "f-out", out, "val", NULL );
  1807. errLabel:
  1808. return rc;
  1809. }
  1810. cmDspRC_t _cmDspSysPgm_Router( cmDspSysH_t h, void** userPtrPtr )
  1811. {
  1812. cmDspRC_t rc;
  1813. unsigned inCnt = 3;
  1814. unsigned initSel = 0;
  1815. cmDspInst_t* rtr = cmDspSysAllocInst(h,"Router", NULL, 2, inCnt, initSel );
  1816. cmDspInst_t* sel = cmDspSysAllocScalar( h, "Sel", 0, inCnt-1, 1.0, 0.0);
  1817. cmDspInst_t* in = cmDspSysAllocScalar( h, "In", 0.0, 10.0, 0.001, 0.0);
  1818. cmDspInst_t* out0 = cmDspSysAllocScalar( h, "Out-0", 0.0, 10.0, 0.001, 0.0);
  1819. cmDspInst_t* out1 = cmDspSysAllocScalar( h, "Out-1", 0.0, 10.0, 0.001, 0.0);
  1820. cmDspInst_t* out2 = cmDspSysAllocScalar( h, "Out-2", 0.0, 10.0, 0.001, 0.0);
  1821. // check for allocation errors
  1822. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1823. goto errLabel;
  1824. cmDspSysInstallCb( h, sel, "val", rtr, "sel", NULL );
  1825. cmDspSysInstallCb( h, in, "val", rtr, "f-in", NULL );
  1826. cmDspSysInstallCb( h, rtr, "f-out-0", out0, "val", NULL );
  1827. cmDspSysInstallCb( h, rtr, "f-out-1", out1, "val", NULL );
  1828. cmDspSysInstallCb( h, rtr, "f-out-2", out2, "val", NULL );
  1829. errLabel:
  1830. return rc;
  1831. }
  1832. cmDspRC_t _cmDspSysPgm_Preset( cmDspSysH_t h, void** userPtrPtr )
  1833. {
  1834. cmDspRC_t rc;
  1835. unsigned sgShapeId = 0;
  1836. double sgHz = 500;
  1837. double sgGain = 0.02;
  1838. unsigned grpSymId = cmDspSysPresetRegisterGroup(h,"test");
  1839. const cmChar_t* prefixLabel = NULL;
  1840. cmDspInst_t* sg = cmDspSysAllocInst( h, "SigGen", NULL, 3, sgHz, sgShapeId, sgGain );
  1841. cmDspInst_t* ao = cmDspSysAllocAudioOut( h, 0, 1.0 );
  1842. cmDspInst_t* shapes = cmDspSysAllocMsgListP(h, grpSymId, prefixLabel, "Shape", NULL, "shapeList", 0 );
  1843. cmDspInst_t* gains = cmDspSysAllocMsgListP(h, grpSymId, prefixLabel, "Gains", NULL, "gainMenu", 0 );
  1844. cmDspInst_t* hz = cmDspSysAllocScalarP( h, grpSymId, prefixLabel, "Hz", 0.0, 10000.0, 0.01, sgHz);
  1845. cmDspInst_t* gain = cmDspSysAllocScalarP( h, grpSymId, prefixLabel, "Gain", 0.0, 1.0, 0.01, sgGain);
  1846. cmDspInst_t* preset = cmDspSysAllocInst( h, "Preset", NULL, 1, grpSymId );
  1847. cmDspInst_t* presetLbl = cmDspSysAllocInst( h, "Text", "Preset", 1, "" );
  1848. cmDspInst_t* storeBtn = cmDspSysAllocButton( h, "store", 0);
  1849. cmDspInst_t* recallBtn = cmDspSysAllocButton( h, "recall", 0);
  1850. // check for allocation errors
  1851. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1852. goto errLabel;
  1853. cmDspSysConnectAudio(h, sg, "out", ao, "in" );
  1854. cmDspSysInstallCb( h, shapes,"out", sg, "shape", NULL );
  1855. cmDspSysInstallCb( h, hz, "val", sg, "hz", NULL );
  1856. cmDspSysInstallCb( h, gain, "val", sg, "gain", NULL );
  1857. cmDspSysInstallCb( h, gains, "out", gain, "val", NULL );
  1858. cmDspSysInstallCb( h, presetLbl, "val", preset, "label",NULL);
  1859. cmDspSysInstallCb( h, storeBtn, "sym", preset, "cmd", NULL );
  1860. cmDspSysInstallCb( h, recallBtn, "sym", preset, "cmd", NULL );
  1861. errLabel:
  1862. return rc;
  1863. }
  1864. cmDspRC_t _cmDspSysPgm_RsrcWr( cmDspSysH_t h, void** userPtrPtr )
  1865. {
  1866. cmDspRC_t rc = kOkDspRC;
  1867. const cmChar_t* lbl1 = "rsrc1";
  1868. const cmChar_t* lbl2 = "rsrc2";
  1869. const cmChar_t* str1 = NULL;
  1870. const cmChar_t* str2 = NULL;
  1871. if( cmDspRsrcString(h,&str1, lbl1, NULL ) != kOkDspRC )
  1872. str1 = "1";
  1873. if( cmDspRsrcString(h,&str2, lbl2, NULL ) != kOkDspRC )
  1874. str2 = "2";
  1875. cmDspInst_t* rsrcWr = cmDspSysAllocInst( h, "RsrcWr", NULL, 2, lbl1, lbl2 );
  1876. cmDspInst_t* textUi0 = cmDspSysAllocInst( h, "Text", "Value1", 1, str1 );
  1877. cmDspInst_t* textUi1 = cmDspSysAllocInst( h, "Text", "Value2", 1, str2 );
  1878. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1879. goto errLabel;
  1880. cmDspSysInstallCb( h, textUi0, "val", rsrcWr, "rsrc1", NULL );
  1881. cmDspSysInstallCb( h, textUi1, "val", rsrcWr, "rsrc2", NULL );
  1882. errLabel:
  1883. return rc;
  1884. }
  1885. cmDspRC_t _cmDspSysPgm_1Up( cmDspSysH_t h, void** userPtrPtr )
  1886. {
  1887. cmDspRC_t rc;
  1888. unsigned chCnt = 3;
  1889. double maxIdx = chCnt - 1;
  1890. unsigned initIdx = 2;
  1891. cmDspInst_t* sel = cmDspSysAllocScalar( h, "Chan", 0.0, maxIdx, 1.0, 0.0 );
  1892. cmDspInst_t* up = cmDspSysAllocInst( h, "1Up", NULL, 2, chCnt, initIdx );
  1893. cmDspInst_t* pr0 = cmDspSysAllocInst( h, "Printer", NULL, 1, "0:" );
  1894. cmDspInst_t* pr1 = cmDspSysAllocInst( h, "Printer", NULL, 1, "1:" );
  1895. cmDspInst_t* pr2 = cmDspSysAllocInst( h, "Printer", NULL, 1, "2:" );
  1896. // check for allocation errors
  1897. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1898. goto errLabel;
  1899. cmDspSysInstallCb( h, sel, "val", up, "sel",NULL);
  1900. cmDspSysInstallCb( h, up, "out-0", pr0, "in", NULL );
  1901. cmDspSysInstallCb( h, up, "out-1", pr1, "in", NULL );
  1902. cmDspSysInstallCb( h, up, "out-2", pr2, "in", NULL );
  1903. errLabel:
  1904. return rc;
  1905. }
  1906. cmDspRC_t _cmDspSysPgm_PortToSym( cmDspSysH_t h, void** userPtrPtr )
  1907. {
  1908. cmDspRC_t rc = kOkDspRC;
  1909. cmDspInst_t* btn0 = cmDspSysAllocButton( h, "Btn0", 0.0 );
  1910. cmDspInst_t* btn1 = cmDspSysAllocButton( h, "Btn1", 0.0 );
  1911. cmDspInst_t* btn2 = cmDspSysAllocButton( h, "Btn2", 0.0 );
  1912. cmDspInst_t* pts = cmDspSysAllocInst( h, "PortToSym", NULL, 3, "one", "two", "three");
  1913. cmDspInst_t* pr0 = cmDspSysAllocInst( h, "Printer", NULL, 1, "0:" );
  1914. cmDspInst_t* pr1 = cmDspSysAllocInst( h, "Printer", NULL, 1, "1:" );
  1915. // check for allocation errors
  1916. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1917. goto errLabel;
  1918. cmDspSysInstallCb( h, btn0, "out", pts, "one",NULL);
  1919. cmDspSysInstallCb( h, btn1, "out", pts, "two",NULL);
  1920. cmDspSysInstallCb( h, btn2, "out", pts, "three",NULL);
  1921. cmDspSysInstallCb( h, btn0, "out", pr1, "in",NULL);
  1922. cmDspSysInstallCb( h, btn1, "out", pr1, "in",NULL);
  1923. cmDspSysInstallCb( h, btn2, "out", pr1, "in",NULL);
  1924. cmDspSysInstallCb( h, pts, "one", pr0, "in", NULL );
  1925. cmDspSysInstallCb( h, pts, "two", pr0, "in", NULL );
  1926. cmDspSysInstallCb( h, pts, "three", pr0, "in", NULL );
  1927. errLabel:
  1928. return rc;
  1929. }
  1930. cmDspRC_t _cmDspSysPgm_Line( cmDspSysH_t h, void** userPtrPtr )
  1931. {
  1932. cmDspRC_t rc = kOkDspRC;
  1933. cmDspInst_t* beg = cmDspSysAllocScalar( h, "beg", -10.0, 10.0, 1.0, 0.0 );
  1934. cmDspInst_t* end = cmDspSysAllocScalar( h, "end", -10.0, 10.0, 1.0, 1.0 );
  1935. cmDspInst_t* dur = cmDspSysAllocScalar( h, "dur", 0.0, 10000.0, 1.0, 0.0 );
  1936. cmDspInst_t* reset = cmDspSysAllocButton(h, "reset", 0.0 );
  1937. cmDspInst_t* line = cmDspSysAllocInst( h, "Line", NULL, 3, 0.0, 10.0, 1000.0 );
  1938. cmDspInst_t* mtr = cmDspSysAllocInst( h, "Meter", NULL, 3, -10.0, 10.0, 0.0 );
  1939. cmDspInst_t* pr1 = cmDspSysAllocInst( h, "Printer", NULL, 1, ">" );
  1940. // check for allocation errors
  1941. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1942. goto errLabel;
  1943. cmDspSysInstallCb( h, beg, "val", line, "beg",NULL);
  1944. cmDspSysInstallCb( h, end, "val", line, "end",NULL);
  1945. cmDspSysInstallCb( h, dur, "val", line, "dur",NULL);
  1946. cmDspSysInstallCb( h, line, "out", mtr, "in", NULL );
  1947. cmDspSysInstallCb( h, reset, "sym", line, "cmd", NULL );
  1948. cmDspSysInstallCb( h, line, "out", pr1, "in", NULL );
  1949. errLabel:
  1950. return rc;
  1951. }
  1952. cmDspRC_t _cmDspSysPgm_Array( cmDspSysH_t h, void** userPtrPtr )
  1953. {
  1954. cmDspRC_t rc = kOkDspRC;
  1955. unsigned cnt = 0;
  1956. const cmChar_t* rsrcLabelStr = "test";
  1957. if( cmDspRsrcArrayCount( h, &cnt, rsrcLabelStr, NULL ) != kOkDspRC )
  1958. return cmErrMsg(&cmDspSysPgmCtx(h)->err,kPgmCfgFailDspRC,"The resource '%s' could not be read.",rsrcLabelStr);
  1959. cmDspInst_t* printBtn = cmDspSysAllocButton( h, "print", 0.0 );
  1960. cmDspInst_t* sendBtn = cmDspSysAllocButton( h, "send", 0.0 );
  1961. cmDspInst_t* cntBtn = cmDspSysAllocButton( h, "count", 0.0 );
  1962. cmDspInst_t* offsCtl = cmDspSysAllocScalar( h, "offset",0.0, 128.0, 1.0, 60.0 );
  1963. cmDspInst_t* array = cmDspSysAllocInst( h, "Array", NULL, 1, rsrcLabelStr );
  1964. cmDspInst_t** pcvt = cmDspSysAllocInstArray( h, cnt, "PitchCvt", NULL, NULL, 0 );
  1965. cmDspInst_t* printer = cmDspSysAllocInst( h, "Printer", NULL, 1, ">" );
  1966. cmDspSysInstallCb( h, printBtn, "sym", array, "cmd", NULL );
  1967. cmDspSysInstallCb( h, sendBtn, "sym", array, "cmd", NULL );
  1968. cmDspSysInstallCb( h, cntBtn, "sym", array, "cmd", NULL );
  1969. cmDspSysInstallCb11N1( h, offsCtl, "val", pcvt, "offs", cnt );
  1970. cmDspSysInstallCb1NN1( h, array, "out", pcvt, "midi", cnt );
  1971. cmDspSysInstallCbN111( h, pcvt, "midi", printer, "in", cnt );
  1972. cmDspSysInstallCb( h, array, "cnt", printer, "in", NULL );
  1973. return rc;
  1974. }
  1975. cmDspRC_t _cmDspSysPgm_SegLine( cmDspSysH_t h, void** userPtrPtr )
  1976. {
  1977. cmDspRC_t rc = kOkDspRC;
  1978. cmDspInst_t* btn = cmDspSysAllocButton( h, "Trig", 0.0 );
  1979. cmDspInst_t* sline = cmDspSysAllocInst( h, "SegLine", NULL, 1, "array" );
  1980. cmDspInst_t* printer = cmDspSysAllocInst( h, "Printer", NULL, 1, ">" );
  1981. // check for allocation errors
  1982. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  1983. goto errLabel;
  1984. cmDspSysInstallCb( h, btn, "sym", sline, "trig", NULL );
  1985. cmDspSysInstallCb( h, sline, "out", printer, "in", NULL );
  1986. errLabel:
  1987. return rc;
  1988. }
  1989. cmDspRC_t _cmDspSysPgm_AvailCh( cmDspSysH_t h, void** userPtrPtr )
  1990. {
  1991. double frqHz = 440.0;
  1992. unsigned xfadeChCnt = 2;
  1993. double xfadeMs = 250.0;
  1994. bool xfadeInitFl = false;
  1995. const char* fn = "/home/kevin/media/audio/20110723-Kriesberg/Audio Files/Piano 3_01.wav";
  1996. cmDspInst_t* chk0 = cmDspSysAllocInst(h,"Button", "0", 2, kButtonDuiId, 0.0 );
  1997. //cmDspInst_t* chk1 = cmDspSysAllocInst(h,"Button", "1", 2, kCheckDuiId, 0.0 );
  1998. cmDspInst_t* achp = cmDspSysAllocInst( h, "AvailCh", NULL, 1, xfadeChCnt );
  1999. cmDspInst_t* sphp = cmDspSysAllocInst( h, "Phasor", NULL, 2, cmDspSysSampleRate(h), frqHz );
  2000. cmDspInst_t* swtp = cmDspSysAllocInst( h, "WaveTable", NULL, 2, ((int)cmDspSysSampleRate(h)), 4);
  2001. cmDspInst_t* fphp = cmDspSysAllocInst( h, "Phasor", NULL, 1, cmDspSysSampleRate(h) );
  2002. cmDspInst_t* fwtp = cmDspSysAllocInst( h, "WaveTable", NULL, 5, ((int)cmDspSysSampleRate(h)), 1, fn, -1, 7000000 );
  2003. cmDspInst_t* fad0 = cmDspSysAllocInst( h, "Xfader", NULL, 3, xfadeChCnt, xfadeMs, xfadeInitFl );
  2004. //cmDspInst_t* prp = cmDspSysAllocInst( h, "Printer", NULL, 1, ">" );
  2005. cmDspInst_t* ao0p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 0 );
  2006. cmDspInst_t* ao1p = cmDspSysAllocInst(h,"AudioOut", NULL, 1, 1 );
  2007. // phasor->sine->fad-0->aout
  2008. cmDspSysConnectAudio(h, sphp, "out", swtp, "phs" );
  2009. cmDspSysConnectAudio(h, swtp, "out", fad0, "in-0" );
  2010. cmDspSysConnectAudio(h, fad0, "out-0", ao0p, "in" );
  2011. // phasor->file->fad-1->aout
  2012. cmDspSysConnectAudio(h, fphp, "out", fwtp, "phs" );
  2013. cmDspSysConnectAudio(h, fwtp, "out", fad0, "in-1" );
  2014. cmDspSysConnectAudio(h, fad0, "out-1", ao1p, "in" );
  2015. //cmDspSysInstallCb(h, chk0, "out", fad0, "gate-0", NULL);
  2016. //cmDspSysInstallCb(h, chk1, "out", fad0, "gate-1", NULL);
  2017. cmDspSysInstallCb(h, chk0, "sym", achp, "trig", NULL);
  2018. cmDspSysInstallCb(h, achp, "gate-0", fad0, "gate-0", NULL );
  2019. cmDspSysInstallCb(h, fad0, "state-0", achp, "dis-0", NULL );
  2020. cmDspSysInstallCb(h, achp, "gate-1", fad0, "gate-1", NULL );
  2021. cmDspSysInstallCb(h, fad0, "state-1", achp, "dis-1", NULL );
  2022. return kOkDspRC;
  2023. }
  2024. cmDspRC_t _cmDspSysPgm_Goertzel( cmDspSysH_t h, void** userPtrPtr )
  2025. {
  2026. cmDspRC_t rc;
  2027. const unsigned chCnt = 8;
  2028. unsigned hopFact = 2;
  2029. double dfltHz = 18000.0;
  2030. unsigned sigGenMode = 2; // sine
  2031. double sigGenGain = 0.9;
  2032. double dfltMixGain = 1.0/chCnt;
  2033. double fcHzV[chCnt];
  2034. unsigned i;
  2035. for(i=0; i<chCnt; ++i)
  2036. fcHzV[i] = 18000.0 + (20000.0-18000.0) * i /chCnt;
  2037. cmDspInst_t* ain = cmDspSysAllocAudioIn( h, 0, 1.0);
  2038. cmDspInst_t* amtr = cmDspSysAllocInst( h, "AMeter", "In", 0 );
  2039. cmDspInst_t* goer = cmDspSysAllocInst( h, "Goertzel", NULL, 3, hopFact, chCnt, fcHzV );
  2040. cmDspSysNewColumn(h,0);
  2041. cmDspInst_t** mtrV = cmDspSysAllocInstArray(h, chCnt, "Meter", "Mtr", NULL, 3, 0.0, 0.0, 1.0 );
  2042. cmDspInst_t** sgV = cmDspSysAllocInstArray(h, chCnt, "SigGen", "SG", NULL, 2, dfltHz, sigGenMode, sigGenGain, 0 );
  2043. cmDspInst_t* mix = cmDspSysAllocInst( h, "AMix", NULL,1, chCnt );
  2044. cmDspInst_t* ao0 = cmDspSysAllocAudioOut( h, 0, 1.0);
  2045. cmDspInst_t* ao1 = cmDspSysAllocAudioOut( h, 0, 1.0);
  2046. cmDspSysNewColumn(h,0);
  2047. cmDspInst_t** hzV = cmDspSysAllocInstArray( h, chCnt, "Scalar", "Hz", NULL, 5, kNumberDuiId, 0.0, 22000.0, 100.0, dfltHz );
  2048. cmDspSysNewColumn(h,0);
  2049. cmDspInst_t** gnV = cmDspSysAllocInstArray( h, chCnt, "Scalar", "Gain", NULL, 5, kNumberDuiId, 0.0, 1.0, 0.01, dfltMixGain );
  2050. cmDspInst_t* igain = cmDspSysAllocScalar( h, "igain", 0.0, 3.0, 0.01, 1.0 );
  2051. cmDspInst_t* hop = cmDspSysAllocScalar( h, "hop", 0.0, 16.0, 1.0, 4.0 );
  2052. //cmDspInst_t* prnt = cmDspSysAllocInst( h,"Printer", NULL, 1, ">" );
  2053. // check for allocation errors
  2054. if((rc = cmDspSysLastRC(h)) != kOkDspRC )
  2055. goto errLabel;
  2056. cmDspSysConnectAudio(h,ain,"out", goer, "in" );
  2057. cmDspSysConnectAudio(h,ain,"out", amtr, "in" );
  2058. cmDspSysConnectAudioN11N(h,sgV, "out", mix, "in", chCnt );
  2059. cmDspSysConnectAudio(h,mix,"out", ao0, "in" );
  2060. cmDspSysConnectAudio(h,mix,"out", ao1, "in" );
  2061. cmDspSysInstallCb( h, igain, "val", ain, "gain", NULL);
  2062. cmDspSysInstallCbN1N1( h, hzV, "val", sgV, "hz", chCnt);
  2063. cmDspSysInstallCbN11N( h, hzV, "val", goer, "hz", chCnt );
  2064. cmDspSysInstallCbN11N( h, gnV, "val", mix, "gain", chCnt);
  2065. cmDspSysInstallCb1NN1( h, goer, "out", mtrV, "in", chCnt );
  2066. cmDspSysInstallCb( h, hop, "val", goer, "hop", NULL );
  2067. errLabel:
  2068. return rc;
  2069. }
  2070. _cmDspSysPgm_t _cmDspSysPgmArray[] =
  2071. {
  2072. { "time_line", _cmDspSysPgm_TimeLine, NULL, NULL },
  2073. { "multi-out", _cmDspSysPgm_MultiOut, NULL, NULL },
  2074. { "multi-in", _cmDspSysPgm_MultiIn, NULL, NULL },
  2075. { "goertzel", _cmDspSysPgm_Goertzel, NULL, NULL },
  2076. { "kr_live", _cmDspSysPgm_KrLive, NULL, NULL },
  2077. { "main", _cmDspSysPgm_Main, NULL, NULL },
  2078. { "array", _cmDspSysPgm_Array, NULL, NULL },
  2079. { "line", _cmDspSysPgm_Line, NULL, NULL },
  2080. { "1Up", _cmDspSysPgm_1Up, NULL, NULL },
  2081. { "PortToSym", _cmDspSysPgm_PortToSym, NULL, NULL },
  2082. { "preset", _cmDspSysPgm_Preset, NULL, NULL },
  2083. { "rsrcWr", _cmDspSysPgm_RsrcWr, NULL, NULL },
  2084. { "router", _cmDspSysPgm_Router, NULL, NULL },
  2085. { "1ofN", _cmDspSysPgm_1ofN, NULL, NULL },
  2086. { "NofM", _cmDspSysPgm_NofM, NULL, NULL },
  2087. { "whirl_net", _cmDspSysPgm_WhirlNet, NULL, NULL },
  2088. { "thunk_net", _cmDspSysPgm_ThunkNet, NULL, NULL },
  2089. { "seq", _cmDspSysPgm_Seq, NULL, NULL },
  2090. { "dist_ds", _cmDspSysPgm_DistDs, NULL, NULL },
  2091. { "bi_quad_eq", _cmDspSysPgm_BiQuadEq, NULL, NULL },
  2092. { "compressor", _cmDspSysPgm_Compressor, NULL, NULL },
  2093. { "adsr", _cmDspSysPgm_Adsr, NULL, NULL },
  2094. { "msg delay", _cmDspSysPgm_MsgDelay, NULL, NULL },
  2095. { "pickup rmod2", _cmDspSysPgm_RingMod2, NULL, NULL },
  2096. { "pickup rmod", _cmDspSysPgm_RingMod, NULL, NULL },
  2097. { "pickup tails", _cmDspSysPgm_NoiseTails, NULL, NULL },
  2098. { "tails_2", _cmDspSysPgm_NoiseTails2, NULL, NULL },
  2099. { "pickups", _cmDspSysPgm_Pickups0, NULL, NULL },
  2100. { "sync_recd", _cmDspSysPgm_SyncRecd, NULL, NULL },
  2101. { "midi_test", _cmDspSysPgm_Test_Midi, NULL, NULL },
  2102. { "2_thru", _cmDspSysPgm_Stereo_Through, NULL, NULL },
  2103. { "guitar", _cmDspSysPgmGuitar, NULL, NULL },
  2104. { "2_fx", _cmDspSysPgm_Stereo_Fx, NULL, NULL },
  2105. { "sine", _cmDspSysPgm_PlaySine, NULL, NULL },
  2106. { "file", _cmDspSysPgm_PlayFile, NULL, NULL },
  2107. { "gate_detect", _cmDspSysPgm_GateDetect, NULL, NULL },
  2108. { "record", _cmDspSysPgm_Record, NULL, NULL },
  2109. { "pitch_shift", _cmDspSysPgm_PitchShiftFile, NULL, NULL },
  2110. { "loop_recd", _cmDspSysPgm_LoopRecd, NULL, NULL },
  2111. { "ui_test", _cmDspSysPgm_UiTest, NULL, NULL },
  2112. { "xfade_test", _cmDspSysPgm_Xfade, NULL, NULL },
  2113. { "auto_gain", _cmDspSysPgm_AutoGain, NULL, NULL },
  2114. { "comb filt", _cmDspSysPgm_CombFilt, NULL, NULL },
  2115. { "scalar op", _cmDspSysPgm_ScalarOp, NULL, NULL },
  2116. { "seg_line", _cmDspSysPgm_SegLine, NULL, NULL },
  2117. { "avail_ch", _cmDspSysPgm_AvailCh, NULL, NULL },
  2118. { NULL , NULL, NULL, NULL }
  2119. };
  2120. _cmDspSysPgm_t* _cmDspSysPgmArrayBase()
  2121. {
  2122. return _cmDspSysPgmArray;
  2123. }