more lua-script updates:
* comments and explain amp4.lua * move amp1-3 to "Example" category
This commit is contained in:
parent
e6621c4405
commit
11d2074ee6
|
@ -1,7 +1,7 @@
|
||||||
ardour {
|
ardour {
|
||||||
["type"] = "dsp",
|
["type"] = "dsp",
|
||||||
name = "Simple Amp",
|
name = "Simple Amp",
|
||||||
category = "Amplifier",
|
category = "Example",
|
||||||
license = "MIT",
|
license = "MIT",
|
||||||
author = "Robin Gareus",
|
author = "Robin Gareus",
|
||||||
email = "robin@gareus.org",
|
email = "robin@gareus.org",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
ardour {
|
ardour {
|
||||||
["type"] = "dsp",
|
["type"] = "dsp",
|
||||||
name = "Simple Amp II",
|
name = "Simple Amp II",
|
||||||
category = "Amplifier",
|
category = "Example",
|
||||||
license = "MIT",
|
license = "MIT",
|
||||||
author = "Robin Gareus",
|
author = "Robin Gareus",
|
||||||
email = "robin@gareus.org",
|
email = "robin@gareus.org",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
ardour {
|
ardour {
|
||||||
["type"] = "dsp",
|
["type"] = "dsp",
|
||||||
name = "Simple Amp III",
|
name = "Simple Amp III",
|
||||||
category = "Amplifier",
|
category = "Example",
|
||||||
license = "MIT",
|
license = "MIT",
|
||||||
author = "Robin Gareus",
|
author = "Robin Gareus",
|
||||||
email = "robin@gareus.org",
|
email = "robin@gareus.org",
|
||||||
|
|
|
@ -12,6 +12,7 @@ ardour {
|
||||||
function dsp_ioconfig ()
|
function dsp_ioconfig ()
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
|
-- -1, -1 = any number of channels as long as input and output count matches
|
||||||
{ audio_in = -1, audio_out = -1},
|
{ audio_in = -1, audio_out = -1},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -25,7 +26,7 @@ function dsp_params ()
|
||||||
end
|
end
|
||||||
|
|
||||||
local lpf = 0.02 -- parameter low-pass filter time-constant
|
local lpf = 0.02 -- parameter low-pass filter time-constant
|
||||||
local cur_gain = 0 -- current gain (dB)
|
local cur_gain = 0 -- current smoothed gain (dB)
|
||||||
|
|
||||||
-- called once when plugin is instantiated
|
-- called once when plugin is instantiated
|
||||||
function dsp_init (rate)
|
function dsp_init (rate)
|
||||||
|
@ -40,22 +41,15 @@ function low_pass_filter_param (old, new, limit)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- use ardour's vectorized functions
|
-- the DSP callback function
|
||||||
--
|
-- "ins" and "outs" are http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
-- This is as efficient as Ardour doing it itself in C++
|
|
||||||
-- Lua function overhead is negligible
|
|
||||||
--
|
|
||||||
-- this also exemplifies the /simpler/ way of delegating the
|
|
||||||
-- channel-mapping to ardour.
|
|
||||||
|
|
||||||
function dsp_run (ins, outs, n_samples)
|
function dsp_run (ins, outs, n_samples)
|
||||||
assert (#ins == #outs) -- ensure that we can run in-place (channel count matches)
|
|
||||||
local ctrl = CtrlPorts:array() -- get control port array (read/write)
|
local ctrl = CtrlPorts:array() -- get control port array (read/write)
|
||||||
local siz = n_samples
|
local siz = n_samples -- samples remaining to process
|
||||||
local off = 0
|
local off = 0 -- already processed samples
|
||||||
local changed = false
|
local changed = false
|
||||||
|
|
||||||
-- if the gain parameter was changed, process at most 64 samples at a time
|
-- if the gain parameter was changed, process at most 32 samples at a time
|
||||||
-- and interpolate gain until the current settings match the target values
|
-- and interpolate gain until the current settings match the target values
|
||||||
if cur_gain ~= ctrl[1] then
|
if cur_gain ~= ctrl[1] then
|
||||||
changed = true
|
changed = true
|
||||||
|
@ -63,12 +57,14 @@ function dsp_run (ins, outs, n_samples)
|
||||||
end
|
end
|
||||||
|
|
||||||
while n_samples > 0 do
|
while n_samples > 0 do
|
||||||
if siz > n_samples then siz = n_samples end
|
if siz > n_samples then siz = n_samples end -- process at most "remaining samples"
|
||||||
if changed then
|
if changed then
|
||||||
cur_gain = low_pass_filter_param (cur_gain, ctrl[1], 0.05)
|
-- smooth gain changes above 0.02 dB difference
|
||||||
|
cur_gain = low_pass_filter_param (cur_gain, ctrl[1], 0.02)
|
||||||
end
|
end
|
||||||
|
|
||||||
local gain = ARDOUR.DSP.dB_to_coefficient (cur_gain) -- 10 ^ (0.05 * cur_gain)
|
local gain = ARDOUR.DSP.dB_to_coefficient (cur_gain) -- 10 ^ (0.05 * cur_gain)
|
||||||
|
|
||||||
for c = 1,#ins do -- process all channels
|
for c = 1,#ins do -- process all channels
|
||||||
-- check if output and input buffers for this channel are identical
|
-- check if output and input buffers for this channel are identical
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
|
@ -76,7 +72,7 @@ function dsp_run (ins, outs, n_samples)
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
|
||||||
ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
|
ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
|
||||||
end
|
end
|
||||||
ARDOUR.DSP.apply_gain_to_buffer (outs[c]:offset (off), siz, gain); -- process in-place
|
ARDOUR.DSP.apply_gain_to_buffer (outs[c]:offset (off), siz, gain); -- apply-gain, process in-place
|
||||||
end
|
end
|
||||||
n_samples = n_samples - siz
|
n_samples = n_samples - siz
|
||||||
off = off + siz
|
off = off + siz
|
||||||
|
@ -90,18 +86,21 @@ end
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
--- inline display + text example
|
--- inline display + text example
|
||||||
|
|
||||||
local txt = nil -- cache globally
|
local txt = nil -- cache pango context globally
|
||||||
|
|
||||||
function render_inline (ctx, w, max_h)
|
function render_inline (ctx, w, max_h)
|
||||||
local ctrl = CtrlPorts:array ()
|
local ctrl = CtrlPorts:array () -- get control ports
|
||||||
|
|
||||||
if not txt then
|
if not txt then
|
||||||
|
-- allocate PangoLayout and set font
|
||||||
|
--http://manual.ardour.org/lua-scripting/class_reference/#Cairo:PangoLayout
|
||||||
txt = Cairo.PangoLayout (ctx, "Mono 8px")
|
txt = Cairo.PangoLayout (ctx, "Mono 8px")
|
||||||
end
|
end
|
||||||
|
|
||||||
txt:set_text (string.format ("%+.2f dB", ctrl[1]));
|
txt:set_text (string.format ("%+.2f dB", ctrl[1]));
|
||||||
tw, th = txt:get_pixel_size ()
|
tw, th = txt:get_pixel_size ()
|
||||||
|
|
||||||
local h = math.ceil (th + 4) -- use text-height with 4px padding
|
local h = th + 4 -- use text-height with 4px padding
|
||||||
if (h > max_h) then h = max_h end -- but at most max-height
|
if (h > max_h) then h = max_h end -- but at most max-height
|
||||||
|
|
||||||
-- clear background
|
-- clear background
|
||||||
|
|
Loading…
Reference in New Issue
Block a user