2020-04-30 12:17:10 -04:00
|
|
|
ardour {
|
|
|
|
["type"] = "dsp",
|
2020-07-12 18:53:45 -04:00
|
|
|
name = "a-Cross Fade",
|
2020-04-30 12:17:10 -04:00
|
|
|
category = "Amplifier",
|
|
|
|
license = "MIT",
|
|
|
|
author = "Ardour Team",
|
2020-07-12 18:53:45 -04:00
|
|
|
description = [[Auotomatable Crossfade. Channels are grouped:
|
|
|
|
Mono out: In 1/2 -> Out 1
|
|
|
|
Stereo out: In 1/3 -> Out 1, In 2/4 -> Out 2
|
|
|
|
Quad out: In 1/5 -> Out 1, In 2/6 -> Out 2, In 3/7 -> Out 3, In 4/8 -> Out 4
|
|
|
|
]]
|
2020-04-30 12:17:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function dsp_ioconfig ()
|
|
|
|
return {
|
2020-07-12 18:53:45 -04:00
|
|
|
connect_all_audio_outputs = true, -- override strict-i/o
|
2020-04-30 12:17:10 -04:00
|
|
|
-- in theory any combination with N_in = 2 * N_out is possible
|
|
|
|
{ audio_in = 2, audio_out = 1},
|
|
|
|
{ audio_in = 4, audio_out = 2},
|
|
|
|
{ audio_in = 8, audio_out = 4},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function dsp_params ()
|
2020-07-12 18:53:45 -04:00
|
|
|
return { { ["type"] = "input", name = "A/B", min = 0, max = 1, default = 0} }
|
2020-04-30 12:17:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local sr = 48000
|
|
|
|
local cur_a = 0.0
|
|
|
|
local cur_b = 0.0
|
|
|
|
|
2020-07-12 18:53:45 -04:00
|
|
|
local n_aout = 0
|
|
|
|
|
2020-04-30 12:17:10 -04:00
|
|
|
function dsp_init (rate)
|
|
|
|
sr = rate
|
|
|
|
end
|
|
|
|
|
|
|
|
function dsp_configure (ins, outs)
|
|
|
|
n_ainp = ins:n_audio ()
|
|
|
|
n_aout = outs:n_audio ()
|
|
|
|
assert (n_aout * 2 == n_ainp)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- the DSP callback function
|
|
|
|
function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
|
|
|
|
local ctrl = CtrlPorts:array() -- get control port array
|
2020-07-12 18:53:45 -04:00
|
|
|
local target_B = ctrl[1]
|
|
|
|
local target_A = 1 - target_B
|
2020-04-30 12:17:10 -04:00
|
|
|
|
|
|
|
local gA = cur_a
|
|
|
|
local gB = cur_b
|
|
|
|
|
|
|
|
for c = 1, n_aout do
|
|
|
|
local o = out_map:get (ARDOUR.DataType ("audio"), c - 1)
|
|
|
|
if o == ARDOUR.ChanMapping.Invalid then
|
|
|
|
goto next
|
|
|
|
end
|
|
|
|
|
2020-07-12 18:53:45 -04:00
|
|
|
local in_a = c
|
|
|
|
local in_b = c + n_aout
|
2020-04-30 12:17:10 -04:00
|
|
|
local ia = in_map:get (ARDOUR.DataType ("audio"), in_a - 1)
|
|
|
|
local ib = in_map:get (ARDOUR.DataType ("audio"), in_b - 1)
|
|
|
|
|
|
|
|
local buf_aout = bufs:get_audio(o)
|
|
|
|
|
2020-07-12 18:53:45 -04:00
|
|
|
-- optimize hard A/B fixed gain case (copy buffers)
|
2020-04-30 12:17:10 -04:00
|
|
|
if cur_a == target_A and cur_b == target_B then
|
|
|
|
if target_A == 1.0 then
|
2020-07-23 15:51:13 -04:00
|
|
|
if ia == ARDOUR.ChanMapping.Invalid then
|
|
|
|
buf_aout:silence (n_samples, offset)
|
|
|
|
elseif buf_aout ~= bufs:get_audio(ia) then
|
2020-04-30 12:17:10 -04:00
|
|
|
buf_aout:read_from (bufs:get_audio(ia):data (0), n_samples, offset, offset)
|
|
|
|
end
|
2020-07-12 18:53:45 -04:00
|
|
|
goto next
|
|
|
|
elseif target_B == 1.0 then
|
2020-07-23 15:51:13 -04:00
|
|
|
if ib == ARDOUR.ChanMapping.Invalid then
|
|
|
|
buf_aout:silence (n_samples, offset)
|
|
|
|
else
|
|
|
|
assert (buf_aout ~= bufs:get_audio(ib))
|
|
|
|
buf_aout:read_from (bufs:get_audio(ib):data (0), n_samples, offset, offset)
|
|
|
|
end
|
2020-07-12 18:53:45 -04:00
|
|
|
goto next
|
2020-04-30 12:17:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-12 18:53:45 -04:00
|
|
|
-- apply gain to each input channel in-place
|
2020-04-30 12:17:10 -04:00
|
|
|
if ia ~= ARDOUR.ChanMapping.Invalid and ia ~= ib then
|
|
|
|
cur_a = ARDOUR.Amp.apply_gain (bufs:get_audio(ia), sr, n_samples, gA, target_A, offset)
|
|
|
|
end
|
|
|
|
if ib ~= ARDOUR.ChanMapping.Invalid and ia ~= ib then
|
|
|
|
cur_b = ARDOUR.Amp.apply_gain (bufs:get_audio(ib), sr, n_samples, gB, target_B, offset)
|
|
|
|
end
|
|
|
|
|
2020-07-12 18:53:45 -04:00
|
|
|
-- copy input to output if needed (first set of channels may be in-place)
|
2020-07-23 15:51:13 -04:00
|
|
|
if ia == ARDOUR.ChanMapping.Invalid then
|
|
|
|
buf_aout:silence (n_samples, offset)
|
|
|
|
elseif buf_aout ~= bufs:get_audio(ia) then
|
2020-04-30 12:17:10 -04:00
|
|
|
buf_aout:read_from (bufs:get_audio(ia):data (0), n_samples, offset, offset)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- add the second buffer
|
2020-07-23 15:51:13 -04:00
|
|
|
if ib ~= ARDOUR.ChanMapping.Invalid then
|
|
|
|
ARDOUR.DSP.mix_buffers_no_gain (buf_aout:data (offset), bufs:get_audio(ib):data (offset), n_samples)
|
|
|
|
end
|
2020-04-30 12:17:10 -04:00
|
|
|
|
|
|
|
::next::
|
|
|
|
end
|
|
|
|
end
|