Advertisement
S_Fang

Untitled

Nov 27th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright 2007, Thomas Scott Stillwell
  2. // All rights reserved.
  3. //
  4. //Redistribution and use in source and binary forms, with or without modification, are permitted
  5. //provided that the following conditions are met:
  6. //
  7. //Redistributions of source code must retain the above copyright notice, this list of conditions
  8. //and the following disclaimer.
  9. //
  10. //Redistributions in binary form must reproduce the above copyright notice, this list of conditions
  11. //and the following disclaimer in the documentation and/or other materials provided with the distribution.
  12. //
  13. //The name of Thomas Scott Stillwell may not be used to endorse or
  14. //promote products derived from this software without specific prior written permission.
  15. //
  16. //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  17. //IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. //FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  19. //BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  22. //STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. //THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24.  
  25. desc:Downward Expander
  26. desc:Downward Expander [Stillwell]
  27. //tags: dynamics expander
  28. //author: Stillwell
  29.  
  30. slider1:-120<-120,0,0.1>Threshold (dB)
  31. slider2:1<1,100,0.1>Ratio
  32. slider3:0<-20,20,0.1>Gain
  33. slider4:0<0,1,1{Normal,Sidechain}>Detector Input
  34. slider5:0<0,1,1{Peak,RMS}>Detection
  35. slider6:30<0,200,1>Attack (ms)
  36. slider7:2<0,500,1>Release (ms)
  37. slider8:0<0,1,1{Off,On}>Auto Makeup
  38.  
  39. in_pin:left input
  40. in_pin:right input
  41. in_pin:sidechain left input
  42. in_pin:sidechain right input
  43. out_pin:left output
  44. out_pin:right output
  45.  
  46. @init
  47. log2db = 8.6858896380650365530225783783321; // 20 / ln(10)
  48. db2log = 0.11512925464970228420089957273422; // ln(10) / 20
  49. attime=slider6 * 0.001;
  50. reltime=slider7 * 0.001;
  51. maxover=0;
  52. ratio=0;
  53. cratio=0;
  54. rundb=0;
  55. overdb=0;
  56. maxover=0;
  57. atcoef=exp(-1/(attime * srate));
  58. relcoef=exp(-1/(reltime * srate));
  59. fbacoef=exp(-1000/(2 * srate)); // 2 msec. opto attack for feedback detection
  60. fbrcoef=exp(-1000/(200 * srate)); // 200 msec. opto release for feedback detection
  61. sidechain = 0;
  62. automakeup = 0;
  63.  
  64. @slider
  65. thresh = slider1;
  66. threshv = exp(thresh * db2log);
  67. ratio = slider2;
  68. sidechain = slider4;
  69. makeup = slider3;
  70. makeupv = exp((makeup) * db2log);
  71. RMSdet = slider5;
  72. RMSdet ? (
  73. rmscoef=exp(-1000/(10 * srate)); // 10 ms RMS window
  74. ) : (
  75. rmscoef=exp(-1000/(0.0025 * srate)); // 2.5 us Peak detector
  76. );
  77. attime=slider6 * 0.001;
  78. reltime=slider7 * 0.001;
  79. atcoef=exp(-1/(attime * srate));
  80. relcoef=exp(-1/(reltime * srate));
  81. automakeup=slider8
  82.  
  83. @sample
  84. sidechain ? (
  85. aspl0 = abs(spl2);
  86. aspl1 = abs(spl3);
  87. ) : (
  88. aspl0 = abs(spl0);
  89. aspl1 = abs(spl1);
  90. );
  91.  
  92. RMSDet ? (
  93. ave = (aspl0 * aspl0) + (aspl1 * aspl1);
  94. runave = ave + rmscoef * (runave - ave);
  95. det = sqrt(max(0,runave));
  96. ) : (
  97. maxspl = max(aspl0, aspl1);
  98. maxspl = maxspl * maxspl;
  99. runave = maxspl + rmscoef * (runave - maxspl);
  100. det = sqrt(max(0,runave));
  101. );
  102. overdb = 2.08136898 * log(det/threshv) * log2db;
  103. overdb = min(0,overdb);
  104.  
  105. overdb > rundb ? (
  106. rundb = overdb + atcoef * (rundb - overdb);
  107. ) : (
  108. rundb = overdb + relcoef * (rundb - overdb);
  109. );
  110. overdb = rundb;
  111.  
  112. cratio = (softknee ? (1 + (ratio-1) * min(overdb, 6) / 6) : ratio);
  113.  
  114. gr = overdb * (cratio-1)/cratio;
  115. grv = exp(gr * db2log);
  116.  
  117. spl0 *= grv * makeupv;
  118. spl1 *= grv * makeupv;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement