save as ~/.config/ardour8/scripts/stereo_gain.lua
EDIT: direct download: https://paste.debian.net/download/1348589
ardour {
["type"] = "dsp",
name = "ACE Stereo Gain",
category = "Utility",
license = "MIT",
author = "Ardour Community",
description = [[DrNi asked for it]]
}
function dsp_ioconfig ()
return { { audio_in = 2, audio_out = 2} }
end
function dsp_params ()
return {
{ ["type"] = "input", name = "Gain Left", min = -20, max = 20, default = 0, unit="dB"},
{ ["type"] = "input", name = "Gain Right", min = -20, max = 20, default = 0, unit="dB"},
}
end
local current_gain_l = 1.0
local current_gain_r = 1.0
local sample_rate = 48000
function dsp_init (rate)
sample_rate = rate
end
function dsp_configure (ins, outs)
n_out = outs
end
function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
ARDOUR.DSP.process_map (bufs, n_out, in_map, out_map, n_samples, offset) -- apply pin connections
local id_l = out_map:get (ARDOUR.DataType ("audio"), 0); -- get id of mapped left output buffer
local id_r = out_map:get (ARDOUR.DataType ("audio"), 1); -- get id of mapped right output buffer
local ctrl = CtrlPorts:array() -- get parameters
local target_gain_l = ARDOUR.DSP.dB_to_coefficient (ctrl[1]) -- 10 ^ (0.05 * ctrl[1])
local target_gain_r = ARDOUR.DSP.dB_to_coefficient (ctrl[2]) -- 10 ^ (0.05 * ctrl[2])
if (id_l ~= ARDOUR.ChanMapping.Invalid) then
current_gain_l = ARDOUR.Amp.apply_gain (bufs:get_audio(id_l), sample_rate, n_samples, current_gain_l, target_gain_l, offset)
end
if (id_r ~= ARDOUR.ChanMapping.Invalid) then
current_gain_r = ARDOUR.Amp.apply_gain (bufs:get_audio(id_r), sample_rate, n_samples, current_gain_r, target_gain_r, offset)
end
end