[SCM] calf/master: More refactoring of the VUs. The goal: to be able to add peak meters without major hassle.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:40:23 UTC 2013


The following commit has been merged in the master branch:
commit 00ee132cc2ebe3b664c7d5760260d76dda37bf26
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sun Sep 19 21:41:29 2010 +0100

    More refactoring of the VUs. The goal: to be able to add peak meters without major hassle.

diff --git a/src/calf/metadata.h b/src/calf/metadata.h
index 1c2e1f9..7f6f324 100644
--- a/src/calf/metadata.h
+++ b/src/calf/metadata.h
@@ -25,6 +25,9 @@
 
 #include "giface.h"
 
+#define MONO_VU_METER_PARAMS param_meter_in, param_meter_out, param_clip_in, param_clip_out
+#define STEREO_VU_METER_PARAMS param_meter_inL, param_meter_inR, param_meter_outL, param_meter_outR, param_clip_inL, param_clip_inR, param_clip_outL, param_clip_outR
+
 namespace calf_plugins {
 
 struct flanger_metadata: public plugin_metadata<flanger_metadata>
@@ -147,7 +150,7 @@ struct monosynth_metadata: public plugin_metadata<monosynth_metadata>
 struct compressor_metadata: public plugin_metadata<compressor_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_meter_in, param_meter_out, param_clip_in, param_clip_out,
+    enum { param_bypass, param_level_in, MONO_VU_METER_PARAMS,
            param_threshold, param_ratio, param_attack, param_release, param_makeup, param_knee, param_detection, param_stereo_link, param_compression, 
            param_count };
     PLUGIN_NAME_ID_LABEL("compressor", "compressor", "Compressor")
@@ -157,7 +160,7 @@ struct compressor_metadata: public plugin_metadata<compressor_metadata>
 struct sidechaincompressor_metadata: public plugin_metadata<sidechaincompressor_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_meter_in, param_meter_out, param_clip_in, param_clip_out,
+    enum { param_bypass, param_level_in, MONO_VU_METER_PARAMS,
            param_threshold, param_ratio, param_attack, param_release, param_makeup, param_knee, param_detection, param_stereo_link, param_compression, 
            param_sc_mode, param_f1_freq, param_f2_freq, param_f1_level, param_f2_level,
            param_sc_listen, param_f1_active, param_f2_active, param_count };
@@ -168,8 +171,8 @@ struct sidechaincompressor_metadata: public plugin_metadata<sidechaincompressor_
 struct multibandcompressor_metadata: public plugin_metadata<multibandcompressor_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_meter_inL, param_meter_inR,
-           param_meter_outL, param_meter_outR, param_clip_inL, param_clip_inR, param_clip_outL, param_clip_outR,
+    enum { param_bypass, param_level_in, param_level_out, 
+           STEREO_VU_METER_PARAMS,
            param_freq0, param_freq1, param_freq2,
            param_sep0, param_sep1, param_sep2,
            param_q0, param_q1, param_q2,
@@ -202,7 +205,7 @@ struct deesser_metadata: public plugin_metadata<deesser_metadata>
 struct gate_metadata: public plugin_metadata<gate_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_meter_in, param_meter_out, param_clip_in, param_clip_out,
+    enum { param_bypass, param_level_in, MONO_VU_METER_PARAMS,
            param_range, param_threshold, param_ratio, param_attack, param_release, param_makeup, param_knee, param_detection, param_stereo_link, param_gating, 
            param_count };
     PLUGIN_NAME_ID_LABEL("gate", "gate", "Gate")
@@ -212,7 +215,7 @@ struct gate_metadata: public plugin_metadata<gate_metadata>
 struct sidechaingate_metadata: public plugin_metadata<sidechaingate_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_meter_in, param_meter_out, param_clip_in, param_clip_out,
+    enum { param_bypass, param_level_in, MONO_VU_METER_PARAMS,
            param_range, param_threshold, param_ratio, param_attack, param_release, param_makeup, param_knee, param_detection, param_stereo_link, param_gating, 
            param_sc_mode, param_f1_freq, param_f2_freq, param_f1_level, param_f2_level,
            param_sc_listen, param_f1_active, param_f2_active, param_count };
@@ -223,8 +226,7 @@ struct sidechaingate_metadata: public plugin_metadata<sidechaingate_metadata>
 struct equalizer5band_metadata: public plugin_metadata<equalizer5band_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_meter_inL, param_meter_inR,
-           param_meter_outL, param_meter_outR, param_clip_inL, param_clip_outL, param_clip_inR, param_clip_outR,
+    enum { param_bypass, param_level_in, param_level_out, STEREO_VU_METER_PARAMS,
            param_ls_active, param_ls_level, param_ls_freq,
            param_hs_active, param_hs_level, param_hs_freq,
            param_p1_active, param_p1_level, param_p1_freq, param_p1_q,
@@ -241,8 +243,8 @@ struct equalizer5band_metadata: public plugin_metadata<equalizer5band_metadata>
 struct equalizer8band_metadata: public plugin_metadata<equalizer8band_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_meter_inL, param_meter_inR,
-           param_meter_outL, param_meter_outR, param_clip_inL, param_clip_inR, param_clip_outL, param_clip_outR,
+    enum { param_bypass, param_level_in, param_level_out, 
+           STEREO_VU_METER_PARAMS,
            param_hp_active, param_hp_freq, param_hp_mode,
            param_lp_active, param_lp_freq, param_lp_mode,
            param_ls_active, param_ls_level, param_ls_freq,
@@ -259,8 +261,8 @@ struct equalizer8band_metadata: public plugin_metadata<equalizer8band_metadata>
 struct equalizer12band_metadata: public plugin_metadata<equalizer12band_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_meter_inL, param_meter_inR,
-           param_meter_outL, param_meter_outR, param_clip_inL, param_clip_inR, param_clip_outL, param_clip_outR,
+    enum { param_bypass, param_level_in, param_level_out, 
+           STEREO_VU_METER_PARAMS,
            param_hp_active, param_hp_freq, param_hp_mode,
            param_lp_active, param_lp_freq, param_lp_mode,
            param_ls_active, param_ls_level, param_ls_freq,
@@ -282,8 +284,7 @@ struct equalizer12band_metadata: public plugin_metadata<equalizer12band_metadata
 struct pulsator_metadata: public plugin_metadata<pulsator_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_meter_inL, param_meter_inR,
-           param_meter_outL, param_meter_outR, param_clip_inL, param_clip_inR, param_clip_outL, param_clip_outR,
+    enum { param_bypass, param_level_in, param_level_out, STEREO_VU_METER_PARAMS,
            param_mode, param_freq, param_amount, param_offset, param_mono, param_reset, param_count };
     PLUGIN_NAME_ID_LABEL("pulsator", "pulsator", "Pulsator")
 };
@@ -292,8 +293,7 @@ struct pulsator_metadata: public plugin_metadata<pulsator_metadata>
 struct saturator_metadata: public plugin_metadata<saturator_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 1, outs_optional = 1, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_mix, param_meter_in,
-           param_meter_out, param_clip_in, param_clip_out, param_drive, param_blend, param_meter_drive,
+    enum { param_bypass, param_level_in, param_level_out, param_mix, MONO_VU_METER_PARAMS, param_drive, param_blend, param_meter_drive,
            param_lp_pre_freq, param_hp_pre_freq, param_lp_post_freq, param_hp_post_freq,
            param_p_freq, param_p_level, param_p_q, param_count };
     PLUGIN_NAME_ID_LABEL("saturator", "saturator", "Saturator")
@@ -302,8 +302,7 @@ struct saturator_metadata: public plugin_metadata<saturator_metadata>
 struct exciter_metadata: public plugin_metadata<exciter_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 1, outs_optional = 1, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_amount, param_meter_in,
-           param_meter_out, param_clip_in, param_clip_out, param_drive, param_blend, param_meter_drive,
+    enum { param_bypass, param_level_in, param_level_out, param_amount, MONO_VU_METER_PARAMS, param_drive, param_blend, param_meter_drive,
            param_freq, param_listen, param_count };
     PLUGIN_NAME_ID_LABEL("exciter", "exciter", "Exciter")
 };
@@ -311,8 +310,7 @@ struct exciter_metadata: public plugin_metadata<exciter_metadata>
 struct bassenhancer_metadata: public plugin_metadata<bassenhancer_metadata>
 {
     enum { in_count = 2, out_count = 2, ins_optional = 1, outs_optional = 1, support_midi = false, require_midi = false, rt_capable = true };
-    enum { param_bypass, param_level_in, param_level_out, param_amount, param_meter_in,
-           param_meter_out, param_clip_in, param_clip_out, param_drive, param_blend, param_meter_drive,
+    enum { param_bypass, param_level_in, param_level_out, param_amount, MONO_VU_METER_PARAMS, param_drive, param_blend, param_meter_drive,
            param_freq, param_listen, param_count };
     PLUGIN_NAME_ID_LABEL("bassenhancer", "bassenhancer", "Bass Enhancer")
 };
diff --git a/src/calf/modules_eq.h b/src/calf/modules_eq.h
index 14cad3c..e378169 100644
--- a/src/calf/modules_eq.h
+++ b/src/calf/modules_eq.h
@@ -28,6 +28,7 @@
 #include "audio_fx.h"
 #include "giface.h"
 #include "metadata.h"
+#include "plugin_tools.h"
 
 namespace calf_plugins {
 
@@ -51,8 +52,7 @@ private:
     float hs_level_old, hs_freq_old;
     float p_level_old[PeakBands], p_freq_old[PeakBands], p_q_old[PeakBands];
     mutable float old_params_for_graph[graph_param_count];
-    uint32_t clip_inL, clip_outL, clip_inR, clip_outR;
-    float meter_inL, meter_outL, meter_inR, meter_outR;
+    dual_in_out_metering<BaseClass> meters;
     CalfEqMode hp_mode, lp_mode;
     dsp::biquad_d2<float> hp[3][2], lp[3][2];
     dsp::biquad_d2<float> lsL, lsR, hsL, hsR;
diff --git a/src/calf/plugin_tools.h b/src/calf/plugin_tools.h
index cd497b2..a9e2094 100644
--- a/src/calf/plugin_tools.h
+++ b/src/calf/plugin_tools.h
@@ -28,12 +28,12 @@
 
 namespace calf_plugins {
 
-/// Base class for universal stereo level metering
-struct stereo_in_out_metering_base
+template<class Meter>
+struct in_out_metering_base
 {
-    dsp::vumeter vumeter_in, vumeter_out;
-    
-    stereo_in_out_metering_base()
+    typedef Meter meter;
+    meter vumeter_in, vumeter_out;
+    in_out_metering_base()
     {
         reset();
     }
@@ -44,9 +44,9 @@ struct stereo_in_out_metering_base
     }
 };
     
-/// Universal stereo level metering for a specific plugin
+/// Universal single stereo level metering for a specific plugin
 template<class Metadata>
-class stereo_in_out_metering: public stereo_in_out_metering_base
+class stereo_in_out_metering: public in_out_metering_base<dsp::vumeter>
 {
 public:
     inline void process(float *const *params, const float *const *inputs, const float *const *outputs, unsigned int offset, unsigned int nsamples)
@@ -79,6 +79,49 @@ public:
     }
 };
 
+/// Universal dual level metering for a specific plugin
+template<class Metadata>
+class dual_in_out_metering: public in_out_metering_base<dsp::dual_vumeter>
+{
+public:
+    inline void process(float *const *params, const float *const *inputs, const float *const *outputs, unsigned int offset, unsigned int nsamples)
+    {
+        if (params[Metadata::param_meter_inL] || params[Metadata::param_clip_inL] || params[Metadata::param_meter_inR] || params[Metadata::param_clip_inR]) {
+            if (inputs)
+                vumeter_in.update_stereo(inputs[0] ? inputs[0] + offset : NULL, inputs[1] ? inputs[1] + offset : NULL, nsamples);
+            else
+                vumeter_in.update_zeros(nsamples);
+            if (params[Metadata::param_meter_inL])
+                *params[Metadata::param_meter_inL] = vumeter_in.left.level;
+            if (params[Metadata::param_meter_inR])
+                *params[Metadata::param_meter_inR] = vumeter_in.right.level;
+            if (params[Metadata::param_clip_inL])
+                *params[Metadata::param_clip_inL] = vumeter_in.left.clip > 0 ? 1.f : 0.f;
+            if (params[Metadata::param_clip_inR])
+                *params[Metadata::param_clip_inR] = vumeter_in.right.clip > 0 ? 1.f : 0.f;
+        }
+        if (params[Metadata::param_meter_outL] || params[Metadata::param_clip_outL] || params[Metadata::param_meter_outR] || params[Metadata::param_clip_outR]) {
+            if (outputs)
+                vumeter_out.update_stereo(outputs[0] ? outputs[0] + offset : NULL, outputs[1] ? outputs[1] + offset : NULL, nsamples);
+            else
+                vumeter_out.update_zeros(nsamples);
+            if (params[Metadata::param_meter_outL])
+                *params[Metadata::param_meter_outL] = vumeter_out.left.level;
+            if (params[Metadata::param_meter_outR])
+                *params[Metadata::param_meter_outR] = vumeter_out.right.level;
+            if (params[Metadata::param_clip_outL])
+                *params[Metadata::param_clip_outL] = vumeter_out.left.clip > 0 ? 1.f : 0.f;
+            if (params[Metadata::param_clip_outR])
+                *params[Metadata::param_clip_outR] = vumeter_out.right.clip > 0 ? 1.f : 0.f;
+        }
+    }
+    void bypassed(float *const *params, unsigned int nsamples)
+    {
+        reset();
+        process(params, NULL, NULL, 0, nsamples);
+    }
+};
+
 };
 
 #endif
diff --git a/src/calf/vumeter.h b/src/calf/vumeter.h
index 6ef1e76..cd11252 100644
--- a/src/calf/vumeter.h
+++ b/src/calf/vumeter.h
@@ -90,6 +90,27 @@ struct vumeter
     }
 };
 
+struct dual_vumeter
+{
+    vumeter left, right;
+    
+    inline void update_stereo(const float *src1, const float *src2, unsigned int len)
+    {
+        left.update_stereo(src1, NULL, len);
+        right.update_stereo(NULL, src2, len);
+    }
+    inline void update_zeros(unsigned int len)
+    {
+        left.update_zeros(len);
+        right.update_zeros(len);
+    }
+    inline void reset()
+    {
+        left.reset();
+        right.reset();
+    }
+};
+
 };
 
 #endif
