Extra "ports" of juce-based plugins using the distrho build system
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.

154 lines
6.6KB

  1. ; Reverse.csd
  2. ; Iain McCurdy [2012]
  3. ;
  4. ; Buffers audio for reversed (and forward) playback.
  5. ;
  6. ; INSTRUCTIONS
  7. ; ------------
  8. ; Time L -- length of the left channel delay buffer
  9. ; Time R -- length of the right channel delay buffer
  10. ; Spread -- stereo spread of the two channel. 1 = hard left and right
  11. ; Mix -- dry/wet mix
  12. ; Level -- output level
  13. ; Reverse -- (switch) activate reversed buffer
  14. ; Forward -- (switch) activate forward buffer
  15. ; Link L&R -- (switch) pair the left and right Time controls (functions differently if 'Time Mod' is activated)
  16. ; Time Mod -- (switch) if this switch is on the delay times for both channels will modulate randomly between 'Time L' and 'Time R'. If 'Link L&R' is active this modulation is done in tandem for both channels.
  17. ; Pan Mod -- (switch) if this switch is on the panning modulates randomly
  18. <Cabbage>
  19. form caption("Reverse") size(455, 95), pluginID("rvrs")
  20. image bounds(0, 0, 455, 95), colour("darkslategrey"), shape("rounded"), outline("white"), line(4)
  21. rslider bounds( 10, 10, 75, 75), text("Time L"), channel("timeL"), range(0.010, 4, 1, 0.5,0.001),colour(darkslategrey) fontcolour(255,255,200), trackercolour(lightblue)
  22. rslider bounds( 80, 10, 75, 75), text("Time R"), channel("timeR"), range(0.010, 4, 1, 0.5,0.001),colour(darkslategrey) fontcolour(255,255,200), trackercolour(lightblue)
  23. rslider bounds(150, 10, 75, 75), text("Spread"), channel("spread"), range(0, 1.00, 1), colour(darkslategrey) fontcolour(255,255,200), trackercolour(lightblue)
  24. rslider bounds(220, 10, 75, 75), text("Mix"), channel("mix"), range(0, 1.00, 1), colour(darkslategrey) fontcolour(255,255,200), trackercolour(lightblue)
  25. rslider bounds(290, 10, 75, 75), text("Level"), channel("level"), range(0, 1.00, 1, 0.5), colour(darkslategrey) fontcolour(255,255,200), trackercolour(lightblue)
  26. checkbox bounds(370, 12, 100, 12), text("Reverse"), channel("reverse"), value(1), colour(255,255, 50) fontcolour(255,255,200)
  27. checkbox bounds(370, 27, 100, 12), text("Forward"), channel("forward"), value(0), colour(255,255, 50) fontcolour(255,255,200)
  28. checkbox bounds(370, 42, 100, 12), text("Link L&R"), channel("link"), value(0), colour(255,255, 50) fontcolour(255,255,200)
  29. checkbox bounds(370, 57, 100, 12), text("Time Mod."), channel("TMod"), value(0), colour(255,255, 50) fontcolour(255,255,200)
  30. checkbox bounds(370, 72, 100, 12), text("Pan Mod."), channel("PMod"), value(0), colour(255,255, 50) fontcolour(255,255,200)
  31. }
  32. </Cabbage>
  33. <CsoundSynthesizer>
  34. <CsOptions>
  35. -d -n
  36. </CsOptions>
  37. <CsInstruments>
  38. sr = 44100
  39. ksmps = 32
  40. nchnls = 2
  41. 0dbfs = 1
  42. ;Author: Iain McCurdy (2012)
  43. ;http://iainmccurdy.org/csound.html
  44. opcode Reverse, a, aKkkk ;nb. CAPITAL K CREATE A K-RATE VARIABLE THAT HAS A USEFUL VALUE ALSO AT I-TIME
  45. ain,ktime,kreverse,kforward,klink xin ;READ IN INPUT ARGUMENTS
  46. ;four windowing envelopes. An appropriate one will be chosen based on the reversed chunk duration
  47. ienv1 ftgenonce 0, 0, 131072, 7, 0, 1024, 1, 131072-(1024*2), 1, 1024, 0 ;for longest chunk times
  48. ienv2 ftgenonce 0, 0, 131072, 7, 0, 4096, 1, 131072-(4096*2), 1, 4096, 0
  49. ienv3 ftgenonce 0, 0, 131072, 7, 0,16384, 1, 131072-(16384*2), 1, 16384, 0
  50. ienv4 ftgenonce 0, 0, 131072, 7, 0,32768, 1, 131072-(32768*2), 1, 32768, 0 ;for shortest chunk times
  51. atime interp ktime ;INTERPOLATE TO CREATE A-RATE VERSION OF K-TIME
  52. iratio = octave(1)
  53. ktrig trigger klink,0.5,0 ;if 'Link L&R' is turned on restart delay time phasors to ensure sync between the two channels
  54. if ktrig=1 then
  55. reinit RESTART_PHASOR
  56. endif
  57. RESTART_PHASOR:
  58. aptr phasor (2/ktime) ;CREATE A MOVING PHASOR THAT WITH BE USED TO TAP THE DELAY BUFFER
  59. rireturn
  60. if ktime<0.2 then ;IF CHUNK TIME IS LESS THAN 0.2... (VERY SHORT)
  61. aenv table3 aptr,ienv4,1 ;CREATE AMPLITUDE ENVELOPE
  62. elseif ktime<0.4 then
  63. aenv table3 aptr,ienv3,1
  64. elseif ktime<2 then
  65. aenv table3 aptr,ienv2,1
  66. else ;other longest bracket of delay times
  67. aenv table3 aptr,ienv1,1
  68. endif
  69. aptr = aptr*atime ;SCALE PHASOR ACCORDING TO THE LENGTH OF THE DELAY TIME CHOSEN BY THE USER
  70. abuffer delayr 4 ;+ 0.01 ;CREATE A DELAY BUFFER
  71. abwd deltap3 aptr ;READ AUDIO FROM A TAP WITHIN THE DELAY BUFFER
  72. afwd deltap3 atime ;FORWARD DELAY
  73. delayw ain ;WRITE AUDIO INTO DELAY BUFFER
  74. ;rireturn ;RETURN FROM REINITIALISATION PASS
  75. xout (abwd*aenv*kreverse)+(afwd*kforward) ;SEND AUDIO BACK TO CALLER INSTRUMENT. APPLY AMPLITUDE ENVELOPE TO PREVENT CLICKS.
  76. endop
  77. instr 1
  78. ktimeL chnget "timeL"
  79. ktimeR chnget "timeR"
  80. kspread chnget "spread"
  81. kmix chnget "mix"
  82. klevel chnget "level"
  83. kreverse chnget "reverse"
  84. kforward chnget "forward"
  85. kTMod chnget "TMod"
  86. kPMod chnget "PMod"
  87. /* LINK */
  88. klink chnget "link" ; if 'Link L&R' is selected
  89. if klink=1&&kTMod=0 then
  90. ktrigL changed ktimeL,klink
  91. ktrigR changed ktimeR
  92. if ktrigL=1 then
  93. chnset ktimeL,"timeR"
  94. elseif ktrigR=1 then
  95. chnset ktimeR,"timeL"
  96. endif
  97. endif
  98. a1,a2 ins
  99. if kTMod=1 then ; if time modulation is selected....
  100. if klink=0 then ; and if 'link L&R' is off...
  101. ktime1 rspline ktimeL,ktimeR,0.2,1 ; generate delay time value: random spline between ktimeL and ktimeR
  102. ktime2 rspline ktimeL,ktimeR,0.2,1
  103. ktimeL limit ktime1,0.01,4 ; assign to delay time variable and limit to prevent out of range values (possible with rspline)
  104. ktimeR limit ktime2,0.01,4
  105. else
  106. ktime rspline ktimeL,ktimeR,0.2,1
  107. ktimeL limit ktime,0.01,4
  108. ktimeR = ktimeL ; right channel delay the same as left
  109. endif
  110. endif
  111. arev1 Reverse a1,ktimeL,kreverse,kforward,klink ; call UDO
  112. arev2 Reverse a2,ktimeR,kreverse,kforward,klink
  113. if kPMod=1 then ; if panning modulation is on...
  114. kpan rspline 0,1,0.2,1 ; pan position generated as a random spline
  115. ap1 = (arev1*kpan) + (arev2*(1-kpan)) ; create new left channel
  116. ap2 = (arev1*(1-kpan)) + (arev2*kpan) ; create new right channel
  117. arev1 = ap1 ; reassign left channel to new left channel
  118. arev2 = ap2 ; reassign right channel to new right channel
  119. endif
  120. a1 ntrpol a1,arev1,kmix ; dry/wet mix
  121. a2 ntrpol a2,arev2,kmix
  122. a1 = a1 * klevel ; apply level control
  123. a2 = a2 * klevel
  124. kspread scale kspread,1,0.5 ; rescale from range 0 - 1 to 0.5 - 1
  125. aL sum a1*kspread,a2*(1-kspread) ; create stereo mix according to Spread control
  126. aR sum a2*kspread,a1*(1-kspread) ; create stereo mix according to Spread control
  127. outs aL,aR
  128. endin
  129. </CsInstruments>
  130. <CsScore>
  131. i 1 0 [60*60*24*7]
  132. </CsScore>
  133. </CsoundSynthesizer>