summaryrefslogtreecommitdiff
path: root/share/scripts/__convolv.lua
blob: 23ad9034eda26edd9bd1c729ff3055e1c1611297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
ardour { ["type"] = "dsp", name = "Lua Convolver", license = "MIT", author = "Ardour Lua Task Force", description = [[Another simple DSP example]] }

function dsp_ioconfig () return
	{
		{ audio_in = 1, audio_out = 1},
		{ audio_in = 1, audio_out = 2},
		{ audio_in = 2, audio_out = 2},
	}
end

local conv, mode, ir_file

ir_file = "/tmp/reverbs/St Nicolaes Church.wav"
ir_file = "/tmp/reverbs/Large Wide Echo Hall.wav"

function dsp_configure (ins, outs)
	if outs:n_audio() == 1 then
		assert (ins:n_audio() == 1)
		mode = ARDOUR.DSP.IRChannelConfig.Mono
	elseif ins:n_audio() == 1 then
		assert (outs:n_audio() == 2)
		mode = ARDOUR.DSP.IRChannelConfig.MonoToStereo
	else
		assert (ins:n_audio() == 2)
		assert (outs:n_audio() == 2)
		mode = ARDOUR.DSP.IRChannelConfig.Stereo
	end

	local irs = ARDOUR.DSP.IRSettings()
	irs.gain = 0.5
	conv = ARDOUR.DSP.Convolver (Session, ir_file, mode, irs)
	collectgarbage ()
end

function dsp_latency ()
	if conv then
		return conv:latency()
	else
		return 0
	end
end

-- the DSP callback function to process audio audio
-- "ins" and "outs" are http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
function dsp_run (ins, outs, n_samples)
	assert (#ins <= #outs)

	for c = 1, #ins do
		if ins[c] ~= outs[c] then -- if processing is not in-place..
			ARDOUR.DSP.copy_vector (outs[c], ins[c], n_samples) -- ..copy data from input to output.
		end
	end

	if #outs == 1 then
		conv:run_mono (outs[1], n_samples)
	else
		conv:run_stereo (outs[1], outs[2], n_samples)
	end
end