4 category = "Amplifier",
6 author = "Ardour Team",
7 description = [[Versatile +/- 20dB multichannel amplifier]]
10 function dsp_ioconfig ()
13 -- -1, -1 = any number of channels as long as input and output count matches
14 { audio_in = -1, audio_out = -1},
19 function dsp_params ()
22 { ["type"] = "input", name = "Gain", min = -20, max = 20, default = 0, unit="dB"},
26 local lpf = 0.02 -- parameter low-pass filter time-constant
27 local cur_gain = 0 -- current smoothed gain (dB)
29 -- called once when plugin is instantiated
30 function dsp_init (rate)
31 lpf = 780 / rate -- interpolation time constant
34 function low_pass_filter_param (old, new, limit)
35 if math.abs (old - new) < limit then
38 return old + lpf * (new - old)
42 -- the DSP callback function
43 -- "ins" and "outs" are http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
44 function dsp_run (ins, outs, n_samples)
45 local ctrl = CtrlPorts:array() -- get control port array (read/write)
46 local siz = n_samples -- samples remaining to process
47 local off = 0 -- already processed samples
50 -- if the gain parameter was changed, process at most 32 samples at a time
51 -- and interpolate gain until the current settings match the target values
52 if cur_gain ~= ctrl[1] then
57 while n_samples > 0 do
58 if siz > n_samples then siz = n_samples end -- process at most "remaining samples"
60 -- smooth gain changes above 0.02 dB difference
61 cur_gain = low_pass_filter_param (cur_gain, ctrl[1], 0.02)
64 local gain = ARDOUR.DSP.dB_to_coefficient (cur_gain) -- 10 ^ (0.05 * cur_gain)
66 for c = 1,#ins do -- process all channels
67 -- check if output and input buffers for this channel are identical
68 -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
69 if ins[c] ~= outs[c] then
70 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
71 ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
73 ARDOUR.DSP.apply_gain_to_buffer (outs[c]:offset (off), siz, gain); -- apply-gain, process in-place
75 n_samples = n_samples - siz
81 self:queue_draw () -- notify display
86 -------------------------------------------------------------------------------
87 --- inline display + text example
90 local txt = nil -- cache pango context globally
92 function render_inline (ctx, w, max_h)
93 local ctrl = CtrlPorts:array () -- get control ports
96 -- allocate PangoLayout and set font
97 --http://manual.ardour.org/lua-scripting/class_reference/#Cairo:PangoLayout
98 txt = Cairo.PangoLayout (ctx, "Mono 8px")
101 txt:set_text (string.format ("%+.2f dB", ctrl[1]));
102 tw, th = txt:get_pixel_size ()
104 local h = th + 4 -- use text-height with 4px padding
105 if (h > max_h) then h = max_h end -- but at most max-height
108 ctx:rectangle (0, 0, w, h)
109 ctx:set_source_rgba (.2, .2, .2, 1.0)
113 ctx:set_source_rgba (.8, .8, .8, 1.0)
114 ctx:move_to (.5 * (w - tw), .5 * (h - th))
115 txt:show_in_cairo_context (ctx)