add a notch-bank filter
[ardour.git] / scripts / _notch_bank.lua
1 ardour {
2         ["type"]    = "dsp",
3         name        = "Notch Bank",
4         category    = "Example",
5         license     = "MIT",
6         author      = "Ardour Lua Task Force",
7         description = [[An Example Filter Plugin]]
8 }
9
10 function dsp_ioconfig ()
11         return
12         {
13                 { audio_in = 1, audio_out = 1},
14         }
15 end
16
17 function dsp_params ()
18         return
19         {
20                 { ["type"] = "input", name = "Base Freq", min = 10, max = 1000, default = 100, unit="Hz", logarithmic = true },
21                 { ["type"] = "input", name = "Quality", min = 1.0, max = 16.0, default = 8.0 },
22                 { ["type"] = "input", name = "Stages", min = 1.0, max = 20, default = 6.0, integer = true },
23         }
24 end
25
26 local filters = {} -- the biquad filter instances
27 local freq = 0
28 local bw = 0
29
30 function dsp_init (rate)
31         for i = 1,20 do
32                 filters[i] = ARDOUR.DSP.Biquad (rate)
33         end
34 end
35
36 function dsp_run (ins, outs, n_samples)
37         assert (#outs == 1)
38         assert (n_samples < 8192)
39
40         -- this is quick/dirty: no declick, no de-zipper, no latency reporting,...
41         -- and no documentation :)
42
43         local ctrl = CtrlPorts:array() -- get control parameters
44         if freq ~= ctrl[1] or bw ~= ctrl[2] then
45                 freq = ctrl[1]
46                 bw = ctrl[2]
47                 for i = 1,20 do
48                         filters[i]:compute (ARDOUR.DSP.BiquadType.Notch, freq * i, bw, 0)
49                 end
50         end
51
52         if not ins[1]:sameinstance (outs[1]) then
53                 ARDOUR.DSP.copy_vector (outs[1], outs[1], n_samples)
54         end
55
56         local stages = math.floor (ctrl['3'])
57         if stages < 1 then stages = 1; end
58         if stages > 20 then stages = 20; end
59
60         for i = 1, stages do
61                 filters[i]:run (outs[1], n_samples)
62         end
63 end