home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February / PCWorld_2008-02_cd.bin / audio-video / reaper / reaper2028-install.exe / Effects / SStillwell / ozzifier < prev    next >
Text File  |  2007-12-03  |  5KB  |  136 lines

  1. // Copyright 2006, Thomas Scott Stillwell
  2. // Portions Copyright (C) 2006 Cockos Incorporated
  3. // All rights reserved.
  4. //
  5. //Redistribution and use in source and binary forms, with or without modification, are permitted 
  6. //provided that the following conditions are met:
  7. //
  8. //Redistributions of source code must retain the above copyright notice, this list of conditions 
  9. //and the following disclaimer. 
  10. //
  11. //Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
  12. //and the following disclaimer in the documentation and/or other materials provided with the distribution. 
  13. //
  14. //The name of Thomas Scott Stillwell may not be used to endorse or 
  15. //promote products derived from this software without specific prior written permission. 
  16. //
  17. //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
  18. //IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
  19. //FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
  20. //BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  21. //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  22. //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  23. //STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
  24. //THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  
  26. desc: ozzifier - pitch/delay doubler
  27.  
  28. slider1:2<0,6,1>Number of voices
  29. slider2:10<0,120,0.1>time spread (ms)
  30. slider3:20<0,120,1>pitch spread (cent)
  31. slider4:-6<-120,6,1>wet mix (dB)
  32. slider5:-6<-120,6,1>dry mix (dB)
  33. slider6:100<0,100>pan spread%
  34.  
  35. @init
  36.   bufsize = srate|0;
  37.   xfade=(srate*0.10)|0; // 100ms xfade
  38.   bufloc0 = 10000;
  39.   bufloc1 = bufloc0+bufsize+1000;
  40.   voiceptr0loc = bufloc1+bufsize+1000;
  41.   voicerateloc = voiceptr-loc+1000;
  42.   cospanloc = voicerateloc+1000;
  43.   sinpanloc = cospanloc+1000;
  44.  
  45.   buffer0 = bufloc0;
  46.   buffer1 = bufloc1;
  47.   voiceptr0 = voiceptr0loc;
  48.   voicerate = voicerateloc;
  49.   cospan = cospanloc;
  50.   sinpan = sinpanloc;
  51.  
  52.   bufdiff=bufloc1-bufloc0;
  53. @slider
  54.   numvoices = slider1;
  55.  
  56.   delaytime = (slider2*0.001*srate)|0;
  57.  
  58.   pitchspread = slider3;
  59.  
  60.   totalpitch = pitchspread * numvoices;
  61.  
  62.   bufsize = (delaytime)|0; 
  63.   xfade=(bufsize*0.05)|0;
  64.  
  65.   drymix = 2 ^ (slider5/6); 
  66.   wetmix = 2 ^ (slider4/6);
  67.  
  68.   panwidth = slider6/100;
  69.   lpan = 0.5 - (panwidth/2);
  70.   panincr = panwidth/max(1,numvoices-1);
  71.  
  72.   i = 1;
  73.  
  74.   loop(numvoices,
  75.     voicerate[i] = 2 ^ (-((totalpitch / 2) - (pitchspread * i)) / 1200);
  76.     voiceptr0[i] = bufloc0 + bufsize - (i/numvoices) * delaytime;
  77.     (voiceptr0[i] < bufloc0) ? voiceptr0[i] += bufsize;
  78.     cospan[i] = cos((lpan + (i - 1) * panincr) * $pi / 2);
  79.     sinpan[i] = sin((lpan + (i - 1) * panincr) * $pi / 2);
  80.     i += 1;
  81.   );
  82. @sample
  83.   wet0 = wet1 = 0;
  84.   i = 1;
  85.   loop(numvoices,
  86.     v0=voiceptr0[i]; iv0=0|(v0); frac0=v0-iv0;
  87.     iv02 = iv0 >= (bufloc0+bufsize-1) ? iv0-bufsize+1 : iv0+1;   
  88.   
  89.     ren0=(iv0[0]*(1-frac0)+iv02[0]*frac0);
  90.     ren1=(iv0[bufdiff]*(1-frac0)+iv02[bufdiff]*frac0);
  91.     vr=voicerate[i];
  92.  
  93.     vr >= 1.0 ?
  94.     (
  95.       tv=v0;
  96.       tv>buffer0?tv-=bufsize;
  97.       (tv >= buffer0-xfade && tv < buffer0) ? (
  98.          // xfade
  99.         frac=(buffer0-tv)/xfade;
  100.         tmp=v0+xfade;
  101.         tmp>=bufloc0+bufsize?tmp-=bufsize;
  102.         tmp2=tmp>=bufloc0+bufsize-1?bufloc0:tmp+1;
  103.         ren0 = ren0*frac + (1-frac)*( tmp[0]*(1-frac0)+tmp2[0]*frac0 );
  104.         ren1 = ren1*frac + (1-frac)*( tmp[bufdiff]*(1-frac0)+tmp2[bufdiff]*frac0 );
  105.         tv+vr > buffer0+1 ? v0+=xfade;
  106.       );
  107.     ) : ( // read pointer moving slower than write pointer
  108.       tv=v0;
  109.       tv<buffer0?tv+=bufsize;
  110.       (tv >= buffer0 && tv < buffer0+xfade) ? (
  111.          // xfade
  112.         frac=(tv-buffer0)/xfade;
  113.         tmp=v0+xfade;
  114.         tmp>=bufloc0+bufsize?tmp-=bufsize;
  115.         tmp2=tmp>=bufloc0+bufsize-1?bufloc0:tmp+1;
  116.         ren0 = ren0*frac + (1-frac)*( tmp[0]*(1-frac0)+tmp2[0]*frac0 );
  117.         ren1 = ren1*frac + (1-frac)*( tmp[bufdiff]*(1-frac0)+tmp2[bufdiff]*frac0 );
  118.         tv+vr < buffer0+1 ? v0+=xfade;
  119.       );
  120.     );
  121.     wet0 += cospan[i] * ren0;
  122.     wet1 += sinpan[i] * ren1;
  123.     
  124.     ((v0+=vr) >= (bufloc0+bufsize)) ? v0 -= bufsize;
  125.     voiceptr0[i]=v0;
  126.     i += 1;
  127.   );
  128.  
  129.   buffer0[0] = spl0; // write after reading it to avoid clicks
  130.   buffer0[bufdiff] = spl1;
  131.  
  132.   spl0 = wet0 * wetmix + spl0 * drymix;
  133.   spl1 = wet1 * wetmix + spl1 * drymix;
  134.  
  135.   ((buffer0+=1) >= (bufloc0 + bufsize)) ? buffer0 -= bufsize;
  136.