2016-02-23 09:44:41 -05:00
|
|
|
ardour {
|
|
|
|
["type"] = "dsp",
|
|
|
|
name = "Voice/Level Activate",
|
|
|
|
license = "MIT",
|
|
|
|
author = "Robin Gareus",
|
|
|
|
authoremail = "robin@gareus.org",
|
|
|
|
site = "http://gareus.org",
|
|
|
|
description = [[
|
|
|
|
An Example Audio Plugin that rolls the transport
|
2016-02-27 08:56:36 -05:00
|
|
|
when the signal level on the plugin's input exceeds a given threshold.]]
|
2016-02-23 09:44:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function dsp_ioconfig ()
|
|
|
|
return
|
|
|
|
{
|
2016-02-27 08:56:36 -05:00
|
|
|
-- support all in/out as long as input port count equals output port count
|
2016-02-23 09:44:41 -05:00
|
|
|
{ audio_in = -1, audio_out = -1},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function dsp_params ()
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{ ["type"] = "input", name = "Threshold", min = -20, max = 0, default = -6, doc = "Threshold in dBFS for all channels" },
|
|
|
|
{ ["type"] = "output", name = "Level", min = -120, max = 0 },
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function dsp_configure (ins, outs)
|
2016-02-27 08:56:36 -05:00
|
|
|
n_channels = ins:n_audio()
|
2016-02-23 09:44:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
|
|
|
|
local ctrl = CtrlPorts:array() -- get control port array (read/write)
|
2016-02-27 08:56:36 -05:00
|
|
|
|
|
|
|
if Session:transport_rolling() then
|
|
|
|
-- don't do anything if the transport is already rolling
|
|
|
|
ctrl[2] = -math.huge -- set control output port value
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-02-23 09:44:41 -05:00
|
|
|
local threshold = 10 ^ (.05 * ctrl[1]) -- dBFS to coefficient
|
|
|
|
local level = -math.huge
|
2016-02-27 08:56:36 -05:00
|
|
|
|
2016-02-23 09:44:41 -05:00
|
|
|
for c = 1,n_channels do
|
2016-02-27 08:56:36 -05:00
|
|
|
local b = in_map:get(ARDOUR.DataType("audio"), c - 1) -- get id of audio-buffer for the given channel
|
|
|
|
if b ~= ARDOUR.ChanMapping.Invalid then -- check if channel is mapped
|
|
|
|
local a = ARDOUR.DSP.compute_peak(bufs:get_audio(b):data(offset), n_samples, 0) -- compute digital peak
|
2016-02-23 09:44:41 -05:00
|
|
|
if a > threshold then
|
|
|
|
Session:request_transport_speed(1.0, true)
|
|
|
|
end
|
2016-02-27 08:56:36 -05:00
|
|
|
if a > level then level = a end -- max level of all channels
|
2016-02-23 09:44:41 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-27 08:56:36 -05:00
|
|
|
ctrl[2] = ARDOUR.DSP.accurate_coefficient_to_dB (level) -- set control output port value
|
2016-02-23 09:44:41 -05:00
|
|
|
end
|