4 category = "Amplifier",
6 author = "Ardour Team",
7 description = [[Mute button with slow fade in/out]]
10 function dsp_ioconfig ()
11 -- -1, -1 = any number of channels as long as input and output count matches
12 return { { audio_in = -1, audio_out = -1} }
16 function dsp_params ()
17 return { { ["type"] = "input", name = "Mute", min = 0, max = 1, default = 0, toggled = true } }
21 local lpf = 0.002 -- parameter low-pass filter time-constant
23 function dsp_init (rate)
24 lpf = 100 / rate -- interpolation time constant
27 function low_pass_filter_param (old, new, limit)
28 if math.abs (old - new) < limit then
31 return old + lpf * (new - old)
35 -- the DSP callback function
36 -- "ins" and "outs" are http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
37 function dsp_run (ins, outs, n_samples)
38 local ctrl = CtrlPorts:array() -- get control port array
39 local target_gain = ctrl[1] > 0 and 0.0 or 1.0; -- when muted, target_gain = 0.0; otherwise use 1.0
40 local siz = n_samples -- samples remaining to process
41 local off = 0 -- already processed samples
44 -- if the target gain changes, process at most 32 samples at a time,
45 -- and interpolate gain until the current settings match the target values
46 if cur_gain ~= target_gain then
51 while n_samples > 0 do
52 if siz > n_samples then siz = n_samples end
54 cur_gain = low_pass_filter_param (cur_gain, target_gain, 0.001)
57 for c = 1,#ins do -- process all channels
58 if ins[c] ~= outs[c] then
59 ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
61 ARDOUR.DSP.apply_gain_to_buffer (outs[c]:offset (off), siz, cur_gain);
63 n_samples = n_samples - siz