Fix Mixbus action fc83d044f8 & 65bda27d4 rebase ordering
[ardour.git] / scripts / _amp1.lua
1 ardour {
2         ["type"]    = "dsp",
3         name        = "Simple Amp",
4         category    = "Example",
5         license     = "MIT",
6         author      = "Ardour Lua Task Force",
7         description = [[
8         An Example DSP Plugin for processing audio, to
9         be used with Ardour's Lua scripting facility.]]
10 }
11
12
13 -- return possible i/o configurations
14 function dsp_ioconfig ()
15         -- -1, -1 = any number of channels as long as input and output count matches
16         return { [1] = { audio_in = -1, audio_out = -1}, }
17 end
18
19 -- optional function, called when configuring the plugin
20 function dsp_configure (ins, outs)
21         -- store configuration in global variable
22         audio_ins = ins:n_audio();
23         local audio_outs = outs:n_audio()
24         assert (audio_ins == audio_outs)
25 end
26
27 -- this variant asks for a complete *copy* of the
28 -- audio data in a lua-table.
29 -- after processing the data is copied back.
30 --
31 -- this also exemplifies the direct "connect and run" process function,
32 -- where the channel-mapping needs to be done in lua.
33
34 function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
35         for c = 1,audio_ins do
36                 -- Note: lua starts counting at 1, ardour's ChanMapping::get() at 0
37                 local ib = in_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of mapped input buffer for given channel
38                 local ob = out_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of mapped output buffer for given channel
39                 assert (ib ~= ARDOUR.ChanMapping.Invalid);
40                 assert (ob ~= ARDOUR.ChanMapping.Invalid);
41                 local a = bufs:get_audio (ib):data (offset):get_table(n_samples) -- copy audio-data from input buffer
42                 for s = 1,n_samples do
43                         a[s] = a[s] * 2; -- amplify data in lua table
44                 end
45                 bufs:get_audio(ob):data(offset):set_table(a, n_samples) -- copy back
46         end
47 end