Debian Codegraph @

Resources/modules/Time/UltimateGrainer.c5

raw
1 import random
2 class Module(BaseModule):
3 """
4 "A state-of-the-art granulation processing module"
5
6 Description
7
8 This module offers more controls than the classic granulation module.
9 Useful to generate clouds, to stretch a sound without changing the pitch
10 or to transpose without changing the duration. It features a grain filter
11 with control over type, frequency and Q for each grain.
12
13 `Density per Second * Grain Duration` defines the overall overlaps.
14
15 Sliders
16
17 # Density per Sec :
18 How many grains to play per second
19 # Transpose :
20 Overall transposition, in cents, of the grains
21 # Grain Position :
22 Soundfile index
23 # Grain Duration :
24 Duration of each grain, in seconds
25 # Start Time Dev :
26 Maximum deviation of the starting time of the grain
27 # Filter Freq :
28 Filter cutoff or center frequency, chosen at the beginning of the grain
29 # Filter Q :
30 Filter Q, chosen at the beginning of the grain
31 # Panning Random :
32 Random added to the panning of each grain
33 # Density Random :
34 Jitter applied to the density per second
35 # Pitch Random :
36 Jitter applied on the pitch of the grains
37 # Position Random :
38 Jitter applied on the soundfile index
39 # Duration Random :
40 Jitter applied to the grain duration
41 # Filter Freq Random :
42 Jitter applied to the grain's filter cutoff or center frequency
43 # Filter Q Random :
44 Jitter applied to the grain's filter Q
45
46 Graph Only
47
48 # Overall Amplitude :
49 The amplitude curve applied on the total duration of the performance
50 # Grain Envelope :
51 Emplitude envelope of the grains
52
53 Popups & Toggles
54
55 # Balance :
56 Compression mode. Off, balanced with a fixed signal
57 or balanced with the input source.
58 # Filter Type :
59 Type of the grain's filter (Lowpass, Highpass, Bandpass, Bandstop, Allpass)
60 # Filter Freq Ratio :
61 List ratios used to randomize grain's filter frequency
62 # Discreet Transpo :
63 List of pitch ratios used to randomize grain's transposition
64 # Polyphony Voices :
65 Number of voices played simultaneously (polyphony),
66 only available at initialization time
67 # Polyphony Spread :
68 Pitch variation between voices (chorus),
69 only available at initialization time
70
71 """
72 def __init__(self):
73 BaseModule.__init__(self)
74 self.table = self.addFilein("sndtable")
75 self.densr = Randi(-self.dnsrnd, self.dnsrnd, freq=1, add=1)
76 self.posr = Noise(self.posrnd * self.table.getSize(False))
77 self.pitr = Noise(self.pitrnd, add=1)
78 self.durr = Noise(self.durrnd, add=1)
79 self.freqr = Noise(self.ffrnd, add=1)
80 self.qr = Noise(self.fqrnd, add=1)
81 self.filterfreq = Choice(choice=self.ffchoice_value, freq=1000, mul=self.ffreq)
82 self.discr = Choice(choice=self.discreet_value, freq=1000)
83 self.pitch = CentsToTranspo(self.transp, mul=self.polyphony_spread)
84 self.pospos = Sig(self.pos, mul=self.table.getSize(False), add=self.posr)
85 initpan = [float(i) / (self.nchnls-1) for i in range(self.nchnls)]
86 self.panr = Noise(self.pan, add=initpan)
87 self.panw = Clip(self.panr, 0, 1)
88
89 self.gr = Particle2(table=self.table,
90 env=self.grainenv,
91 dens=self.dens*self.densr,
92 pitch=self.pitch*self.pitr*self.discr,
93 pos=self.pospos,
94 dur=self.dur*self.durr,
95 dev=self.dev,
96 pan=self.panw,
97 filterfreq=self.filterfreq*self.freqr,
98 filterq=self.filterq*self.qr,
99 filtertype=self.filtertype_index,
100 chnls=self.nchnls,
101 mul=self.env*0.2
102 )
103
104 self.osc = Sine(10000,mul=.1)
105 self.balanced = Balance(self.gr, self.osc, freq=10)
106 self.out = Interp(self.gr, self.balanced)
107
108 #INIT
109 self.balance(self.balance_index, self.balance_value)
110
111 def balance(self, index, value):
112 if index == 0:
113 self.out.interp = 0
114 elif index ==1:
115 self.out.interp = 1
116 self.balanced.input2 = self.osc
117 elif index == 2:
118 self.out.interp = 1
119 self.balanced.input2 = self.gr
120
121 def filtertype(self, index, value):
122 self.gr.filtertype = index
123
124 def ffchoice(self, value):
125 self.filterfreq.choice = value
126
127 def discreet(self, value):
128 self.discr.choice = value
129
130 Interface = [ cfilein(name="sndtable", label="Audio"),
131 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
132 cgraph(name="grainenv", label="Grain Envelope", func=[(0,0),(0.5,1),(1,0)], table=True, curved=True, col="purple1"),
133
134 cslider(name="dens", label="Density per Sec", min=1, max=1000, init=100, rel="log", gliss=0, res="int", unit="x", col="blue1"),
135 cslider(name="transp", label="Transpose", min=-4800, max=4800, init=0, rel="lin", unit="cnts", col="red1"),
136 cslider(name="pos", label="Grain Position", min=0, max=1, init=0, func=[(0,0),(1,1)], rel="lin", unit="x", col="purple1"),
137 cslider(name="dur", label="Grain Duration", min=0.0001, max=10, init=0.15, rel="log", unit="sec", col="orange1"),
138 cslider(name="dev", label="Start Time Dev", min=0.0001, max=1, init=0.01, rel="log", unit="x", col="purple3"),
139 cslider(name="ffreq", label="Filter Freq", min=20, max=18000, init=10000, rel="log", unit="Hz", col="green1"),
140 cslider(name="filterq", label="Filter Q", min=0.5, max=20, init=0.7, rel="log", unit="x", col="green2"),
141
142 cslider(name="pan", label="Panning Random", min=0, max=1, init=0, rel="lin", unit="x", col="purple4"),
143
144 cslider(name="dnsrnd", label="Density Random", min=0.00001, max=1, init=0.001, rel="log", unit="x", col="blue2", half=True),
145 cslider(name="pitrnd", label="Pitch Random", min=0.00001, max=0.5, init=0.001, rel="log", unit="x", col="red2", half=True),
146 cslider(name="posrnd", label="Position Random", min=0.00001, max=0.5, init=0.001, rel="log", unit="x", col="purple2", half=True),
147 cslider(name="durrnd", label="Duration Random", min=0.00001, max=1, init=0.001, rel="log", unit="x", col="orange2", half=True),
148 cslider(name="ffrnd", label="Filter Freq Random", min=0.00001, max=1, init=0.001, rel="log", unit="x", col="green1", half=True),
149 cslider(name="fqrnd", label="Filter Q Random", min=0.00001, max=1, init=0.001, rel="log", unit="x", col="green2", half=True),
150
151 cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Source"]),
152 cpopup(name="filtertype", label = "Filter Type", init= "Lowpass", col="green1",
153 value=["Lowpass","Highpass", "Bandpass", "Bandstop", "Allpass"]),
154 cgen(name="ffchoice", label="Filter Freq Ratio", init=[1], col="green1"),
155 cgen(name="discreet", label="Discreet Transpo", init=[1], col="red1"),
156 cpoly()
157 ]
158