mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-16 03:36:32 +01:00
Release notch-bank filter
This commit is contained in:
parent
6edc919656
commit
0a9674ec6b
1 changed files with 21 additions and 17 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
ardour {
|
ardour {
|
||||||
["type"] = "dsp",
|
["type"] = "dsp",
|
||||||
name = "Notch Bank",
|
name = "a-Notch Bank",
|
||||||
category = "Example",
|
category = "Filter",
|
||||||
license = "MIT",
|
license = "MIT",
|
||||||
author = "Ardour Lua Task Force",
|
author = "Ardour Lua Task Force",
|
||||||
description = [[An Example Filter Plugin]]
|
description = [[Notch Filter Bank; useful to remove noise with a harmonic spectum (e.g, mains hum, GSM signals, charge-pump noise, etc).
|
||||||
|
Note: this plugin is not suitable to be automated, it is intended for static noise only.]]
|
||||||
}
|
}
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
-- this is a quick/dirty example filter: no de-click, no de-zipper,
|
-- this is a quick/dirty example filter: no de-click, no de-zipper
|
||||||
-- no latency reporting,...
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
-- configuration
|
-- configuration
|
||||||
|
|
@ -28,23 +28,22 @@ end
|
||||||
function dsp_params ()
|
function dsp_params ()
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
{ ["type"] = "input", name = "Base Freq", min = 10, max = 1000, default = 100, unit="Hz", logarithmic = true },
|
{ ["type"] = "input", name = "Base Freq", min = 10, max = 2000, default = 100, unit="Hz", logarithmic = true },
|
||||||
{ ["type"] = "input", name = "Quality", min = 1.0, max = 100.0, default = 8.0, logarithmic = true },
|
{ ["type"] = "input", name = "Quality", min = 1.0, max = 100.0, default = 8.0, logarithmic = true },
|
||||||
{ ["type"] = "input", name = "Stages", min = 1.0, max = max_stages, default = 8.0, integer = true },
|
{ ["type"] = "input", name = "Stages", min = 1.0, max = max_stages, default = 8.0, integer = true },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- plugin instance state
|
-- plugin instance state
|
||||||
local filters = {} -- the biquad filter instances
|
local filters = {} -- the biquad filter instances
|
||||||
local chn = 0 -- configured channel count
|
local chn = 0 -- configured channel count
|
||||||
local sample_rate = 0 -- configured sample-rate
|
local sample_rate = 0 -- configured sample-rate
|
||||||
|
local limit = 0 -- max number of stages (given freq & sample-rate)
|
||||||
|
|
||||||
-- cached control ports (keep track of changed)
|
-- cached control ports (keep track of changed)
|
||||||
local freq = 0
|
local freq = 0
|
||||||
local qual = 0
|
local qual = 0
|
||||||
|
|
||||||
|
|
||||||
-- dsp_init is called once when instantiating the plugin
|
-- dsp_init is called once when instantiating the plugin
|
||||||
function dsp_init (rate)
|
function dsp_init (rate)
|
||||||
-- remember the sample-rate
|
-- remember the sample-rate
|
||||||
|
|
@ -56,6 +55,10 @@ end
|
||||||
function dsp_configure (ins, outs)
|
function dsp_configure (ins, outs)
|
||||||
assert (ins:n_audio () == outs:n_audio ())
|
assert (ins:n_audio () == outs:n_audio ())
|
||||||
|
|
||||||
|
-- explicit cleanup
|
||||||
|
filters = {}
|
||||||
|
collectgarbage ()
|
||||||
|
|
||||||
-- remember audio-channels
|
-- remember audio-channels
|
||||||
chn = ins:n_audio ()
|
chn = ins:n_audio ()
|
||||||
|
|
||||||
|
|
@ -68,7 +71,6 @@ function dsp_configure (ins, outs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- the actual process function, called every cycle
|
-- the actual process function, called every cycle
|
||||||
-- ins, outs are audio-data arrays
|
-- ins, outs are audio-data arrays
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
|
|
@ -79,31 +81,33 @@ function dsp_run (ins, outs, n_samples)
|
||||||
-- ...and matches the configured number of channels
|
-- ...and matches the configured number of channels
|
||||||
assert (#ins == chn)
|
assert (#ins == chn)
|
||||||
|
|
||||||
local ctrl = CtrlPorts:array() -- get control parameters as array
|
local ctrl = CtrlPorts:array () -- get control parameters as array
|
||||||
-- ctrl[1] .. corresponds to the parameters given in in dsp_params()
|
-- ctrl[] .. correspond to the parameters given in in dsp_params()
|
||||||
|
|
||||||
-- test if the plugin-parameters have changed
|
-- test if the plugin-parameters have changed
|
||||||
if freq ~= ctrl[1] or qual ~= ctrl[2] then
|
if freq ~= ctrl[1] or qual ~= ctrl[2] then
|
||||||
-- remember current settings
|
-- remember current settings
|
||||||
freq = ctrl[1]
|
freq = ctrl[1]
|
||||||
qual = ctrl[2]
|
qual = ctrl[2]
|
||||||
|
-- calc max number of states to configure/process
|
||||||
|
limit = math.floor (sample_rate / (2 * freq)) -- at most up to SR / 2
|
||||||
|
if limit > max_stages then limit = max_stages end
|
||||||
|
|
||||||
-- re-compute the filter coefficients for all filters
|
-- re-compute the filter coefficients for all filters
|
||||||
for c = 1, chn do -- for each channel
|
for c = 1, chn do -- for each channel
|
||||||
for i = 1, max_stages do -- and for each filter stage
|
for i = 1, limit do -- and for each filter stage
|
||||||
-- the parameters are type, frequency, quality(bandwidth), gain
|
|
||||||
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad
|
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:Biquad
|
||||||
-- for a list of available types, see
|
-- and for a list of available types, see
|
||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.DSP.Biquad.Type
|
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.DSP.Biquad.Type
|
||||||
|
-- the parameters are type, frequency, quality(bandwidth), gain
|
||||||
filters[c][i]:compute (ARDOUR.DSP.BiquadType.Notch, freq * i, qual * i, 0)
|
filters[c][i]:compute (ARDOUR.DSP.BiquadType.Notch, freq * i, qual * i, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- limit the number of process stages
|
-- limit the number of process stages
|
||||||
local limit = math.floor (sample_rate / ( 2 * freq )) -- at most up to SR / 2
|
|
||||||
local stages = math.floor (ctrl['3']) -- current user-set parameter
|
local stages = math.floor (ctrl['3']) -- current user-set parameter
|
||||||
if stages < 1 then stages = 1 end -- at least one stage...
|
if stages < 1 then stages = 1 end -- at least one stage...
|
||||||
if stages > max_stages then stages = max_stages end
|
|
||||||
if stages > limit then stages = limit end
|
if stages > limit then stages = limit end
|
||||||
|
|
||||||
-- process all channels
|
-- process all channels
|
||||||
Loading…
Add table
Add a link
Reference in a new issue