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.

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