6 author = "Ardour Lua Task Force",
7 description = [[Notch Filter Bank; useful to remove noise with a harmonic spectum (e.g, mains hum, GSM signals, charge-pump noise, etc).
8 Note: this plugin is not suitable to be automated, it is intended for static noise only.]]
11 ------------------------------------------------------------------
12 -- this is a quick/dirty example filter: no de-click, no de-zipper
13 -------------------------------------------------------------------
16 local max_stages = 100
19 function dsp_ioconfig ()
22 -- allow any number of I/O as long as port-count matches
23 { audio_in = -1, audio_out = -1},
27 -- plugin control ports
28 function dsp_params ()
31 { ["type"] = "input", name = "Base Freq", min = 10, max = 2000, default = 100, unit="Hz", logarithmic = true },
32 { ["type"] = "input", name = "Quality", min = 1.0, max = 100.0, default = 8.0, logarithmic = true },
33 { ["type"] = "input", name = "Stages", min = 1.0, max = max_stages, default = 8.0, integer = true },
37 -- plugin instance state
38 local filters = {} -- the biquad filter instances
39 local chn = 0 -- configured channel count
40 local sample_rate = 0 -- configured sample-rate
41 local limit = 0 -- max number of stages (given freq & sample-rate)
43 -- cached control ports (keep track of changed)
47 -- dsp_init is called once when instantiating the plugin
48 function dsp_init (rate)
49 -- remember the sample-rate
53 -- dsp_configure is called every time when the channel-count
54 -- changes, and at least once at the beginning.
55 function dsp_configure (ins, outs)
56 assert (ins:n_audio () == outs:n_audio ())
62 -- remember audio-channels
65 -- set up filter instances for all channels
68 for i = 1, max_stages do
69 filters[c][i] = ARDOUR.DSP.Biquad (sample_rate)
74 -- the actual process function, called every cycle
75 -- ins, outs are audio-data arrays
76 -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
77 -- n_samples are the number of samples to process
78 function dsp_run (ins, outs, n_samples)
79 -- make sure input and output count matches...
80 assert (#ins == #outs)
81 -- ...and matches the configured number of channels
84 local ctrl = CtrlPorts:array () -- get control parameters as array
85 -- ctrl[] .. correspond to the parameters given in in dsp_params()
87 -- test if the plugin-parameters have changed
88 if freq ~= ctrl[1] or qual ~= ctrl[2] then
89 -- remember current settings
92 -- calc max number of states to configure/process
93 limit = math.floor (sample_rate / (2 * freq)) -- at most up to SR / 2
94 if limit > max_stages then limit = max_stages end
96 -- re-compute the filter coefficients for all filters
97 for c = 1, chn do -- for each channel
98 for i = 1, limit do -- and for each filter stage
99 -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad
100 -- and for a list of available types, see
101 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.DSP.Biquad.Type
102 -- the parameters are type, frequency, quality(bandwidth), gain
103 filters[c][i]:compute (ARDOUR.DSP.BiquadType.Notch, freq * i, qual * i, 0)
108 -- limit the number of process stages
109 local stages = math.floor (ctrl['3']) -- current user-set parameter
110 if stages < 1 then stages = 1 end -- at least one stage...
111 if stages > limit then stages = limit end
113 -- process all channels
115 -- when not processing in-place, copy the data from input to output first
116 if ins[c] ~= outs[c] then
117 ARDOUR.DSP.copy_vector (outs[c], ins[c], n_samples)
120 -- run all stages, in-place on the output buffer
122 filters[c][i]:run (outs[c], n_samples)