home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 July & August / PCWorld_2007-07-08_cd.bin / audio-video / reaper / reaper1861-install.exe / Effects / SStillwell / 1175 next >
Text File  |  2007-02-27  |  4KB  |  105 lines

  1. // Copyright 2006, 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. desc:FAST attack compressor with prog-dependent release
  25.  
  26. slider1:0<-60,0,0.1>Threshold (dB)
  27. slider2:1<0,3,1{4,8,12,20,All}>Ratio
  28. slider3:0<-20,20,0.1>Gain
  29. slider4:20<20,2000,10>Attack time (usec.)
  30. slider5:250<20,1000,1>Release time (msec.)
  31. slider6:100<0,100,0.1>Mix%
  32.  
  33. @init
  34.   log2db = 8.6858896380650365530225783783321; // 20 / ln(10)
  35.   db2log = 0.11512925464970228420089957273422; // ln(10) / 20 
  36.   attime=0.010;
  37.   reltime=0.100;
  38.   ratio=0;
  39.   cratio=0;
  40.   rundb=0;
  41.   overdb=0;
  42.   ratatcoef = exp(-1/(0.00001 * srate));
  43.   ratrelcoef = exp(-1/(0.5 * srate));
  44.   atcoef=exp(-1/(attime * srate));
  45.   relcoef=exp(-1/(reltime * srate));
  46.   mix=1;
  47.  
  48. @slider
  49.   thresh = slider1;
  50.   threshv = exp(thresh * db2log);
  51.   ratio = (slider2==0 ? 4 : (slider2==1 ? 8 : (slider2 == 2 ? 12 : (slider2 == 3 ? 20 : 20 ))));
  52.   slider2 == 4 ? (allin=1; cratio=20;) : (allin=0; cratio = ratio;);
  53.   cthresh = (softknee ? (thresh -3) : thresh);
  54.   cthreshv = exp(cthresh * db2log);
  55.   makeup = slider3;
  56.   makeupv = exp((makeup+autogain) * db2log);
  57.   attime = slider4 / 1000000;
  58.   reltime = slider5 / 1000;
  59.   atcoef=exp(-1/(attime * srate));
  60.   relcoef=exp(-1/(reltime * srate));
  61.   mix=slider6/100;
  62.  
  63. @sample
  64.   ospl0 = spl0;
  65.   ospl1 = spl1;
  66.   aspl0 = abs(spl0);
  67.   aspl1 = abs(spl1);
  68.   maxspl = max(aspl0, aspl1);
  69.   maxspl = maxspl * maxspl;
  70.   runave = maxspl + rmscoef * (runave - maxspl);
  71.   det = sqrt(max(0,runave));
  72.  
  73.   overdb = 2.08136898 * log(det/cthreshv) * log2db;
  74.   overdb = max(0,overdb);
  75.  
  76.   overdb - rundb > 5 ? (averatio = 4;);
  77.  
  78.   overdb > rundb ? (
  79.     rundb = overdb + atcoef * (rundb - overdb);
  80.     runratio = averatio + ratatcoef * (runratio - averatio);
  81.   ) : (
  82.     rundb = overdb + relcoef * (rundb - overdb);
  83.     runratio = averatio + ratrelcoef * (runratio - averatio);
  84.   );
  85.   overdb = rundb;
  86.   averatio = runratio;
  87.  
  88.   allin ? (
  89.     cratio = 12 + averatio;
  90.   ) : (
  91.     cratio = ratio;
  92.   );
  93.   
  94.   gr = -overdb * (cratio-1)/cratio;
  95.   grv = exp(gr * db2log);
  96.   
  97.   runmax = maxover + relcoef * (runmax - maxover);  // highest peak for setting att/rel decays in reltime
  98.   maxover = runmax;
  99.  
  100.   spl0 *= grv * makeupv * mix;
  101.   spl1 *= grv * makeupv * mix;  
  102.   
  103.   spl0 += ospl0 * (1-mix);
  104.   spl1 += ospl1 * (1-mix);
  105.