[SCM] calf/master: + Compressor: Changed knee range to 18 dB and combined graph/compression code into one inline function.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:38:36 UTC 2013


The following commit has been merged in the master branch:
commit 7af5bf95accc5161e77339d10029b722d4124733
Author: Thor Harald Johansen <thj at thj.no>
Date:   Mon Nov 24 23:45:00 2008 +0100

    + Compressor: Changed knee range to 18 dB and combined graph/compression code into one inline function.

diff --git a/src/calf/modules.h b/src/calf/modules.h
index b8bf5fc..088ac7b 100644
--- a/src/calf/modules.h
+++ b/src/calf/modules.h
@@ -698,7 +698,7 @@ public:
 
 class compressor_audio_module: public audio_module<compressor_metadata>, public line_graph_iface {
 private:
-    float linslope, clip, peak, detected;
+    float linslope, clip, peak, detected, kneeSqrt, kneeStart, kneeStop, threshold, ratio, knee, makeup;
     bool aweighting;
     aweighter awL, awR;
 public:
@@ -716,14 +716,18 @@ public:
         bool rms = *params[param_detection] == 0;
         bool average = *params[param_stereo_link] == 0;
         aweighting = *params[param_aweighting] > 0.5f;
-        float threshold = *params[param_threshold];
-        float ratio = *params[param_ratio];
+        threshold = *params[param_threshold];
+        ratio = *params[param_ratio];
         float attack = *params[param_attack];
         float attack_coeff = std::min(1.f, 1.f / (attack * srate / 4000.f));
         float release = *params[param_release];
         float release_coeff = std::min(1.f, 1.f / (release * srate / 4000.f));
-        float makeup = *params[param_makeup];
-        float knee = *params[param_knee];
+        makeup = *params[param_makeup];
+        knee = *params[param_knee];
+        
+        kneeSqrt = sqrt(knee);
+        kneeStart = threshold / kneeSqrt;
+        kneeStop = threshold * kneeSqrt;
 
         numsamples += offset;
         
@@ -747,9 +751,10 @@ public:
             return inputs_mask;
         }
 
-        float gain = 1.f;
-        
+        float compression = 1.f;
+
         while(offset < numsamples) {
+            float gain = 1.f;
             float left = ins[0][offset];
             float right = ins[1][offset];
             if(aweighting) {
@@ -762,26 +767,18 @@ public:
             float slope = rms ? sqrt(linslope) : linslope;
             detected = slope;
 
-            if(slope > 0.f && (slope > threshold || knee < 1.f)) {
-                if(IS_FAKE_INFINITY(ratio)) {
-                    gain = threshold;
-                } else {
-                    gain = (slope - threshold) / ratio + threshold;
-                }
-                
-                if(knee < 1.f) {
-                    float t = std::min(1.f, std::max(0.f, slope / threshold - knee) / (1.f - knee));
-                    gain = (gain - slope) * t + slope;
-                }
-                
+            if(slope > 0.f) {
+                gain = output_gain(slope);
                 gain /= slope;
             }
-        
-            
-            float outL = ins[0][offset] * gain * makeup;
+
+            compression = gain;
+            gain *= makeup;
+
+            float outL = ins[0][offset] * gain;
             outs[0][offset] = outL;
 
-            float outR = ins[1][offset] * gain * makeup;
+            float outR = ins[1][offset] * gain;
             outs[1][offset] = outR;
 
             ++offset;
@@ -800,7 +797,7 @@ public:
         }
         
         if(params[param_compression] != NULL) {
-            *params[param_compression] = gain;
+            *params[param_compression] = compression;
         }
 
         if(params[param_clip] != NULL) {
@@ -814,19 +811,12 @@ public:
         return inputs_mask;
     }
 
-    void set_sample_rate(uint32_t sr);
-    inline float output_level(float slope)
-    {
-        float threshold = *params[param_threshold];
-        float ratio = *params[param_ratio];
-        float makeup = *params[param_makeup];
-        float knee = *params[param_knee];
-        
-        float kneeSqrt = sqrt(knee);
-        float kneeStart = threshold / kneeSqrt;
-        float kneeStop = threshold * kneeSqrt;
-
-        if(slope > 0.f && slope > kneeStart) {
+    inline float output_level(float slope) {
+        return output_gain(slope) * makeup;
+    }
+    
+    inline float output_gain(float slope) {
+         if(slope > kneeStart) {
             float gain = 0.f;
             float delta = 0.f;
             if(IS_FAKE_INFINITY(ratio)) {
@@ -838,12 +828,17 @@ public:
             }
             
             if(knee > 1.f && slope < kneeStop) {
-                gain = hermite_interpolation(slope, kneeStart, kneeStop, kneeStart, (threshold * kneeSqrt - threshold) / ratio + threshold, 1.f, delta);
+                gain = hermite_interpolation(slope, kneeStart, kneeStop, kneeStart, (kneeStop - threshold) / ratio + threshold, 1.f, delta);
             }
-            return gain * makeup;
+            
+            return gain;
         }
-        return slope * makeup;
+
+        return slope;
     }
+
+    void set_sample_rate(uint32_t sr);
+    
     virtual bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
     virtual bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_iface *context);
     virtual bool get_gridline(int index, int subindex, float &pos, bool &vertical, std::string &legend, cairo_iface *context);
diff --git a/src/modules.cpp b/src/modules.cpp
index 3b0bf25..168f229 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -182,7 +182,7 @@ CALF_PORT_PROPS(compressor) = {
     { 15,     0.01, 2000, 0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_MSEC, NULL, "attack", "Attack" },
     { 150,    0.01, 2000, 0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_MSEC, NULL, "release", "Release" },
     { 2,      1, 16,   0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "makeup", "Makeup Gain" },
-    { 1,      1,  16,   0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "knee", "Knee" },
+    { 1,      1,  8,   0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "knee", "Knee" },
     { 0,      0,  1,   0, PF_ENUM | PF_CTL_COMBO, compressor_detection_names, "detection", "Detection" },
     { 0,      0,  1,   0, PF_ENUM | PF_CTL_COMBO, compressor_stereo_link_names, "stereo_link", "Stereo Link" },
     { 0,      0,  1,   0, PF_BOOL | PF_CTL_TOGGLE, NULL, "aweighting", "A-weighting" },

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list