diff options
author | Robin Gareus <robin@gareus.org> | 2016-02-27 14:56:36 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-02-27 14:56:36 +0100 |
commit | 38c15c0714ef77d666615bba742cf239d4256969 (patch) | |
tree | 7b8193b100e61e85a20eaa18a5301a527ae3a0c1 /scripts/voice_activate.lua | |
parent | 803220865698828b5a7681784e6ad2d2bab5e936 (diff) |
Lua example script: fix some typos and add some comments
Diffstat (limited to 'scripts/voice_activate.lua')
-rw-r--r-- | scripts/voice_activate.lua | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/scripts/voice_activate.lua b/scripts/voice_activate.lua index eb9ef962f0..bf21071075 100644 --- a/scripts/voice_activate.lua +++ b/scripts/voice_activate.lua @@ -7,12 +7,13 @@ ardour { 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.]] + when the signal level on the plugin's input exceeds a given threshold.]] } function dsp_ioconfig () return { + -- support all in/out as long as input port count equals output port count { audio_in = -1, audio_out = -1}, } end @@ -26,24 +27,30 @@ function dsp_params () end function dsp_configure (ins, outs) - n_channels = ins:n_audio(); + 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 + + 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 + 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) + 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 if a > threshold then Session:request_transport_speed(1.0, true) end - if a > level then level = a end + if a > level then level = a end -- max level of all channels end end - ctrl[2] = ARDOUR.DSP.accurate_coefficient_to_dB (level) + ctrl[2] = ARDOUR.DSP.accurate_coefficient_to_dB (level) -- set control output port value end |