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

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