[SCM] calf/master: Add second envelope to Monosynth (second LFO is still a mockup only).

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


The following commit has been merged in the master branch:
commit 1dbd4ea8de83b20efb214931133362193f82c627
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat May 8 15:40:59 2010 +0100

    Add second envelope to Monosynth (second LFO is still a mockup only).

diff --git a/gui/gui-monosynth.xml b/gui/gui-monosynth.xml
index fa4f8c8..ebccb01 100644
--- a/gui/gui-monosynth.xml
+++ b/gui/gui-monosynth.xml
@@ -214,27 +214,27 @@
             <hbox spacing="4">
               <table cols="5" rows="1" homogeneous="1" fill-x="0" expand-x="0">
                 <vbox attach-x="0" attach-y="0">
-                  <label param="adsr_a"/>
+                  <label param="adsr_a" text="Attack"/>
                   <vscale param="adsr_a" inverted="1" size="1"/>
                   <value param="adsr_a" width="4"/>
                 </vbox>
                 <vbox attach-x="1" attach-y="0">
-                  <label param="adsr_d"/>
+                  <label param="adsr_d" text="Decay"/>
                   <vscale param="adsr_d" inverted="1" size="1"/>
                   <value param="adsr_d" width="4"/>
                 </vbox>
                 <vbox attach-x="2" attach-y="0">
-                  <label param="adsr_s"/>
+                  <label param="adsr_s" text="Sustain"/>
                   <vscale param="adsr_s" inverted="1" size="1"/>
                   <value param="adsr_s"/>
                 </vbox>
                 <vbox attach-x="3" attach-y="0">
-                  <label param="adsr_f"/>
+                  <label param="adsr_f" text="Fade"/>
                   <vscale param="adsr_f" inverted="1" size="1"/>
                   <value param="adsr_f" width="4"/>
                 </vbox>
                 <vbox attach-x="4" attach-y="0">
-                  <label param="adsr_r"/>
+                  <label param="adsr_r" text="Release"/>
                   <vscale param="adsr_r" inverted="1" size="1"/>
                   <value param="adsr_r" width="4"/>
                 </vbox>
@@ -262,46 +262,46 @@
             <hbox spacing="4">
               <table cols="5" rows="1" homogeneous="1" fill-x="0" expand-x="0">
                 <vbox attach-x="0" attach-y="0">
-                  <label param="adsr_a"/>
-                  <vscale param="adsr_a" inverted="1" size="1"/>
-                  <value param="adsr_a" width="4"/>
+                  <label param="adsr2_a" text="Attack"/>
+                  <vscale param="adsr2_a" inverted="1" size="1"/>
+                  <value param="adsr2_a" width="4"/>
                 </vbox>
                 <vbox attach-x="1" attach-y="0">
-                  <label param="adsr_d"/>
-                  <vscale param="adsr_d" inverted="1" size="1"/>
-                  <value param="adsr_d" width="4"/>
+                  <label param="adsr2_d" text="Decay"/>
+                  <vscale param="adsr2_d" inverted="1" size="1"/>
+                  <value param="adsr2_d" width="4"/>
                 </vbox>
                 <vbox attach-x="2" attach-y="0">
-                  <label param="adsr_s"/>
-                  <vscale param="adsr_s" inverted="1" size="1"/>
-                  <value param="adsr_s"/>
+                  <label param="adsr2_s" text="Sustain"/>
+                  <vscale param="adsr2_s" inverted="1" size="1"/>
+                  <value param="adsr2_s"/>
                 </vbox>
                 <vbox attach-x="3" attach-y="0">
-                  <label param="adsr_f"/>
-                  <vscale param="adsr_f" inverted="1" size="1"/>
-                  <value param="adsr_f" width="4"/>
+                  <label param="adsr2_f" text="Fade"/>
+                  <vscale param="adsr2_f" inverted="1" size="1"/>
+                  <value param="adsr2_f" width="4"/>
                 </vbox>
                 <vbox attach-x="4" attach-y="0">
-                  <label param="adsr_r"/>
-                  <vscale param="adsr_r" inverted="1" size="1"/>
-                  <value param="adsr_r" width="4"/>
+                  <label param="adsr2_r" text="Release"/>
+                  <vscale param="adsr2_r" inverted="1" size="1"/>
+                  <value param="adsr2_r" width="4"/>
                 </vbox>
               </table>
               <vbox>
                 <vbox>
                   <label text="To Cutoff"/>
