-
Notifications
You must be signed in to change notification settings - Fork 3
/
BespokeBPF.lua
146 lines (121 loc) · 4.11 KB
/
BespokeBPF.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
-- GLOBALS: app, os, verboseLevel, connect, tie
local app = app
local libcore = require "core.libcore"
local Class = require "Base.Class"
local Unit = require "Unit"
local Fader = require "Unit.ViewControl.Fader"
local GainBias = require "Unit.ViewControl.GainBias"
local Pitch = require "Unit.ViewControl.Pitch"
local Encoder = require "Encoder"
local ply = app.SECTION_PLY
local BespokeBPF = Class{}
BespokeBPF:include(Unit)
function BespokeBPF:init(args)
args.title = "Ladder BPF"
args.mnemonic = "LB"
Unit.init(self,args)
end
function BespokeBPF:onLoadGraph(channelCount)
local lpfilter = self:addObject("filter",libcore.StereoLadderFilter())
local hpfilter = self:addObject("filter",libcore.StereoLadderHPF())
if channelCount==2 then
connect(self,"In1",lpfilter,"Left In")
connect(lpfilter,"Left Out",hpfilter,"Left In")
connect(hpfilter,"Left Out",self,"Out1")
connect(self,"In2",lpfilter,"Right In")
connect(lpfilter,"Right Out",hpfilter,"Right In")
connect(hpfilter,"Right Out",self,"Out2")
else
connect(self,"In1",lpfilter,"Left In")
connect(lpfilter,"Left Out",hpfilter,"Left In")
connect(hpfilter,"Left Out",self,"Out1")
end
local tune = self:addObject("tune",app.ConstantOffset())
local tuneRange = self:addObject("tuneRange",app.MinMax())
local f0 = self:addObject("f0",app.GainBias())
local f0Range = self:addObject("f0Range",app.MinMax())
local res = self:addObject("res",app.GainBias())
local resRange = self:addObject("resRange",app.MinMax())
local clipper = self:addObject("clipper",libcore.Clipper())
clipper:setMaximum(0.999)
clipper:setMinimum(0)
local bw = self:addObject("bw",app.GainBias())
local bwRange = self:addObject("bwRange",app.MinMax())
local negate = self:addObject("negate",app.ConstantGain())
negate:hardSet("Gain",-1)
local addBw = self:addObject("addBw",app.Sum())
local subBw = self:addObject("subBw",app.Sum())
connect(tune,"Out",lpfilter,"V/Oct")
connect(tune,"Out",hpfilter,"V/Oct")
connect(tune,"Out",tuneRange,"In")
connect(f0,"Out",addBw,"Left")
connect(bw,"Out",addBw,"Right")
connect(addBw,"Out",lpfilter,"Fundamental")
--connect(addBw,"Out",hpfilter,"Fundamental")
connect(f0,"Out",subBw,"Left")
connect(bw,"Out",negate,"In")
connect(negate,"Out",subBw,"Right")
--connect(subBw,"Out",lpfilter,"Fundamental")
connect(subBw,"Out",hpfilter,"Fundamental")
connect(f0,"Out",f0Range,"In")
connect(bw,"Out",bwRange,"In")
connect(res, "Out",clipper,"In")
connect(clipper,"Out",lpfilter,"Resonance")
connect(clipper,"Out",hpfilter,"Resonance")
connect(clipper,"Out",resRange,"In")
self:addMonoBranch("tune",tune,"In",tune,"Out")
self:addMonoBranch("Q",res,"In",res,"Out")
self:addMonoBranch("f0",f0,"In",f0,"Out")
self:addMonoBranch("bw",bw,"In",bw,"Out")
end
local views = {
expanded = {"tune","freq","resonance","bandwidth"},
collapsed = {},
}
function BespokeBPF:onLoadViews(objects,branches)
local controls = {}
controls.tune = Pitch {
button = "V/oct",
branch = branches.tune,
description = "V/oct",
offset = objects.tune,
range = objects.tuneRange
}
controls.freq = GainBias {
button = "f0",
branch = branches.f0,
description = "Fundamental",
gainbias = objects.f0,
range = objects.f0Range,
biasMap = Encoder.getMap("filterFreq"),
biasUnits = app.unitHertz,
initialBias = 440,
gainMap = Encoder.getMap("freqGain"),
scaling = app.octaveScaling
}
controls.resonance = GainBias {
button = "Q",
branch = branches.Q,
description = "Resonance",
gainbias = objects.res,
range = objects.resRange,
biasMap = Encoder.getMap("unit"),
biasUnits = app.unitNone,
initialBias = 0.25,
gainMap = Encoder.getMap("[-10,10]")
}
controls.bandwidth = GainBias {
button = "bw",
branch = branches.bw,
description = "Bandwidth",
gainbias = objects.bw,
range = objects.bwRange,
biasMap = Encoder.getMap("filterFreq"),
biasUnits = app.unitHertz,
initialBias = 1,
gainMap = Encoder.getMap("freqGain"),
scaling = app.octaveScaling
}
return controls, views
end
return BespokeBPF