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.

167 lines
8.2KB

  1. Convolution Reverb
  2. ------------------
  3. You are encouraged to experiment with different impulse files.
  4. You can find some here: http://www.openairlib.net/
  5. The one I reference in this example can be found here: http://www.iainmccurdy.org/CsoundRealtimeExamples/SourceMaterials/Stairwell.wav
  6. NOTE THAT ZERO LATENCY (or close to zero) CONV0LUTION WILL NOT BE POSSIBLE.
  7. Instructions
  8. ------------
  9. 'Size Ratio' compresses the duration of the impulse file (provided that 'compressed' is chosen for 'resize' mode).
  10. 'Curve' defines the shape of an envelope applied to compressed impulse files using GEN16
  11. zero = straight line decaying
  12. positive vals. = increasingly convex decaying
  13. negative vals = increasingly concave decaying
  14. Increase 'iplen' (must be a power of 2) if experiencing performance problems, or reduce it to reduce latency.
  15. 'Delay OS' fine tunes the delay applied to the dry signal. Normally this should be zero but adjust it to modify how the dry signal lines up with the convoluted signal.
  16. <Cabbage>
  17. form caption("Convolution Reverb") size(505, 90), pluginID("Conv")
  18. image bounds(0, 0, 505, 90), colour(135, 30, 30,220), shape("rounded"), outline(255,255,150), line(4)
  19. button bounds( 10, 10, 90, 20), text("forward","backward"), channel("FwdBwd"), value(0), fontcolour(250,250,250)
  20. label bounds( 30, 30, 60, 12), text("direction"), fontcolour(250,250,250)
  21. button bounds( 10, 50, 90, 20), text("normal","compressed"), channel("resize"), value(0), fontcolour(250,250,250)
  22. label bounds( 35, 70, 60, 12), text("resize"), fontcolour(250,250,250)
  23. rslider bounds(105, 11, 70, 70), text("Size Ratio"), colour(135, 30, 30), trackercolour(255,255,150), fontcolour(250,250,250), channel("CompRat"), range(0, 1.00, 1)
  24. rslider bounds(170, 11, 70, 70), text("Curve"), colour(135, 30, 30), trackercolour(255,255,150), fontcolour(250,250,250), channel("Curve"), range(-8.00, 8.00, 0)
  25. rslider bounds(235, 11, 70, 70), text("In Skip"), colour(135, 30, 30), trackercolour(255,255,150), fontcolour(250,250,250), channel("skipsamples"), range(0, 1.00, 0)
  26. rslider bounds(300, 11, 70, 70), text("Del.OS."), colour(135, 30, 30), trackercolour(255,255,150), fontcolour(250,250,250), channel("DelayOS"), range(-1.00, 1.00, 0)
  27. rslider bounds(365, 11, 70, 70), text("Mix"), colour(135, 30, 30), trackercolour(255,255,150), fontcolour(250,250,250), channel("mix"), range(0, 1.00, 0.25)
  28. rslider bounds(430, 11, 70, 70), text("Level"), colour(135, 30, 30), trackercolour(255,255,150), fontcolour(250,250,250), channel("level"), range(0, 1.00, 0.4)
  29. }
  30. </Cabbage>
  31. <CsoundSynthesizer>
  32. <CsOptions>
  33. -d -n
  34. </CsOptions>
  35. <CsInstruments>
  36. sr = 44100 ;SAMPLE RATE
  37. ksmps = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
  38. nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
  39. 0dbfs = 1
  40. ;Author: Iain McCurdy (2012)
  41. ; IMPULSE RESPONSES STORED AS STEREO GEN01 FUNCTION TABLES
  42. giImpulse ftgen 1, 0, 262144, 1, "stairwell.wav", 0, 0, 0 ;stereo file, duration 1.176s
  43. ; reverse function table UDO
  44. opcode tab_reverse,i,i
  45. ifn xin
  46. iTabLen = nsamp(ifn)
  47. iTableRev ftgen ifn+100,0,-iTabLen,-2, 0
  48. icount = 0
  49. loop:
  50. ival table iTabLen-icount-1, ifn
  51. tableiw ival,icount,iTableRev
  52. loop_lt icount,1,iTabLen,loop
  53. xout iTableRev
  54. endop
  55. ; compress function table UDO
  56. opcode tab_compress,i,iii
  57. ifn,iCompRat,iCurve xin
  58. iTabLen = nsamp(ifn)
  59. iTabLenComp = int(nsamp(ifn)*iCompRat)
  60. iTableComp ftgen ifn+200,0,-iTabLenComp,-2, 0
  61. iAmpScaleTab ftgen ifn+300,0,-iTabLenComp,-16, 1,iTabLenComp,iCurve,0
  62. icount = 0
  63. loop:
  64. ival table icount, ifn
  65. iAmpScale table icount, iAmpScaleTab
  66. tableiw ival*iAmpScale,icount,iTableComp
  67. loop_lt icount,1,iTabLenComp,loop
  68. xout iTableComp
  69. endop
  70. ; compress reverse function table UDO
  71. opcode tab_compress_rev,i,iii
  72. ifn,iCompRat,iCurve xin
  73. iTabLen = nsamp(ifn)
  74. iTabLenComp = int(nsamp(ifn)*iCompRat)
  75. iTableComp ftgen ifn+400,0,-iTabLenComp,-2, 0
  76. iAmpScaleTab ftgen ifn+500,0,-iTabLenComp,-16, 1,iTabLenComp,iCurve,0
  77. icount = 0
  78. loop:
  79. ival table icount, ifn
  80. iAmpScale table icount, iAmpScaleTab
  81. tableiw ival*iAmpScale, iTabLenComp-icount-1,iTableComp
  82. loop_lt icount,1,iTabLenComp,loop
  83. xout iTableComp
  84. endop
  85. instr 1 ;CONVOLUTION REVERB INSTRUMENT
  86. kFwdBwd chnget "FwdBwd"
  87. kresize chnget "resize"
  88. kmix chnget "mix"
  89. klevel chnget "level"
  90. kCompRat chnget "CompRat"
  91. kCurve chnget "Curve"
  92. kskipsamples chnget "skipsamples"
  93. kDelayOS chnget "DelayOS"
  94. kCompRat init 1 ;IF THIS IS LEFT UNINITIALISED A CRASH WILL OCCUR!
  95. ainL,ainR ins ;READ STEREO AUDIO INPUT
  96. ;ainL,ainR diskin2 "808loop.wav",1,0,1 ;USE A SOUND FILE FOR TESTING
  97. ainMix sum ainL,ainR
  98. ;CREATE REVERSED TABLES
  99. irev tab_reverse giImpulse
  100. kSwitch changed kskipsamples,kFwdBwd,kDelayOS,kCompRat,kCurve ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
  101. if kSwitch=1 then ;IF I-RATE VARIABLE IS CHANGED...
  102. reinit UPDATE ;BEGIN A REINITIALISATION PASS IN ORDER TO EFFECT THIS CHANGE. BEGIN THIS PASS AT LABEL ENTITLED 'UPDATE' AND CONTINUE UNTIL rireturn OPCODE
  103. endif ;END OF CONDITIONAL BRANCHING
  104. UPDATE: ;LABEL
  105. ;CREATE COMPRESSED TABLES
  106. icomp tab_compress giImpulse,i(kCompRat),i(kCurve)
  107. ;CREATE COMPRESSED REVERSED TABLES
  108. icomprev tab_compress_rev giImpulse,i(kCompRat),i(kCurve)
  109. iplen = 1024 ;BUFFER LENGTH (INCREASE IF EXPERIENCING PERFORMANCE PROBLEMS, REDUCE IN ORDER TO REDUCE LATENCY)
  110. itab = giImpulse ;DERIVE FUNCTION TABLE NUMBER OF CHOSEN TABLE FOR IMPULSE FILE
  111. iirlen = nsamp(itab)*0.5 ;DERIVE THE LENGTH OF THE IMPULSE RESPONSE IN SAMPLES. DIVIDE BY 2 AS TABLE IS STEREO.
  112. iskipsamples = nsamp(itab)*0.5*i(kskipsamples) ;DERIVE INSKIP INTO IMPULSE FILE. DIVIDE BY 2 (MULTIPLY BY 0.5) AS ALL IMPULSE FILES ARE STEREO
  113. ;FORWARDS REVERB
  114. if kFwdBwd==0&&kresize==0 then
  115. aL,aR ftconv ainMix, itab, iplen,iskipsamples, iirlen ;CONVOLUTE INPUT SOUND
  116. adelL delay ainL, abs((iplen/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE
  117. adelR delay ainR, abs((iplen/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE
  118. ;BACKWARDS REVERB
  119. elseif kFwdBwd==1&&kresize==0 then
  120. aL,aR ftconv ainMix, irev, iplen, iskipsamples, iirlen ;CONVOLUTE INPUT SOUND
  121. adelL delay ainL,abs((iplen/sr)+(iirlen/sr)-(iskipsamples/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE AND THE DURATION OF THE IMPULSE FILE
  122. adelR delay ainR,abs((iplen/sr)+(iirlen/sr)-(iskipsamples/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE AND THE DURATION OF THE IMPULSE FILE
  123. elseif kFwdBwd==0&&kresize==1 then
  124. aL,aR ftconv ainMix, icomp, iplen,iskipsamples, iirlen*i(kCompRat) ;CONVOLUTE INPUT SOUND
  125. adelL delay ainL, abs((iplen/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE
  126. adelR delay ainR, abs((iplen/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE
  127. elseif kFwdBwd==1&&kresize==1 then
  128. aL,aR ftconv ainMix, icomprev, iplen, iskipsamples, iirlen*i(kCompRat) ;CONVOLUTE INPUT SOUND
  129. adelL delay ainL,abs((iplen/sr)+((iirlen*i(kCompRat))/sr)-(iskipsamples/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE AND THE DURATION OF THE IMPULSE FILE
  130. adelR delay ainR,abs((iplen/sr)+((iirlen*i(kCompRat))/sr)-(iskipsamples/sr)+i(kDelayOS)) ;DELAY THE INPUT SOUND ACCORDING TO THE BUFFER SIZE AND THE DURATION OF THE IMPULSE FILE
  131. endif
  132. ; CREATE A DRY/WET MIX
  133. aMixL ntrpol adelL,aL*0.1,kmix
  134. aMixR ntrpol adelR,aR*0.1,kmix
  135. outs aMixL*klevel,aMixR*klevel
  136. endin
  137. </CsInstruments>
  138. <CsScore>
  139. i 1 0 3600 ;INSTRUMENT 2 (CONVOLUTION INSTRUMENT) RUNS FOR 1 HOUR (AND KEEPS REAL-TIME PERFORMANCE GOING)
  140. </CsScore>
  141. </CsoundSynthesizer>