Advertisement
cpoovey

Spectral EQ

Apr 25th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. <Cabbage>
  2. form caption("SpectralEQ") size(1008, 200), colour(47, 79, 79), pluginid("speq") identchannel("formID")
  3. combobox text("fft size") channel("fftSize") items("512","1024", "2048", "4096", "8192", "16384") value(4) bounds(8,8,80,20)
  4. label text("fft size") bounds(100, 12, 80, 10) align("left")
  5. button text("Randomize") channel("rand") bounds(175,5,80,20) value(1)
  6. button text("zero table") channel("zero") bounds (175,28,80,20)
  7. combobox items("Gaussian","Poisson","Uniform","Linear","Exponential") bounds(255,5,80,20) channel("rType")
  8. gentable tablenumber(101) bounds(8,50,992, 140) amprange(0,2, 101, 0.01) identchannel("table") tablegridcolour(0,0,0,0) tablecolour:N(72, 209, 204) tablebackgroundcolour(27, 59, 59)
  9. label text("Click on the table to draw!") bounds(8,35,140,12) align("left")
  10. button text("store to user defined table") bounds(350,5,150,20) channel("uTabS")
  11. button text("recall to user defined table") bounds(350,25,150,20) channel("uTabR")
  12. nslider text("User Table") bounds(500,5,50,30) range(1,10,1,1,1) channel("uTab")
  13. groupbox text("tween") bounds(700,0,300,45){
  14. nslider channel("beg") range(1,10,1,1,1) bounds(8,22,20,20) value(2)
  15. nslider channel ("end")range(1,10,1,1,1) bounds(272,22,20,20) value(3)
  16. hslider channel ("tween") bounds(38,22,242,20) range(0,1,0,1,0.001)
  17. }
  18. filebutton text("save table list") bounds(550,5,75,20) channel("save") file("specEqDef.speceq") value(0) mode("save")
  19. filebutton text("load table list") bounds(550,25,75,20) channel("load") file("specEqDef.speceq") value(0) mode("file") populate("*.speceq")
  20. label bounds(627,28,70,15) identchannel("filename_id") align("left") text(" ")
  21. </Cabbage>
  22. <CsoundSynthesizer>
  23. <CsOptions>
  24. -n -d -+rtmidi=NULL -M0 -m0d
  25. </CsOptions>
  26. <CsInstruments>
  27. ; Initialize the global variables.
  28. ksmps = 128
  29. nchnls = 2
  30. 0dbfs = 1
  31.  
  32.  
  33. instr update
  34. ;Gui Data
  35. kMouseX chnget "MOUSE_X"
  36. kMouseY chnget "MOUSE_Y"
  37. kMouseLeft chnget "MOUSE_DOWN_LEFT"
  38. iGuiX = 992
  39. iGuiY= 140
  40. kRand init 0
  41. kZero chnget "zero"
  42.  
  43.  
  44. kFftSize chnget "fftSize"
  45. kRand chnget "rand"
  46. kZero chnget "zero"
  47. kFlat chnget "flat"
  48.  
  49. iBands init 100 ;Number of bands must be declaired before run
  50. ;Variable for tweening
  51. kUTab chnget "uTab"
  52. kUTabS chnget "uTabS"
  53. kUTabR chnget "uTabR"
  54. kTween chnget "tween"
  55. SloadFile chnget "load"
  56. SsaveFile chnget "save"
  57.  
  58.  
  59. iTables = 10 ;Number of user defined tables
  60. iCount = 0
  61.  
  62.  
  63. if changed(kFftSize)==1 then
  64. turnoff2 1, 0, 0
  65. reinit makeArray
  66. endif
  67.  
  68. iRandomTypes[] fillarray 6, 11, 1, 2, 4 ;Types of randomness
  69.  
  70. giTab ftgen 101, 0, -iBands, 2, 0 ;generate band table
  71.  
  72. ;Create the user defined tables
  73. until iCount >= iTables do
  74. giUTab ftgen 200+iCount+1, 0, -iBands, 2, 0
  75. iCount += 1
  76. od
  77.  
  78.  
  79.  
  80. makeArray:
  81. giFftSize = pow(2,i(kFftSize)+8)
  82. kFftFilter[] init giFftSize
  83. kBeg[] init giFftSize
  84. kEnd[] init giFftSize
  85. kTweened[] init giFftSize
  86. iclock rtclock
  87. giTab ftgen 102, 0, -(giFftSize+1), 2, 1
  88. event_i "i", 1, 0, pow(9999,9999)
  89. rireturn
  90.  
  91.  
  92. if changed(SloadFile)==1 then
  93. event "i", "loadUTabs", 0, 0.5
  94. endif
  95. if changed(SsaveFile)==1 then
  96. event "i", "saveUTabs", 0, 0.5
  97. endif
  98.  
  99.  
  100. if changed(kUTabS) == 1 then ;Store selected table
  101. reinit saveTab
  102. saveTab:
  103. iTabU = chnget("uTab")
  104. tableicopy iTabU+200, 101
  105.  
  106.  
  107. rireturn
  108. endif
  109.  
  110. if changed(kUTabR) == 1 then ;Read selected table
  111. reinit readTab
  112. readTab:
  113. iTabU = chnget("uTab")
  114. tableicopy 101 ,iTabU+200
  115. chnset "tablenumber(101)", "table"
  116. ;chnset ftlen(iTabU+200), "fftSize"
  117.  
  118. rireturn
  119. endif
  120.  
  121. if changed(kTween) == 1 then ;Tween between 2 tables
  122. reinit morph
  123. morph:
  124. iTabB = 200+chnget("beg")
  125. copyf2array kBeg, iTabB
  126. iTabE = 200+chnget("end")
  127. copyf2array kEnd, iTabE
  128.  
  129.  
  130. kBeg *= 1-kTween
  131. kEnd *= kTween
  132. kTweened = kBeg+kEnd
  133. kCount = 0
  134.  
  135. copya2ftab kTweened, 101
  136. chnset "tablenumber(101)", "table"
  137. rireturn
  138.  
  139. endif
  140.  
  141. if changed(kRand) == 1 then
  142. reinit makeRandTab
  143. makeRandTab:
  144. iRType chnget "rType"
  145. giTab ftgen 101, 0, -iBands, 21, iRandomTypes[iRType], 1
  146. chnset "tablenumber(101)", "table"
  147.  
  148. rireturn
  149. endif
  150.  
  151. if changed(kZero) == 1 then
  152. reinit zero
  153. zero:
  154. giTab ftgen 101, 0, -iBands, 2, 0
  155. chnset "tablenumber(101)", "table"
  156. rireturn
  157. endif
  158.  
  159.  
  160. ;Code for translating mouse position to bands
  161. if (kMouseLeft == 1) then
  162. if ((kMouseX >= 8) && (kMouseX <=1000)) then
  163. if ((kMouseY >= 50) && (kMouseY <=190)) then
  164. kPos = floor((kMouseX-8)/iGuiX*iBands)
  165. tablew 2-((kMouseY-50)/iGuiY)*2, kPos, 101
  166. chnset "tablenumber(101)", "table"
  167. endif
  168. endif
  169. endif
  170.  
  171.  
  172.  
  173.  
  174.  
  175. updateTable:
  176.  
  177. kthisBin = 0
  178.  
  179. until kthisBin >= giFftSize do
  180. kthisBand = floor(pow(kthisBin/(giFftSize),0.9)*iBands*2.1)
  181. kBinVal table kthisBand, 101
  182. kFftFilter[kthisBin] = abs(kBinVal)*2
  183. kthisBin += 1
  184. od
  185. copya2ftab kFftFilter, 102
  186.  
  187.  
  188.  
  189.  
  190. endin
  191.  
  192. instr saveUTabs
  193. Sname chnget "save"
  194. Sname strcat Sname, ".speceq"
  195. chnset Sname, "load"
  196.  
  197. ftsave Sname, 1, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210
  198.  
  199.  
  200. endin
  201.  
  202. instr loadUTabs
  203. Sname chnget "load"
  204. prints Sname
  205. ftload Sname, 1, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210
  206. chnset 2, "uTabR"
  207.  
  208.  
  209.  
  210. endin
  211.  
  212. instr 1
  213. ;fft filter
  214. aIn1 inch 1
  215. aIn2 inch 2
  216.  
  217. fIn1 pvsanal aIn1, giFftSize, giFftSize/6, giFftSize, 0
  218. fIn2 pvsanal aIn2, giFftSize, giFftSize/6, giFftSize, 0
  219. kDepth init 1
  220. fEq1 pvsmaska fIn1,102,kDepth
  221. fEq2 pvsmaska fIn2,102,kDepth
  222. aOut1 pvsynth fEq1
  223. aOut2 pvsynth fEq2
  224.  
  225. outs aOut1, aOut2
  226. endin
  227.  
  228. </CsInstruments>
  229. <CsScore>
  230. ;causes Csound to run for about 7000 years...
  231. f0 z
  232. ;starts instrument 1 and runs it for a week
  233. i "update" 0 z
  234. i "loadUTabs" 0.1 0.1
  235.  
  236.  
  237.  
  238.  
  239.  
  240. </CsScore>
  241. </CsoundSynthesizer>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement