4 category = "Amplifier",
6 author = "Robin Gareus",
7 email = "robin@gareus.org",
8 site = "http://gareus.org",
9 description = [[Versatile +/- 20dB multichannel amplifier]]
12 function dsp_ioconfig ()
15 -- -1, -1 = any number of channels as long as input and output count matches
16 { audio_in = -1, audio_out = -1},
21 function dsp_params ()
24 { ["type"] = "input", name = "Gain", min = -20, max = 20, default = 0, unit="dB"},
28 local lpf = 0.02 -- parameter low-pass filter time-constant
29 local cur_gain = 0 -- current smoothed gain (dB)
31 -- called once when plugin is instantiated
32 function dsp_init (rate)
33 lpf = 780 / rate -- interpolation time constant
36 function low_pass_filter_param (old, new, limit)
37 if math.abs (old - new) < limit then
40 return old + lpf * (new - old)
44 -- the DSP callback function
45 -- "ins" and "outs" are http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
46 function dsp_run (ins, outs, n_samples)
47 local ctrl = CtrlPorts:array() -- get control port array (read/write)
48 local siz = n_samples -- samples remaining to process
49 local off = 0 -- already processed samples
52 -- if the gain parameter was changed, process at most 32 samples at a time
53 -- and interpolate gain until the current settings match the target values
54 if cur_gain ~= ctrl[1] then
59 while n_samples > 0 do
60 if siz > n_samples then siz = n_samples end -- process at most "remaining samples"
62 -- smooth gain changes above 0.02 dB difference
63 cur_gain = low_pass_filter_param (cur_gain, ctrl[1], 0.02)
66 local gain = ARDOUR.DSP.dB_to_coefficient (cur_gain) -- 10 ^ (0.05 * cur_gain)
68 for c = 1,#ins do -- process all channels
69 -- check if output and input buffers for this channel are identical
70 -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
71 if not ins[c]:sameinstance (outs[c]) then
72 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
73 ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
75 ARDOUR.DSP.apply_gain_to_buffer (outs[c]:offset (off), siz, gain); -- apply-gain, process in-place
77 n_samples = n_samples - siz
82 self:queue_draw () -- notify display
86 -------------------------------------------------------------------------------
87 --- inline display + text example
89 local txt = nil -- cache pango context globally
91 function render_inline (ctx, w, max_h)
92 local ctrl = CtrlPorts:array () -- get control ports
95 -- allocate PangoLayout and set font
96 --http://manual.ardour.org/lua-scripting/class_reference/#Cairo:PangoLayout
97 txt = Cairo.PangoLayout (ctx, "Mono 8px")
100 txt:set_text (string.format ("%+.2f dB", ctrl[1]));
101 tw, th = txt:get_pixel_size ()
103 local h = th + 4 -- use text-height with 4px padding
104 if (h > max_h) then h = max_h end -- but at most max-height
107 ctx:rectangle (0, 0, w, h)
108 ctx:set_source_rgba (.2, .2, .2, 1.0)
112 ctx:set_source_rgba (.8, .8, .8, 1.0)
113 ctx:move_to (.5 * (w - tw), .5 * (h - th))
114 txt:show_in_cairo_context (ctx)