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 128KB

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