diff --git a/src/modules_dist.cpp b/src/modules_dist.cpp
index 4d6a891..725e05b 100644
--- a/src/modules_dist.cpp
+++ b/src/modules_dist.cpp
@@ -26,8 +26,6 @@
 using namespace dsp;
 using namespace calf_plugins;
 
-#define SET_IF_CONNECTED(name) if (params[AM::param_##name] != NULL) *params[AM::param_##name] = name;
-
 /// Saturator Band by Markus Schmidt
 ///
 /// This module is based on Krzysztof's filters and Tom Szilagyi's distortion routine.
diff --git a/src/modules_eq.cpp b/src/modules_eq.cpp
index d4ea0bc..04cd0ae 100644
--- a/src/modules_eq.cpp
+++ b/src/modules_eq.cpp
@@ -26,8 +26,6 @@
 using namespace dsp;
 using namespace calf_plugins;
 
-#define SET_IF_CONNECTED(name) if (params[AM::param_##name] != NULL) *params[AM::param_##name] = name;
-
 /// Equalizer 12 Band by Markus Schmidt
 ///
 /// This module is based on Krzysztof's filters. It provides a couple
@@ -40,8 +38,6 @@ equalizerNband_audio_module<BaseClass, has_lphp>::equalizerNband_audio_module()
     is_active = false;
     srate = 0;
     last_generation = 0;
