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

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