-                  <knob type="1" param="env2cutoff"/>
-                  <value param="env2cutoff"/>
+                  <knob type="1" param="adsr2_cutoff"/>
+                  <value param="adsr2_cutoff"/>
                 </vbox>
                 <vbox>
                   <label text="To Res"/>
-                  <knob param="env2res"/>
-                  <value param="env2res"/>
+                  <knob param="adsr2_res"/>
+                  <value param="adsr2_res"/>
                 </vbox>
                 <vbox>
                   <label text="To Amp"/>
-                  <knob param="env2amp"/>
-                  <value param="env2amp"/>
+                  <knob param="adsr2_amp"/>
+                  <value param="adsr2_amp"/>
                 </vbox>
               </vbox>
             </hbox>
diff --git a/src/calf/metadata.h b/src/calf/metadata.h
index ecdf772..4637afa 100644
--- a/src/calf/metadata.h
+++ b/src/calf/metadata.h
@@ -103,9 +103,12 @@ struct monosynth_metadata: public plugin_metadata<monosynth_metadata>
 {
     enum { wave_saw, wave_sqr, wave_pulse, wave_sine, wave_triangle, wave_varistep, wave_skewsaw, wave_skewsqr, wave_test1, wave_test2, wave_test3, wave_test4, wave_test5, wave_test6, wave_test7, wave_test8, wave_count };
     enum { flt_lp12, flt_lp24, flt_2lp12, flt_hp12, flt_lpbr, flt_hpbr, flt_bp6, flt_2bp6 };
-    enum { par_wave1, par_wave2, par_pw1, par_pw2, par_detune, par_osc2xpose, par_oscmode, par_oscmix, par_filtertype, par_cutoff, par_resonance, par_cutoffsep, par_envmod, par_envtores, par_envtoamp, par_attack, par_decay, par_sustain, par_fade, par_release, 
+    enum { par_wave1, par_wave2, par_pw1, par_pw2, par_detune, par_osc2xpose, par_oscmode, par_oscmix, par_filtertype, par_cutoff, par_resonance, par_cutoffsep, par_env1tocutoff, par_env1tores, par_env1toamp, 
+        par_env1attack, par_env1decay, par_env1sustain, par_env1fade, par_env1release, 
         par_keyfollow, par_legato, par_portamento, par_vel2filter, par_vel2amp, par_master, par_pwhlrange, 
         par_lforate, par_lfodelay, par_lfofilter, par_lfopitch, par_lfopw, par_mwhl_lfo, par_scaledetune,
+        par_env2tocutoff, par_env2tores, par_env2toamp, 
+        par_env2attack, par_env2decay, par_env2sustain, par_env2fade, par_env2release, 
         param_count };
     enum { in_count = 0, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = true, require_midi = true, rt_capable = true };
     enum { step_size = 64, step_shift = 6 };
@@ -115,7 +118,9 @@ struct monosynth_metadata: public plugin_metadata<monosynth_metadata>
         modsrc_pressure,
         modsrc_modwheel,
         modsrc_env1,
+        modsrc_env2,
         modsrc_lfo1,
+        modsrc_lfo2,
         modsrc_count,
     };
     enum {
diff --git a/src/calf/modules_synths.h b/src/calf/modules_synths.h
index 68beb73..63e72ed 100644
--- a/src/calf/modules_synths.h
+++ b/src/calf/modules_synths.h
@@ -62,7 +62,7 @@ public:
     /// Last used waveform number - OSC2
     int prev_wave2;
     int filter_type, last_filter_type;
-    float freq, start_freq, target_freq, cutoff, decay_factor, fgain, fgain_delta, separation;
+    float freq, start_freq, target_freq, cutoff, fgain, fgain_delta, separation;
     float detune, xpose, xfade, ampctl, fltctl, queue_vel;
     float odcr, porta_time, lfo_bend, lfo_clock, last_lfov, modwheel_value;
     /// Last value of phase shift for pulse width emulation for OSC1
@@ -71,7 +71,7 @@ public:
     int32_t last_pwshift2;
     int queue_note_on, stop_count, modwheel_value_int;
     int legato;
-    dsp::adsr envelope;
+    dsp::adsr envelope1, envelope2;
     dsp::keystack stack;
     dsp::gain_smoothing master;
     /// Smoothed cutoff value
diff --git a/src/metadata.cpp b/src/metadata.cpp
index ee1a30a..f7d5a41 100644
--- a/src/metadata.cpp
+++ b/src/metadata.cpp
@@ -629,17 +629,17 @@ CALF_PORT_PROPS(monosynth) = {
     { 0.5,        0,    1,    0, PF_FLOAT | PF_SCALE_PERC, NULL, "o12_mix", "O1<>2 Mix" },
     { 1,          0,    7,    0, PF_ENUM | PF_CTL_COMBO | PF_PROP_GRAPH, monosynth_filter_choices, "filter", "Filter" },
     { 33,        10,16000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_HZ, NULL, "cutoff", "Cutoff" },
-    { 2,        0.7,    8,    0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB, NULL, "res", "Resonance" },
+    { 3,        0.7,    8,    0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB, NULL, "res", "Resonance" },
     { 0,      -2400, 2400,    0, PF_FLOAT | PF_SCALE_LINEAR | PF_CTL_KNOB | PF_UNIT_CENTS, NULL, "filter_sep", "Separation" },
     { 8000,  -10800,10800,    0, PF_FLOAT | PF_SCALE_LINEAR | PF_CTL_KNOB | PF_UNIT_CENTS, NULL, "env2cutoff", "Env->Cutoff" },
     { 1,          0,    1,    0, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "env2res", "Env->Res" },
-    { 1,          0,    1,    0, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "env2amp", "Env->Amp" },
+    { 0,          0,    1,    0, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "env2amp", "Env->Amp" },
     
-    { 1,          1,20000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_a", "Attack" },
-    { 350,       10,20000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_d", "Decay" },
-    { 0.5,        0,    1,    0, PF_FLOAT | PF_SCALE_PERC, NULL, "adsr_s", "Sustain" },
-    { 0,     -10000,10000,   21, PF_FLOAT | PF_SCALE_LINEAR | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_f", "Fade" },
-    { 50,       10,20000,     0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_r", "Release" },
+    { 1,          1,20000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_a", "EG1 Attack" },
+    { 350,       10,20000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_d", "EG1 Decay" },
+    { 0.5,        0,    1,    0, PF_FLOAT | PF_SCALE_PERC, NULL, "adsr_s", "EG1 Sustain" },
+    { 0,     -10000,10000,   21, PF_FLOAT | PF_SCALE_LINEAR | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_f", "EG1 Fade" },
+    { 100,       10,20000,     0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr_r", "EG1 Release" },
     
     { 0,          0,    2,    0, PF_FLOAT | PF_SCALE_PERC, NULL, "key_follow", "Key Follow" },
     { 0,          0,    3,    0, PF_ENUM | PF_CTL_COMBO, monosynth_legato_names, "legato", "Legato Mode" },
@@ -660,6 +660,16 @@ CALF_PORT_PROPS(monosynth) = {
     { 1,          0,    1,  0.1, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "mwhl2lfo", "ModWheel->LFO" },
 
     { 1,          0,    1,    0, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "scale_detune", "Scale Detune" },
+
+    { 0,  -10800,10800,    0, PF_FLOAT | PF_SCALE_LINEAR | PF_CTL_KNOB | PF_UNIT_CENTS, NULL, "adsr2_cutoff", "EG2->Cutoff" },
+    { 0.3,        0,    1,    0, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "adsr2_res", "EG2->Res" },
+    { 1,          0,    1,    0, PF_FLOAT | PF_SCALE_PERC | PF_CTL_KNOB, NULL, "adsr2_amp", "EG2->Amp" },
+    
+    { 1,          1,20000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr2_a", "EG2 Attack" },
+    { 100,       10,20000,    0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr2_d", "EG2 Decay" },
+    { 0.5,        0,    1,    0, PF_FLOAT | PF_SCALE_PERC, NULL, "adsr2_s", "EG2 Sustain" },
+    { 0,     -10000,10000,   21, PF_FLOAT | PF_SCALE_LINEAR | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr2_f", "EG2 Fade" },
+    { 50,       10,20000,     0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_FADER | PF_UNIT_MSEC, NULL, "adsr2_r", "Release" },
 };
 
 ////////////////////////////////////////////////////////////////////////////
diff --git a/src/monosynth.cpp b/src/monosynth.cpp
index ac9e6eb..5d92235 100644
--- a/src/monosynth.cpp
+++ b/src/monosynth.cpp
@@ -378,17 +378,20 @@ void monosynth_audio_module::delayed_note_on()
         default:
             break;
         }
-        envelope.note_on();
+        envelope1.note_on();
+        envelope2.note_on();
         running = true;
     }
     if (legato >= 2 && !gate)
         porta_time = -1.f;
     gate = true;
     stopping = false;
-    if (!(legato & 1) || envelope.released()) {
-        envelope.note_on();
+    if (!(legato & 1) || (envelope1.released() && envelope2.released())) {
+        envelope1.note_on();
+        envelope2.note_on();
     }
-    envelope.advance();
+    envelope1.advance();
+    envelope2.advance();
     queue_note_on = -1;
     float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get_last(), modwheel_value, 0, 0.5+0.5*last_lfov};
     calculate_modmatrix(moddest, moddest_count, modsrc);
@@ -415,7 +418,8 @@ void monosynth_audio_module::calculate_step()
         dsp::zero(buffer, step_size);
         if (is_stereo_filter())
             dsp::zero(buffer2, step_size);
-        envelope.advance();
+        envelope1.advance();
+        envelope2.advance();
         return;
     }
     lfo.set_freq(*params[par_lforate], crate);
@@ -440,23 +444,28 @@ void monosynth_audio_module::calculate_step()
         lfo_bend = pow(2.0f, *params[par_lfopitch] * lfov * (1.f / 1200.0f));
     inertia_pitchbend.step();
     set_frequency();
-    envelope.advance();
-    float env = envelope.value;
+    envelope1.advance();
+    envelope2.advance();
+    float env1 = envelope1.value;
+    float env2 = envelope2.value;
     
     // mod matrix
     // this should be optimized heavily; I think I'll do it when MIDI in Ardour 3 gets stable :>
-    float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get(), modwheel_value, env, 0.5+0.5*lfov};
+    float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get(), modwheel_value, env1, env2, 0.5+0.5*lfov, 0.5+0.5*lfov};
     calculate_modmatrix(moddest, moddest_count, modsrc);
     
     inertia_cutoff.set_inertia(*params[par_cutoff]);
-    cutoff = inertia_cutoff.get() * pow(2.0f, (lfov * *params[par_lfofilter] + env * fltctl * *params[par_envmod] + moddest[moddest_cutoff]) * (1.f / 1200.f));
+    cutoff = inertia_cutoff.get() * pow(2.0f, (lfov * *params[par_lfofilter] + env1 * fltctl * *params[par_env1tocutoff] + env2 * fltctl * *params[par_env2tocutoff] + moddest[moddest_cutoff]) * (1.f / 1200.f));
     if (*params[par_keyfollow] > 0.01f)
         cutoff *= pow(freq / 264.f, *params[par_keyfollow]);
     cutoff = dsp::clip(cutoff , 10.f, 18000.f);
     float resonance = *params[par_resonance];
-    float e2r = *params[par_envtores];
-    float e2a = *params[par_envtoamp];
-    resonance = resonance * (1 - e2r) + (0.7 + (resonance - 0.7) * env * env) * e2r + moddest[moddest_resonance];
+    float e2r1 = *params[par_env1tores];
+    float e2a1 = *params[par_env1toamp];
+    resonance = resonance * (1 - e2r1) + (0.7 + (resonance - 0.7) * env1 * env1) * e2r1;
+    float e2r2 = *params[par_env2tores];
+    float e2a2 = *params[par_env2toamp];
+    resonance = resonance * (1 - e2r2) + (0.7 + (resonance - 0.7) * env2 * env2) * e2r2 + moddest[moddest_resonance];
     float cutoff2 = dsp::clip(cutoff * separation, 10.f, 18000.f);
     float newfgain = 0.f;
     if (filter_type != last_filter_type)
@@ -508,9 +517,10 @@ void monosynth_audio_module::calculate_step()
         newfgain = ampctl;        
         break;
     }
-    float aenv = env;
-    if (*params[par_envtoamp] > 0.f)
-        newfgain *= 1.0 - (1.0 - aenv) * e2a;
+    if (e2a1 > 0.f)
+        newfgain *= 1.0 - (1.0 - env1) * e2a1;
+    if (e2a2 > 0.f)
+        newfgain *= 1.0 - (1.0 - env2) * e2a2;
     if (moddest[moddest_attenuation] != 0.f)
         newfgain *= dsp::clip<float>(1 - moddest[moddest_attenuation] * moddest[moddest_attenuation], 0.f, 1.f);
     fgain_delta = (newfgain - fgain) * (1.0 / step_size);
@@ -532,7 +542,7 @@ void monosynth_audio_module::calculate_step()
         calculate_buffer_stereo();
         break;
     }
-    if ((envelope.state == adsr::STOP && !gate) || force_fadeout || (envelope.state == adsr::RELEASE && *params[par_envtoamp] <= 0.f))
+    if ((envelope1.state == adsr::STOP && envelope2.state == adsr::STOP && !gate) || force_fadeout || (envelope1.state == adsr::RELEASE && *params[par_env1toamp] <= 0.f) || (envelope2.state == adsr::RELEASE && *params[par_env2toamp] <= 0.f))
     {
         enum { ramp = step_size * 4 };
         for (int i = 0; i < step_size; i++)
@@ -567,14 +577,16 @@ void monosynth_audio_module::note_off(int note, int vel)
             porta_time = 0;
             set_frequency();
             if (!(legato & 1)) {
-                envelope.note_on();
+                envelope1.note_on();
+                envelope2.note_on();
                 stopping = false;
                 running = true;
             }
             return;
         }
         gate = false;
-        envelope.note_off();
+        envelope1.note_off();
+        envelope2.note_off();
     }
 }
 
@@ -601,7 +613,8 @@ void monosynth_audio_module::control_change(int controller, int value)
         case 123: // all notes off
             gate = false;
             queue_note_on = -1;
-            envelope.note_off();
+            envelope1.note_off();
+            envelope2.note_off();
             stack.clear();
             break;
     }
@@ -612,7 +625,8 @@ void monosynth_audio_module::deactivate()
     gate = false;
     running = false;
     stopping = false;
-    envelope.reset();
+    envelope1.reset();
+    envelope2.reset();
     stack.clear();
 }
 
@@ -634,9 +648,9 @@ void monosynth_audio_module::set_frequency()
 void monosynth_audio_module::params_changed()
 {
     float sf = 0.001f;
-    envelope.set(*params[par_attack] * sf, *params[par_decay] * sf, std::min(0.999f, *params[par_sustain]), *params[par_release] * sf, srate / step_size, *params[par_fade] * sf);
+    envelope1.set(*params[par_env1attack] * sf, *params[par_env1decay] * sf, std::min(0.999f, *params[par_env1sustain]), *params[par_env1release] * sf, srate / step_size, *params[par_env1fade] * sf);
+    envelope2.set(*params[par_env2attack] * sf, *params[par_env2decay] * sf, std::min(0.999f, *params[par_env2sustain]), *params[par_env2release] * sf, srate / step_size, *params[par_env2fade] * sf);
     filter_type = dsp::fastf2i_drm(*params[par_filtertype]);
-    decay_factor = odcr * 1000.0 / *params[par_decay];
     separation = pow(2.0, *params[par_cutoffsep] / 1200.0);
     wave1 = dsp::clip(dsp::fastf2i_drm(*params[par_wave1]), 0, (int)wave_count - 1);
     wave2 = dsp::clip(dsp::fastf2i_drm(*params[par_wave2]), 0, (int)wave_count - 1);
@@ -655,7 +669,10 @@ uint32_t monosynth_audio_module::process(uint32_t offset, uint32_t nsamples, uin
 {
     if (!running && queue_note_on == -1) {
         for (uint32_t i = 0; i < nsamples / step_size; i++)
-            envelope.advance();
+        {
+            envelope1.advance();
+            envelope2.advance();
+        }
         return 0;
     }
     uint32_t op = offset;
@@ -665,7 +682,8 @@ uint32_t monosynth_audio_module::process(uint32_t offset, uint32_t nsamples, uin
             if (running || queue_note_on != -1)
                 calculate_step();
             else {
-                envelope.advance();
+                envelope1.advance();
+                envelope2.advance();
                 dsp::zero(buffer, step_size);
             }
         }

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list