Loading ...
Sorry, an error occurred while loading the content.

Thought this might be fun...

Expand Messages
  • RainbowSally
    /* Audio Compression ratio: Compression ratio of output to input thresh: Threshold where compression kicks in g1: Gain when signal is below the threshold g2:
    Message 1 of 1 , Mar 6, 2001
    View Source
    • 0 Attachment
      /*

       Audio Compression
       
       ratio:  Compression ratio of output to input
       thresh: Threshold where compression kicks in
       g1:  Gain when signal is below the threshold
       g2:  Gain when signal is above the threshold
       
       
       g1 is calculated by output/input at the threshold
       
        g1 = 1 - ( 1 - thresh )^(ratio)
       
       g2 is caclulated by output/input above the threshold

        g2 = 1 - ( 1 - input )^(ratio)

       For vocals, a setting of threshold = .3 (about -10 dB) and
       a compression ratio of 4 is typical.

      */

      float ratio;  // is set by program
      float thresh = 0.2; // approximately -15 dB for starters

      main(){
       clearplot();
       // white background
       paper(15);
       // testing five compression settings
       for(i = 0; i<5; i=i+1)
       {
        ratio = 1 + i;
        // use the true = 1 feature of Cmap to skip cyan (3) because
        // it's hard to see on a whiteboard
        pen(1+i+(i>1));
        plot(x, 0, 1, compress(x));
        // tell what we've plotted in color code
        putxy(.75, .5-i/20, "Compression = ");
        putxy(.9, .5-i/20, ratio);
        putxy(.915, .5-i/20, ":1");
        // and mark the knee where compression kicks in
        putxy(thresh, compress(thresh), "CIRCLE");
       }
       // make it a little prettier so we can get a high paying
       // job writing Cmap applications.  :-)
       pen(0);
       plotaxis(0, 1);
       putxy(.48, .1, "Threshold = ");
       putxy(.6, .1, thresh);
       putxy(.44, 1.05, "AUDIO COMPRESSOR CURVES");
      }

      compress(float in){
       float gain, v;
       if (in < thresh){
        v = thresh;}
       else{
        v = in;}
       gain = (1 - (1-v)^(ratio))/v;
       return (in * gain);
      }
       

      // A collection of subroutines written earlier while
      // "procrastinating".  :-)

      pen( float color)
         {   setop(C, color);   }
       

      paper( float color)
         {   setop(B, color);   }
       

      plotaxis(float a, float b){
         plot(x, a, b, 0);
      }
       
       

    Your message has been successfully submitted and would be delivered to recipients shortly.