Debian Codegraph @

Resources/modules/Pitch/RandomAccumulator.c5

raw
1 class Module(BaseModule):
2 """
3 "Variable speed recording accumulator module"
4
5 Description
6
7 This module records the sound from the sampler in a table at a varying
8 position and speed. The feedback parameter indicates how much of the
9 previous recording at the current position is kept back in the table.
10 The recorded table is read in loop at the normal speed, with possibility
11 to activate a 180 degrees out-of-phase overlap.
12
13 Sliders
14
15 # Pre-Filter Freq :
16 Center frequency of the filter applied before the recording
17 # Pre-Filter Q :
18 Q factor of the filter applied before the recording
19 # Accum Feedback :
20 The amount of previous signal in the table that is kept back,
21 mixed with the new recording.
22 # Record Time Rand :
23 The time it took to the recording head to reach the new position
24 target in the table. The target is chosen randomly between 0 and
25 the end of the table. If the time is longer than the distance to
26 run, the signal will be write slowly, so the playback (at regular
27 speed) will give an upward transposition. When the target is reached,
28 a new target and a new recording duration are chosen.
29 # Buffer Length :
30 The size of the table in seconds. This parameter is updated only
31 at the start of the performance.
32 # Global Seed :
33 Root of stochatic generators. If 0, a new value is chosen randomly each
34 time the performance starts. Otherwise, the same root is used every
35 performance, making the generated sequences the same every time.
36
37 Graph Only
38
39 # Overall Amplitude :
40 The amplitude curve applied on the total duration of the performance
41 # Recording Envelope :
42 The envelope applied to each recording segment
43
44 Popups & Toggles
45
46 # Pre-Filter Type :
47 Type of filter used before the recording
48 # Overlapped :
49 If "On", a second player, 180 degrees out-of-phase, will read the
50 recorded buffer. The signals of both players are summed and sent to
51 the output
52 # Polyphony Voices :
53 Number of voices played simultaneously (polyphony),
54 only available at initialization time
55 # Polyphony Spread :
56 Pitch variation between voices (chorus),
57 only available at initialization time
58
59 """
60 def __init__(self):
61 BaseModule.__init__(self)
62 self.setGlobalSeed(int(self.seed.get()))
63
64 duration = self.buflen.get()
65
66 self.snd = self.addSampler("snd")
67 self.snd_filt = Biquadx(self.snd, freq=self.prefiltf, q=self.prefiltq,
68 type=self.prefilttype_index, stages=2, mul=0.25)
69
70 self.table = NewTable(length=duration, chnls=self.nchnls, feedback=self.feed.get())
71
72 self.dur = RandDur(min=self.min_max[0], max=self.min_max[1])
73 self.trig = Change(self.dur)
74 self.amp = TrigEnv(self.trig, table=self.envelope, dur=self.dur)
75 self.po = TrigRand(self.trig, 0, duration*self.sr)
76 self.pos = SigTo(self.po, self.dur)
77 self.tw = TableWrite(self.snd_filt*self.amp, self.pos, self.table, 1)
78
79 self.tf = TrigFunc(self.trig, self.setFeed)
80
81 self.olapgain = SigTo(self.overlapped_index, time=0.05)
82 self.play1 = Osc(self.table, freq=1.0/duration)
83 self.play2 = Osc(self.table, freq=1.0/duration, phase=0.5, mul=self.olapgain)
84
85 self.out = (self.play1 + self.play2) * self.env
86
87 def setFeed(self):
88 self.table.feedback = self.feed.get()
89
90 def prefilttype(self, index, value):
91 self.snd_filt.type = index
92
93 def overlapped(self, index, value):
94 self.olapgain.value = index
95
96 Interface = [
97 csampler(name="snd"),
98 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
99 cgraph(name="envelope", label="Recording Envelope", func=[(0,0),(0.15,1),(0.85,1),(1,0)], table=True, curved=True, col="purple1"),
100 cslider(name="prefiltf", label="Pre-Filter Freq", min=100, max=18000, init=15000, rel="log", unit="Hz", col="green1"),
101 cslider(name="prefiltq", label="Pre-Filter Q", min=.5, max=10, init=0.707, rel="log", col="green2"),
102 cslider(name="feed", label="Accum Feedback", min=0, max=1, init=0.5, rel="lin", col="purple1"),
103 crange(name="min_max", label="Record Time Rand", min=0.5, max=10, init=[1,2], rel="log", unit="sec", col="orange1"),
104 cslider(name="buflen", label="Buffer Length", min=1, max=10, init=4, rel="lin", unit="sec", up=True),
105 cslider(name="seed", label="Global Seed", min=0, max=5000, init=0, rel="lin", res="int", unit="x", up=True),
106 cpopup(name="prefilttype", label="Pre-Filter Type", init="Lowpass", col="green1", value=["Lowpass","Highpass","Bandpass","Bandstop"]),
107 cpopup(name="overlapped", label="Overlapped", init="Off", col="purple2", value=["Off","On"]),
108 cpoly()
109 ]