libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmDspPgm.c 144KB

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