-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.lua
58 lines (49 loc) · 1.21 KB
/
filter.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function clip(x)
if(x <= -1) then
return -2/3
elseif(x >= 1) then
return 2/3
else
return x-(x^3)/3
end
end
function Filter(params)
local params = params or {type = "bp", g = 0.5, r = 0.5, h = 0.5}
local state_1_, state_2_ = 0,0
local amp = 0
local freq = 1
public = {
update = function (fr,res)
local f = fr
if f >= 0.49 then f = 0.49 end
freq = f
params.g = math.tan(math.pi*f)
params.r = 1.0 / res
params.h = 1.0 / (1.0 + params.r * params.g + params.g * params.g)
end;
process = function (input)
local hp, bp, lp
hp = (input - params.r * state_1_ - params.g * state_1_ - state_2_) * params.h
bp = params.g * hp + state_1_
state_1_ = params.g * hp + bp
lp = params.g * bp + state_2_
state_2_ = params.g * bp + lp
--amp = amp - 0.1*(amp-math.abs(bp))
return lp
end;
processBp = function (input)
local hp, bp, lp
hp = (input - params.r * state_1_ - params.g * state_1_ - state_2_) * params.h
bp = params.g * hp + state_1_
state_1_ = params.g * hp + bp
lp = params.g * bp + state_2_
state_2_ = params.g * bp + lp
--amp = amp - 0.1*(amp-math.abs(bp))
return bp
end;
getFreq = function ()
return freq
end;
}
return public
end