fix commentary
[ardour.git] / scripts / _convolv.lua
1 ardour { ["type"] = "dsp", name = "Lua Convolver", license = "MIT", author = "Ardour Lua Task Force", description = [[Another simple DSP example]] }
2
3 function dsp_ioconfig () return
4         {
5                 { audio_in = 1, audio_out = 1},
6                 { audio_in = 1, audio_out = 2},
7                 { audio_in = 2, audio_out = 2},
8         }
9 end
10
11 local conv, mode, ir_file
12
13 ir_file = "/tmp/reverbs/St Nicolaes Church.wav"
14 ir_file = "/tmp/reverbs/Large Wide Echo Hall.wav"
15
16 function dsp_configure (ins, outs)
17         if outs:n_audio() == 1 then
18                 assert (ins:n_audio() == 1)
19                 mode = ARDOUR.DSP.IRChannelConfig.Mono
20         elseif ins:n_audio() == 1 then
21                 assert (outs:n_audio() == 2)
22                 mode = ARDOUR.DSP.IRChannelConfig.MonoToStereo
23         else
24                 assert (ins:n_audio() == 2)
25                 assert (outs:n_audio() == 2)
26                 mode = ARDOUR.DSP.IRChannelConfig.Stereo
27         end
28
29         conv = ARDOUR.DSP.Convolver (Session, ir_file, mode, 0)
30         collectgarbage ()
31 end
32
33 function dsp_latency ()
34         if conv then
35                 return conv:latency()
36         else
37                 return 0
38         end
39 end
40
41 -- the DSP callback function to process audio audio
42 -- "ins" and "outs" are http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
43 function dsp_run (ins, outs, n_samples)
44         assert (#ins <= #outs)
45
46         for c = 1, #ins do
47                 if ins[c] ~= outs[c] then -- if processing is not in-place..
48                         ARDOUR.DSP.copy_vector (outs[c], ins[c], n_samples) -- ..copy data from input to output.
49                 end
50         end
51
52         if #outs == 1 then
53                 conv:run (outs[1], n_samples)
54         else
55                 conv:run_stereo (outs[1], outs[2], n_samples)
56         end
57 end