[SCM] calf/master: + Compressor: Added clip LED and peak meter.

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


The following commit has been merged in the master branch:
commit 4f7c122a77ce09b7b179291403713d5f84a0fe76
Author: Thor Harald Johansen <thj at thj.no>
Date:   Sat Nov 1 13:08:10 2008 +0100

    + Compressor: Added clip LED and peak meter.

diff --git a/src/calf/modules_dev.h b/src/calf/modules_dev.h
index 996c7b6..b964d76 100644
--- a/src/calf/modules_dev.h
+++ b/src/calf/modules_dev.h
@@ -28,7 +28,7 @@ namespace synth {
 class compressor_audio_module: public null_audio_module {
 public:
     enum { in_count = 2, out_count = 2, support_midi = false, rt_capable = true };
-    enum { param_threshold, param_ratio, param_attack, param_release, param_makeup, param_knee, param_compression, param_count };
+    enum { param_threshold, param_ratio, param_attack, param_release, param_makeup, param_knee, param_rms, param_compression, param_peak, param_clip, param_count };
 
     static const char *port_names[in_count + out_count];
     static synth::ladspa_plugin_info plugin_info;
@@ -37,12 +37,15 @@ public:
     float *params[param_count];
     uint32_t srate;
     static parameter_properties param_props[];
+    float clip, peak;
     void activate() {
         target = 1.f;
         aim = 1.f;
+        peak = 0.f;
     }
     uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask) {
         numsamples += offset;
+        bool rms = *params[param_rms] > 0.5f;
         float threshold = *params[param_threshold];
         float ratio = *params[param_ratio];
         float attack = *params[param_attack];
@@ -52,37 +55,66 @@ public:
         float makeup = *params[param_makeup];
         float knee = *params[param_knee];
 
-        if(params[param_compression] != NULL) {
-            *params[param_compression] = aim;
-        }
-
         while(offset < numsamples) {
             float asample = std::max(fabs(ins[0][offset]), fabs(ins[1][offset]));
-            for(int channel = 0; channel < in_count; channel++) {
-                if(asample > 0 && (asample > threshold || knee < 1)) {
-                    if(IS_FAKE_INFINITY(ratio)) {
-                        target = threshold;
-                    } else {
-                        target = asample - threshold;
-                        target /= ratio;
-                        target += threshold;
-                    }
-                    
-                    if(knee < 1) {
-                        float t = std::min(1.f, std::max(0.f, asample / threshold - knee) / (1.f - knee));
-                        target = (target - asample) * t + asample;
-                    }
-                    
-                    target /= asample;
+            if(rms) asample *= asample;
+            
+            if(asample > 0 && (asample > threshold || knee < 1)) {
+                if(IS_FAKE_INFINITY(ratio)) {
+                    target = threshold;
                 } else {
-                    target = 1.f;
+                    target = asample - threshold;
+                    target /= ratio;
+                    target += threshold;
+                }
+                
+                if(knee < 1) {
+                    float t = std::min(1.f, std::max(0.f, asample / threshold - knee) / (1.f - knee));
+                    target = (target - asample) * t + asample;
                 }
                 
-                outs[channel][offset] = ins[channel][offset] * aim * makeup;
+                target /= asample;
+            } else {
+                target = 1.f;
             }
-            
+        
             aim += (target - aim) * (aim > target ? attack_coeff : release_coeff);
+            
+            peak -= peak * 0.0001;
+            
+            float raim;
+            if(rms) raim = sqrt(aim);
+            raim = aim;
+
+            float outL = ins[0][offset] * raim * makeup;
+            outs[0][offset] = outL;
+
+            float outR = ins[1][offset] * raim * makeup;
+            outs[1][offset] = outR;
+
             ++offset;
+            
+            float maxLR = std::max(fabs(outL), fabs(outR));
+           
+            if(maxLR > 1) clip = srate / 10;
+            if(maxLR > peak) peak = maxLR;
+            
+            if(clip > 0) {
+                --clip;
+            }
+
+        }
+        
+        if(params[param_compression] != NULL) {
+            *params[param_compression] = aim;
+        }
+
+        if(params[param_clip] != NULL) {
+            *params[param_clip] = clip;
+        }
+
+        if(params[param_peak] != NULL) {
+            *params[param_peak] = peak;
         }
 
         return inputs_mask;
diff --git a/src/modules.cpp b/src/modules.cpp
index 3a4140f..d110d39 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -182,7 +182,10 @@ parameter_properties compressor_audio_module::param_props[] = {
     { 200,    0.01, 2000, 0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_MSEC, NULL, "release", "Release" },
     { 1,      1, 12,   0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "makeup", "Makeup Gain" },
     { 1,      0,  1,   0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "knee", "Knee" },
-    { 0, 0.03125, 1,    0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_METER | PF_CTLO_LABEL | PF_CTLO_REVERSE | PF_UNIT_DB | PF_PROP_OUTPUT | PF_PROP_OPTIONAL, NULL, "compression", "Compression" }
+    { 0,      0,  1,   0, PF_BOOL | PF_CTL_TOGGLE, NULL, "rms", "RMS" },
+    { 0, 0.03125, 1,    0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_METER | PF_CTLO_LABEL | PF_CTLO_REVERSE | PF_UNIT_DB | PF_PROP_OUTPUT | PF_PROP_OPTIONAL, NULL, "compression", "Compression" },
+    { 0,      0,  1,    0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_METER | PF_CTLO_LABEL | PF_UNIT_DB | PF_PROP_OUTPUT | PF_PROP_OPTIONAL, NULL, "peak", "Peak" },
+    { 0,      1,  0,    0, PF_BOOL | PF_CTL_LED | PF_PROP_OUTPUT | PF_PROP_OPTIONAL, NULL, "clip", "Clip" }
 };
 
 synth::ladspa_plugin_info compressor_audio_module::plugin_info = { 0x8502, "Compressor", "Calf Compressor", "Thor Harald Johansen", synth::calf_copyright_info, "CompressorPlugin" };

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list