Debian Codegraph @

Resources/modules/Time/Stutterer.c5

raw
1 import random
2
3 class Module(BaseModule):
4 """
5 "Stuttering an audio signal"
6
7 Description
8
9 This module reads successive segments extracted from a sound loaded in memory.
10 The start position of each segment is chosen according to a step factor given
11 in milliseconds.
12
13 Sliders
14
15 # Transpose :
16 Overall transposition, in cents, of the segments.
17 # Segment Duration :
18 Duration of the segments in ms.
19 # Start Pos Step :
20 Starting point offset (from previous start position) in ms.
21 # Crossfade Dur :
22 Crossfade duration as a percentage of the segment duration.
23 # Segment Dur Rand :
24 Amplitude of a random applied to the segment durations.
25 # Pos Step Rand :
26 Amplitude of a random applied to the starting point offset.
27 # Initial Start Pos :
28 The position in the sound memory for the first segment.
29
30 Graph Only
31
32 # Overall Amplitude :
33 The amplitude curve applied on the total duration of the performance
34
35 Popups & Toggles
36
37 # Loop Mode :
38 Sets the reading direction of the segments, either forward, backward or
39 back-and-forth.
40 # Polyphony Voices :
41 Number of voices played simultaneously (polyphony),
42 only available at initialization time
43 # Polyphony Spread :
44 Pitch variation between voices (chorus),
45 only available at initialization time
46
47 """
48 def __init__(self):
49 BaseModule.__init__(self)
50 self.table = self.addFilein("table")
51
52 self.tableDuration = self.table.getDur(False)
53
54 self.segmentStartPos = []
55 self.segmentDuration = []
56 self.reader = []
57 self.trigFunc = []
58 self.pitch = CentsToTranspo(self.transp, mul=self.polyphony_spread)
59 for i in range(self.number_of_voices):
60 self.segmentStartPos.append(Sig(self.tableDuration * self.initpos.get()))
61 self.segmentDuration.append(Sig(self.dur.get() * 0.001))
62 self.reader.append(Looper(self.table, pitch=self.pitch[i], start=self.segmentStartPos[-1], dur=self.segmentDuration[-1],
63 xfade=self.xfade, mode=self.loopmode_index, xfadeshape=1, startfromloop=True, interp=4, autosmooth=True))
64 self.reader[-1].appendFadeTime(True)
65 self.trigFunc.append(TrigFunc(self.reader[-1]["trig"], self.prepare, arg=i))
66
67 self.out = Mix(sum([read for read in self.reader]), voices=self.nchnls, mul=self.env*self.polyphony_scaling)
68
69 def prepare(self, voice=0):
70 durationRandom = random.uniform(-self.durrnd.get(), self.durrnd.get()) * 0.9
71 centralDuration = self.dur.get() * 0.001
72 centralDuration += centralDuration * durationRandom
73 self.segmentDuration[voice].value = centralDuration
74
75 stepRandom = random.uniform(-self.steprnd.get(), self.steprnd.get()) * 0.9
76 step = self.step.get() * 0.001
77 step += step * stepRandom
78 newStartPos = self.segmentStartPos[voice].value + step
79 if newStartPos < 0:
80 newStartPos = self.tableDuration - self.dur.get() * 0.001
81 elif newStartPos > self.tableDuration - centralDuration:
82 newStartPos = 0
83 self.segmentStartPos[voice].value = newStartPos
84
85 def loopmode(self, index, value):
86 [read.setMode(index+1) for read in self.reader]
87
88 Interface = [
89 cfilein(name="table"),
90 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
91 cslider(name="transp", label="Transpose", min=-1200, max=1200, init=0, rel="lin", unit="cnts", col="red1"),
92 cslider(name="dur", label="Segment Duration", min=10, max=500, init=200, unit="ms", col="green1"),
93 cslider(name="step", label="Start Pos Step", min=-250.0, max=250.0, init=5, unit="ms", col="purple1"),
94 cslider(name="xfade", label="Crossfade Dur", min=0, max=50, init=5, unit="%", col="orange2"),
95 cslider(name="durrnd", label="Segment Dur Rand", min=0, max=1, init=0, unit="x", half=True, col="green2"),
96 cslider(name="steprnd", label="Pos Step Rand", min=0, max=1, init=0.01, unit="x", half=True, col="purple2"),
97 cslider(name="initpos", label="Initial Start Pos", min=0.0, max=1.0, init=0, unit="%", col="grey"),
98 cpopup(name="loopmode", label = "Loop Mode", init= "Forward", value=["Forward","Backward", "Two Ways"], col="green1"),
99 cpoly()
100 ]