-    clip_inL = clip_inR = clip_outL = clip_outR  = 0.f;
-    meter_inL = meter_inR = meter_outL = meter_outR = 0.f;
 }
 
 template<class BaseClass, bool has_lphp>
@@ -50,6 +46,7 @@ void equalizerNband_audio_module<BaseClass, has_lphp>::activate()
     is_active = true;
     // set all filters
     params_changed();
+    meters.reset();
 }
 
 template<class BaseClass, bool has_lphp>
@@ -170,6 +167,8 @@ template<class BaseClass, bool has_lphp>
 uint32_t equalizerNband_audio_module<BaseClass, has_lphp>::process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask)
 {
     bool bypass = *params[AM::param_bypass] > 0.f;
+    uint32_t orig_offset = offset;
+    uint32_t orig_numsamples = numsamples;
     numsamples += offset;
     if(bypass) {
         // everything bypassed
@@ -179,19 +178,8 @@ uint32_t equalizerNband_audio_module<BaseClass, has_lphp>::process(uint32_t offs
             ++offset;
         }
         // displays, too
-        clip_inL = clip_inR = clip_outL = clip_outR = 0.f;
-        meter_inL = meter_inR = meter_outL = meter_outR = 0.f;
+        meters.bypassed(params, orig_numsamples);
     } else {
-        
-        clip_inL    -= std::min(clip_inL,  numsamples);
-        clip_inR    -= std::min(clip_inR,  numsamples);
-        clip_outL   -= std::min(clip_outL, numsamples);
-        clip_outR   -= std::min(clip_outR, numsamples);
-        meter_inL = 0.f;
-        meter_inR = 0.f;
-        meter_outL = 0.f;
-        meter_outR = 0.f;
-        
         // process
         while(offset < numsamples) {
             // cycle through samples
@@ -230,37 +218,11 @@ uint32_t equalizerNband_audio_module<BaseClass, has_lphp>::process(uint32_t offs
             // send to output
             outs[0][offset] = outL;
             outs[1][offset] = outR;
-            
-            // clip LED's
-            if(inL > 1.f) {
-                clip_inL  = srate >> 3;
-            }
-            if(inR > 1.f) {
-                clip_inR  = srate >> 3;
-            }
-            if(outL > 1.f) {
-                clip_outL = srate >> 3;
-            }
-            if(outR > 1.f) {
-                clip_outR = srate >> 3;
-            }
-            // set up in / out meters
-            if(inL > meter_inL) {
-                meter_inL = inL;
-            }
-            if(inR > meter_inR) {
-                meter_inR = inR;
-            }
-            if(outL > meter_outL) {
-                meter_outL = outL;
-            }
-            if(outR > meter_outR) {
-                meter_outR = outR;
-            }
-            
+                        
             // next sample
             ++offset;
         } // cycle trough samples
+        meters.process(params, ins, outs, orig_offset, orig_numsamples);
         // clean up
         for(int i = 0; i < 3; ++i) {
             hp[i][0].sanitize();
@@ -275,15 +237,6 @@ uint32_t equalizerNband_audio_module<BaseClass, has_lphp>::process(uint32_t offs
             pR[i].sanitize();
         }
     }
-    // draw meters
-    SET_IF_CONNECTED(clip_inL)
-    SET_IF_CONNECTED(clip_inR)
-    SET_IF_CONNECTED(clip_outL)
-    SET_IF_CONNECTED(clip_outR)
-    SET_IF_CONNECTED(meter_inL)
-    SET_IF_CONNECTED(meter_inR)
-    SET_IF_CONNECTED(meter_outL)
-    SET_IF_CONNECTED(meter_outR)
     // whatever has to be returned x)
     return outputs_mask;
 }

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list