Debian Codegraph @

Resources/modules/Time/Particle.c5

raw
1 import random
2 class Module(BaseModule):
3 """
4 "A full-featured granulation 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.
11
12 `Density per Second * Grain Duration` defines the overall overlaps.
13
14 Sliders
15
16 # Density per Sec :
17 How many grains to play per second
18 # Transpose :
19 Overall transposition, in cents, of the grains
20 # Grain Position :
21 Soundfile index
22 # Grain Duration :
23 Duration of each grain, in seconds
24 # Start Time Dev :
25 Maximum deviation of the starting time of the grain
26 # Panning Random :
27 Random added to the panning of each grain
28 # Density Random :
29 Jitter applied to the density per second
30 # Pitch Random :
31 Jitter applied on the pitch of the grains
32 # Position Random :
33 Jitter applied on the soundfile index
34 # Duration Random :
35 Jitter applied to the grain duration
36
37 Graph Only
38
39 # Overall Amplitude :
40 The amplitude curve applied on the total duration of the performance
41 # Grain Envelope :
42 Emplitude envelope of the grains
43
44 Popups & Toggles
45
46 # Balance :
47 Compression mode. Off, balanced with a fixed signal
48 or balanced with the input source.
49 # Discreet Transpo :
50 List of pitch ratios used to randomize grain's transposition
51 # Polyphony Voices :
52 Number of voices played simultaneously (polyphony),
53 only available at initialization time
54 # Polyphony Spread :
55 Pitch variation between voices (chorus),
56 only available at initialization time
57
58 """
59 def __init__(self):
60 BaseModule.__init__(self)
61 self.table = self.addFilein("sndtable")
62 self.densr = Randi(-self.dnsrnd, self.dnsrnd, freq=1, add=1)
63 self.posr = Noise(self.posrnd * self.table.getSize(False))
64 self.pitr = Noise(self.pitrnd, add=1)
65 self.durr = Noise(self.durrnd, add=1)
66 self.discr = Choice(choice=self.discreet_value, freq=1000)
67 self.pitch = CentsToTranspo(self.transp, mul=self.polyphony_spread)
68 self.pospos = Sig(self.pos, mul=self.table.getSize(False), add=self.posr)
69 initpan = [float(i) / (self.nchnls-1) for i in range(self.nchnls)]
70 self.panr = Noise(self.pan, add=initpan)
71 self.panw = Clip(self.panr, 0, 1)
72
73 self.gr = Particle(table=self.table,
74 env=self.grainenv,
75 dens=self.dens*self.densr,
76 pitch=self.pitch*self.pitr*self.discr,
77 pos=self.pospos,
78 dur=self.dur*self.durr,
79 dev=self.dev,
80 pan=self.panw,
81 chnls=self.nchnls,
82 mul=self.env*0.2
83 )
84
85 self.osc = Sine(10000,mul=.1)
86 self.balanced = Balance(self.gr, self.osc, freq=10)
87 self.out = Interp(self.gr, self.balanced)
88
89 #INIT
90 self.balance(self.balance_index, self.balance_value)
91
92 def balance(self, index, value):
93 if index == 0:
94 self.out.interp = 0
95 elif index ==1:
96 self.out.interp = 1
97 self.balanced.input2 = self.osc
98 elif index == 2:
99 self.out.interp = 1
100 self.balanced.input2 = self.gr
101
102 def discreet(self, value):
103 self.discr.choice = value
104
105 Interface = [ cfilein(name="sndtable", label="Audio"),
106 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
107 cgraph(name="grainenv", label="Grain Envelope", func=[(0,0),(0.5,1),(1,0)], table=True, curved=True, col="purple1"),
108
109 cslider(name="dens", label="Density per Sec", min=1, max=1000, init=100, rel="log", gliss=0, res="int", unit="x", col="blue1"),
110 cslider(name="transp", label="Transpose", min=-4800, max=4800, init=0, rel="lin", unit="cnts", col="red1"),
111 cslider(name="pos", label="Grain Position", min=0, max=1, init=0, func=[(0,0),(1,1)], rel="lin", unit="x", col="purple1"),
112 cslider(name="dur", label="Grain Duration", min=0.0001, max=1, init=0.1, rel="log", unit="sec", col="orange1"),
113 cslider(name="dev", label="Start Time Dev", min=0.0001, max=1, init=0.01, rel="log", unit="x", col="green1"),
114 cslider(name="pan", label="Panning Random", min=0, max=1, init=0, rel="lin", unit="x", col="green3"),
115
116 cslider(name="dnsrnd", label="Density Random", min=0.00001, max=1, init=0.001, rel="log", unit="x", col="blue2", half=True),
117 cslider(name="pitrnd", label="Pitch Random", min=0.00001, max=0.5, init=0.001, rel="log", unit="x", col="red2", half=True),
118 cslider(name="posrnd", label="Position Random", min=0.00001, max=0.5, init=0.001, rel="log", unit="x", col="purple2", half=True),
119 cslider(name="durrnd", label="Duration Random", min=0.00001, max=1, init=0.001, rel="log", unit="x", col="orange2", half=True),
120
121 cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Source"]),
122 cgen(name="discreet", label="Discreet Transpo", init=[1], col="red1"),
123 cpoly()
124 ]
125