Debian Codegraph @

Resources/modules/Filters/StateVar2.c5

raw
1 class Module(BaseModule):
2 """
3 "State Variable Filter, version 2 !"
4
5 Description
6
7 This module implements a second-order state variable filter (SVF) which allow to
8 interpolate over various filter types, organized in a user-defined order (see
9 `Filter Order` parameter below).
10
11 This 2-pole multimode filter is described in the book "The Art of VA Filter Design"
12 by Vadim Zavalishin (version 2.1.0).
13
14 Sliders
15
16 # Filter Freq :
17 Cutoff or center frequency of the filter.
18 # Filter Q :
19 Q factor (inverse of bandwidth) of the filter.
20 # Filter Shelf :
21 Gain, in dB, used by shelving filters.
22 # Type :
23 Interpolating factor between filters
24 # Dry / Wet :
25 Mix between the original and the filtered signals
26
27 Graph Only
28
29 # Overall Amplitude :
30 The amplitude curve applied on the total duration of the performance
31
32 Popups & Toggles
33
34 # Balance :
35 Compression mode. Off, balanced with a fixed signal
36 or balanced with the input source.
37 # Filter Order :
38 The ordering is a list of one to ten integers indicating the filter
39 types order used by the `Type` parameter to crossfade between them.
40 Types, as integer, are:
41 0 = lowpass
42 1 = bandpass
43 2 = highpass
44 3 = highshelf
45 4 = bandshelf
46 5 = lowshelf
47 6 = notch
48 7 = peak
49 8 = allpass
50 # Polyphony Voices :
51 Number of voices played simultaneously (polyphony),
52 only available at initialization time
53 # Polyphony Chords :
54 Pitch interval between voices (chords),
55 only available at initialization time
56
57 """
58 def __init__(self):
59 BaseModule.__init__(self)
60 self.snd = self.addSampler("snd")
61 self.filtOrder = [0, 1, 2, 3, 4, 5, 6, 7, 8]
62 self.filterType = Sig(self.type, mul=len(self.filtOrder))
63 self.dsp = SVF2(self.snd, freq=self.freq, q=self.q, shelf=self.shelf, type=self.filterType)
64 self.dsp.order = self.filtOrder
65 self.deg = Interp(self.snd, self.dsp, self.drywet, mul=self.env)
66
67 #BALANCE
68 self.osc = Sine(10000, mul=.1)
69 self.balanced = Balance(self.deg, self.osc, freq=10)
70 self.out = Interp(self.deg, self.balanced)
71
72 #INIT
73 self.balance(self.balance_index, self.balance_value)
74
75 def balance(self,index,value):
76 if index == 0:
77 self.out.interp = 0
78 elif index ==1:
79 self.out.interp = 1
80 self.balanced.input2 = self.osc
81 elif index == 2:
82 self.out.interp = 1
83 self.balanced.input2 = self.snd
84
85 def order(self, value):
86 self.filtOrder = value[:]
87 self.dsp.order = self.filtOrder
88 self.filterType.mul = len(self.filtOrder)
89
90 Interface = [
91 csampler(name="snd"),
92 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
93 cslider(name="freq", label="Filter Freq", min=20, max=20000, init=1000, rel="log", unit="Hz", col="green1"),
94 cslider(name="q", label="Filter Q", min=0.5, max=25, init=1, rel="log", unit="x", col="green2"),
95 cslider(name="shelf", label="Filter Shelf", min=-12, max=12, init=-6, rel="lin", unit="dB", col="green3"),
96 cslider(name="type", label="Type", min=0, max=1, init=0.5, rel="lin", unit="x", col="green4"),
97 cslider(name="drywet", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue1"),
98 cgen(name="order", label="Filter Order", init=[0,1,2,3,4,5,6,7,8], col="green1"),
99 cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Source"]),
100 cpoly()
101 ]
102