mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 00:04:56 +01:00
fix lua filters for multi-channels processing
This commit is contained in:
parent
dd79aadb94
commit
f2d2bcfd10
2 changed files with 44 additions and 15 deletions
|
|
@ -53,9 +53,11 @@ function map_type (t)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- these globals are *not* shared between DSP and UI
|
-- 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 cur = {0, 0, 0, 0} -- current parameters
|
||||||
local lpf = 0.03 -- parameter low-pass filter time-constant
|
local lpf = 0.03 -- parameter low-pass filter time-constant
|
||||||
|
local chn = 0 -- channel/filter count
|
||||||
|
|
||||||
function dsp_init (rate)
|
function dsp_init (rate)
|
||||||
self:shmem ():allocate (1) -- shared mem to tell the GUI the samplerate
|
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
|
lpf = 13000 / rate -- interpolation time constant
|
||||||
end
|
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
|
-- helper functions for parameter interpolation
|
||||||
function param_changed (ctrl)
|
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
|
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
|
cur[4] = low_pass_filter_param (cur[4], ctrl[4], 0.01) -- quality
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -126,11 +140,11 @@ function dsp_run (ins, outs, n_samples)
|
||||||
-- check if output and input buffers for this channel are identical
|
-- check if output and input buffers for this channel are identical
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
if ins[c]:sameinstance (outs[c]) then
|
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
|
else
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
|
||||||
ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,16 +55,27 @@ local filters = {} -- the biquad filter instances (DSP)
|
||||||
local filt -- the biquad filter instance (GUI, response)
|
local filt -- the biquad filter instance (GUI, response)
|
||||||
local cur = {0, 0, 0, 0} -- current parameters
|
local cur = {0, 0, 0, 0} -- current parameters
|
||||||
local lpf = 0.03 -- parameter low-pass filter time-constant
|
local lpf = 0.03 -- parameter low-pass filter time-constant
|
||||||
|
local chn = 0 -- channel/filter count
|
||||||
|
|
||||||
function dsp_init (rate)
|
function dsp_init (rate)
|
||||||
self:shmem ():allocate (1) -- shared mem to tell the GUI the samplerate
|
self:shmem ():allocate (1) -- shared mem to tell the GUI the samplerate
|
||||||
local cfg = self:shmem ():to_int (0):array ()
|
local cfg = self:shmem ():to_int (0):array ()
|
||||||
cfg[1] = rate
|
cfg[1] = 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] = {}
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad
|
||||||
for k = 1,4 do
|
for k = 1,4 do
|
||||||
filters[k] = ARDOUR.DSP.Biquad (rate) -- initialize filters
|
filters[c][k] = ARDOUR.DSP.Biquad (rate) -- initialize filters
|
||||||
|
end
|
||||||
end
|
end
|
||||||
lpf = 13000 / rate -- interpolation time constant
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- helper functions for parameter interpolation
|
-- helper functions for parameter interpolation
|
||||||
|
|
@ -91,8 +102,10 @@ function apply_params (ctrl)
|
||||||
|
|
||||||
if cur[1] ~= ctrl[1] or cur[2] ~= ctrl[2] then
|
if cur[1] ~= ctrl[1] or cur[2] ~= ctrl[2] then
|
||||||
-- reset filter state when type or order changes
|
-- reset filter state when type or order changes
|
||||||
|
for c = 1, chn do
|
||||||
for k = 1,4 do
|
for k = 1,4 do
|
||||||
filters[k]:reset ()
|
filters[c][k]:reset ()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
for k = 1,4 do cur[k] = ctrl[k] end
|
for k = 1,4 do cur[k] = ctrl[k] end
|
||||||
else
|
else
|
||||||
|
|
@ -104,8 +117,10 @@ function apply_params (ctrl)
|
||||||
if cur[2] < 1 then cur[2] = 1 end
|
if cur[2] < 1 then cur[2] = 1 end
|
||||||
if cur[2] > 4 then cur[2] = 4 end
|
if cur[2] > 4 then cur[2] = 4 end
|
||||||
|
|
||||||
|
for c = 1, chn do
|
||||||
for k = 1,4 do
|
for k = 1,4 do
|
||||||
filters[k]:compute (map_type (cur[1]), cur[3], cur[4], 0)
|
filters[c][k]:compute (map_type (cur[1]), cur[3], cur[4], 0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -134,15 +149,15 @@ function dsp_run (ins, outs, n_samples)
|
||||||
for c = 1,#ins do
|
for c = 1,#ins do
|
||||||
-- check if output and input buffers for this channel are identical
|
-- check if output and input buffers for this channel are identical
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- 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
|
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
|
end
|
||||||
else
|
else
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
|
||||||
ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
|
ARDOUR.DSP.copy_vector (outs[c]:offset (off), ins[c]:offset (off), siz)
|
||||||
for k = 1,o do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue