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