diff options
author | Robin Gareus <robin@gareus.org> | 2016-02-23 15:44:41 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-02-23 15:44:41 +0100 |
commit | 1473c2d36460707f6484fe5a0f1d913fbb8a77e0 (patch) | |
tree | 407cb23481530549e333fcc4fce8959f7d314a15 /scripts/voice_activate.lua | |
parent | 942471d21f0acbb833849873bba2eb8254c4d28d (diff) |
Add some lua scripts
Diffstat (limited to 'scripts/voice_activate.lua')
-rw-r--r-- | scripts/voice_activate.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/voice_activate.lua b/scripts/voice_activate.lua new file mode 100644 index 0000000000..eb9ef962f0 --- /dev/null +++ b/scripts/voice_activate.lua @@ -0,0 +1,49 @@ +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 + when the signal level on the plugin's input a given threshold.]] +} + +function dsp_ioconfig () + return + { + { 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) + n_channels = ins:n_audio(); +end + +-- use ardour's vectorized functions +function dsp_runmap (bufs, in_map, out_map, n_samples, offset) + local ctrl = CtrlPorts:array() -- get control port array (read/write) + if Session:transport_rolling() then ctrl[2] = -math.huge return end + local threshold = 10 ^ (.05 * ctrl[1]) -- dBFS to coefficient + local level = -math.huge + for c = 1,n_channels do + local b = in_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of buffer for given cannel + if b ~= ARDOUR.ChanMapping.Invalid then + local a = ARDOUR.DSP.compute_peak(bufs:get_audio(b):data(offset), n_samples, 0) + if a > threshold then + Session:request_transport_speed(1.0, true) + end + if a > level then level = a end + end + end + ctrl[2] = ARDOUR.DSP.accurate_coefficient_to_dB (level) +end |