Debian Codegraph @

Resources/modules/Resonators&Verbs/Convolve.c5

raw
1 class Module(BaseModule):
2 """
3 "Circular convolution filtering module"
4
5 Description
6
7 Circular convolution filter where the filter kernel is extract from a soundfile segments.
8
9 Circular convolution is very expensive to compute, so the impulse response must be kept
10 very short to run in real time.
11
12 Sliders
13
14 # Impulse index 1 :
15 Position of the first impulse response in the soundfile (mouse up)
16 # Impulse index 2 :
17 Position of the second impulse response in the soundfile (mouse up)
18 # Imp 1 <--> Imp 2 :
19 Morphing between the two impulse responses
20 # Dry / Wet :
21 Mix between the original signal and the convoluted signal
22
23 Graph Only
24
25 # Overall Amplitude :
26 The amplitude curve applied on the total duration of the performance
27
28 Popups & Toggles
29
30 # Size :
31 Buffer size of the convolution
32 # Balance :
33 Compression mode. Off, balanced with a fixed signal
34 or balanced with the input source.
35 # Polyphony Voices :
36 Number of voices played simultaneously (polyphony),
37 only available at initialization time
38 # Polyphony Spread :
39 Pitch variation between voices (chorus),
40 only available at initialization time
41
42 """
43 def __init__(self):
44 BaseModule.__init__(self)
45 self.snd = self.addSampler("snd")
46 self.dump = self.addFilein("sndtable")
47 self.sizeInSec = sampsToSec(int(self.size_value))
48 if type(self.dump.path) == type([]):
49 p = self.dump.path[0]
50 else:
51 p = self.dump.path
52 self.snddur = sndinfo(p)[1]
53 start = self.snddur*(self.index.get()*0.01)
54 start2 = self.snddur*(self.index2.get()*0.01)
55
56 self.sndtable = SndTable(self.dump.path, start=start, stop=start+self.sizeInSec)
57 self.sndtable2 = SndTable(self.dump.path, start=start2, stop=start2+self.sizeInSec)
58 self.mtable = NewTable(self.sizeInSec, self.nchnls)
59
60 self.morphing= TableMorph(self.morph, self.mtable, [self.sndtable, self.sndtable2])
61 self.convo = Convolve(self.snd, self.mtable, size=int(self.size_value), mul=0.25)
62 self.deg = Interp(self.snd, self.convo, self.drywet, mul=self.env)
63
64 self.osc = Sine(10000,mul=.1)
65 self.balanced = Balance(self.deg, self.osc, freq=10)
66 self.out = Interp(self.deg, self.balanced)
67
68 #INIT
69 self.balance(self.balance_index, self.balance_value)
70
71 def index_up(self, value):
72 start = self.snddur*(value*0.01)
73 self.sndtable.setSound(self.dump.path, start=start, stop=start+self.sizeInSec)
74
75 def index2_up(self, value):
76 start2 = self.snddur*(value*0.01)
77 self.sndtable2.setSound(self.dump.path, start=start2, stop=start2+self.sizeInSec)
78
79 def balance(self,index,value):
80 if index == 0:
81 self.out.interp = 0
82 elif index ==1:
83 self.out.interp = 1
84 self.balanced.input2 = self.osc
85 elif index == 2:
86 self.out.interp = 1
87 self.balanced.input2 = self.snd
88
89 Interface = [ csampler(name="snd"),
90 cfilein(name="sndtable", label="Impulse"),
91 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
92 cslider(name="index", label="Impulse index 1", min=0, max=100, init=25, rel="lin", unit="%", up=True),
93 cslider(name="index2", label="Impulse index 2", min=0, max=100, init=50, rel="lin", unit="%", up=True),
94 cslider(name="morph", label="Imp 1 <--> Imp 2", min=0, max=1, init=0.5, rel="lin", unit="x", col="red"),
95 cslider(name="drywet", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue"),
96 cpopup(name="size", label="Size", init="512", col="grey", rate="i", value=["128","256","512","1024","2048","4096","8192"]),
97 cpopup(name="balance", label = "Balance", init= "Off", col="blue", value=["Off","Compress", "Audio"]),
98 cpoly()
99 ]