From f2d2bcfd106a24d517acf7ba4f6dc1dc1aaa2f10 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 1 Jul 2016 16:01:19 +0200 Subject: fix lua filters for multi-channels processing --- scripts/filt.lua | 22 ++++++++++++++++++---- scripts/hplp.lua | 37 ++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/scripts/filt.lua b/scripts/filt.lua index 5f22a48953..5c1b6df73d 100644 --- a/scripts/filt.lua +++ b/scripts/filt.lua @@ -53,9 +53,11 @@ function map_type (t) end -- these globals are *not* shared between DSP and UI -local filt -- the biquad filter instance +local filters = {} -- the biquad filter instances (DSP) +local filt -- the biquad filter instance (GUI, response) local cur = {0, 0, 0, 0} -- current parameters local lpf = 0.03 -- parameter low-pass filter time-constant +local chn = 0 -- channel/filter count function dsp_init (rate) self:shmem ():allocate (1) -- shared mem to tell the GUI the samplerate @@ -66,6 +68,16 @@ function dsp_init (rate) lpf = 13000 / rate -- interpolation time constant end +function dsp_configure (ins, outs) + assert (ins:n_audio () == outs:n_audio ()) + local cfg = self:shmem ():to_int (0):array () + local rate = cfg[1] + chn = ins:n_audio () + for c = 1, chn do + filters[c] = ARDOUR.DSP.Biquad (rate) -- initialize filters + end +end + -- helper functions for parameter interpolation function param_changed (ctrl) if ctrl[1] == cur[1] and ctrl[2] == cur[2] and ctrl[3] == cur[3] and ctrl[4] == cur[4] then @@ -99,7 +111,9 @@ function apply_params (ctrl) cur[4] = low_pass_filter_param (cur[4], ctrl[4], 0.01) -- quality end - filt:compute (map_type (cur[1]), cur[3], cur[4], cur[2]) + for c = 1, chn do + filters[c]:compute (map_type (cur[1]), cur[3], cur[4], cur[2]) + end end @@ -126,11 +140,11 @@ function dsp_run (ins, outs, n_samples) -- check if output and input buffers for this channel are identical -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray if ins[c]:sameinstance (outs[c]) then - filt:run (ins[c]:offset (off), siz) -- in-place processing + filters[c]:run (ins[c]:offset (off), siz) -- in-place processing else -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz) - filt:run (outs[c]:offset (off), siz) + filters[c]:run (outs[c]:offset (off), siz) end end diff --git a/scripts/hplp.lua b/scripts/hplp.lua index 3b6a34c0fd..f894732e7d 100644 --- a/scripts/hplp.lua +++ b/scripts/hplp.lua @@ -55,18 +55,29 @@ local filters = {} -- the biquad filter instances (DSP) local filt -- the biquad filter instance (GUI, response) local cur = {0, 0, 0, 0} -- current parameters local lpf = 0.03 -- parameter low-pass filter time-constant +local chn = 0 -- channel/filter count function dsp_init (rate) self:shmem ():allocate (1) -- shared mem to tell the GUI the samplerate local cfg = self:shmem ():to_int (0):array () cfg[1] = rate - -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad - for k = 1,4 do - filters[k] = ARDOUR.DSP.Biquad (rate) -- initialize filters - end lpf = 13000 / rate -- interpolation time constant end +function dsp_configure (ins, outs) + assert (ins:n_audio () == outs:n_audio ()) + local cfg = self:shmem ():to_int (0):array () + local rate = cfg[1] + chn = ins:n_audio () + for c = 1, chn do + filters[c] = {} + -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad + for k = 1,4 do + filters[c][k] = ARDOUR.DSP.Biquad (rate) -- initialize filters + end + end +end + -- helper functions for parameter interpolation function param_changed (ctrl) if ctrl[1] == cur[1] and ctrl[2] == cur[2] and ctrl[3] == cur[3] and ctrl[4] == cur[4] then @@ -91,8 +102,10 @@ function apply_params (ctrl) if cur[1] ~= ctrl[1] or cur[2] ~= ctrl[2] then -- reset filter state when type or order changes - for k = 1,4 do - filters[k]:reset () + for c = 1, chn do + for k = 1,4 do + filters[c][k]:reset () + end end for k = 1,4 do cur[k] = ctrl[k] end else @@ -104,8 +117,10 @@ function apply_params (ctrl) if cur[2] < 1 then cur[2] = 1 end if cur[2] > 4 then cur[2] = 4 end - for k = 1,4 do - filters[k]:compute (map_type (cur[1]), cur[3], cur[4], 0) + for c = 1, chn do + for k = 1,4 do + filters[c][k]:compute (map_type (cur[1]), cur[3], cur[4], 0) + end end end @@ -134,15 +149,15 @@ function dsp_run (ins, outs, n_samples) for c = 1,#ins do -- check if output and input buffers for this channel are identical -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray - if ins[c]:sameinstance (outs[c]) then + if false then --- ins[c]:sameinstance (outs[c]) then for k = 1,o do - filters[k]:run (ins[c]:offset (off), siz) -- in-place processing + filters[c][k]:run (ins[c]:offset (off), siz) -- in-place processing end else -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz) for k = 1,o do - filters[o]:run (outs[c]:offset (off), siz) + filters[c][k]:run (outs[c]:offset (off), siz) end end end -- cgit v1.2.3