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

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