6 author = "Ardour Lua Task Force",
7 description = [[An Example Filter Plugin]]
10 -------------------------------------------------------------------
11 -- this is a quick/dirty example filter: no de-click, no de-zipper,
12 -- no latency reporting,...
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 = 1000, 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 },
38 -- plugin instance state
39 local filters = {} -- the biquad filter instances
40 local chn = 0 -- configured channel count
41 local sample_rate = 0 -- configured sample-rate
43 -- cached control ports (keep track of changed)
48 -- dsp_init is called once when instantiating the plugin
49 function dsp_init (rate)
50 -- remember the sample-rate
54 -- dsp_configure is called every time when the channel-count
55 -- changes, and at least once at the beginning.
56 function dsp_configure (ins, outs)
57 assert (ins:n_audio () == outs:n_audio ())
59 -- remember audio-channels
62 -- set up filter instances for all channels
65 for i = 1, max_stages do
66 filters[c][i] = ARDOUR.DSP.Biquad (sample_rate)
72 -- the actual process function, called every cycle
73 -- ins, outs are audio-data arrays
74 -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
75 -- n_samples are the number of samples to process
76 function dsp_run (ins, outs, n_samples)
77 -- make sure input and output count matches...
78 assert (#ins == #outs)
79 -- ...and matches the configured number of channels
82 local ctrl = CtrlPorts:array() -- get control parameters as array
83 -- ctrl[1] .. corresponds to the parameters given in in dsp_params()
85 -- test if the plugin-parameters have changed
86 if freq ~= ctrl[1] or qual ~= ctrl[2] then
87 -- remember current settings
90 -- re-compute the filter coefficients for all filters
91 for c = 1, chn do -- for each channel
92 for i = 1, max_stages do -- and for each filter stage
93 -- the parameters are type, frequency, quality(bandwidth), gain
94 -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad
95 -- for a list of available types, see
96 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.DSP.Biquad.Type
97 filters[c][i]:compute (ARDOUR.DSP.BiquadType.Notch, freq * i, qual * i, 0)
102 -- limit the number of process stages
103 local limit = math.floor (sample_rate / ( 2 * freq )) -- at most up to SR / 2
104 local stages = math.floor (ctrl['3']) -- current user-set parameter
105 if stages < 1 then stages = 1 end -- at least one stage...
106 if stages > max_stages then stages = max_stages end
107 if stages > limit then stages = limit end
109 -- process all channels
111 -- when not processing in-place, copy the data from input to output first
112 if ins[c] ~= outs[c] then
113 ARDOUR.DSP.copy_vector (outs[c], ins[c], n_samples)
116 -- run all stages, in-place on the output buffer
118 filters[c][i]:run (outs[c], n_samples)