Debian Codegraph @

Resources/modules/Dynamics/Degrade.c5

raw
1 class Module(BaseModule):
2 """
3 "Sampling rate and bit depth degradation with optional mirror clipping"
4
5 Description
6
7 This module allows the user to degrade a sound with artificial resampling
8 and quantization. This process emulates the artifacts caused by a poor
9 sampling frequency or bit depth resolution. It optionally offers a simple
10 mirror distortion, if the degradation is not enough!
11
12 Sliders
13
14 # Bit Depth :
15 Resolution of the amplitude in bits
16 # Sampling Rate Ratio :
17 Ratio of the new sampling rate compared to the original one
18 # Mirror Threshold :
19 Clipping limits between -1 and 1 (signal is reflected around the thresholds)
20 # Filter Freq :
21 Center frequency of the filter
22 # Filter Q :
23 Q factor of the filter
24 # Dry / Wet :
25 Mix between the original signal and the degraded signal
26
27 Graph Only
28
29 # Overall Amplitude :
30 The amplitude curve applied on the total duration of the performance
31
32 Popups & Toggles
33
34 # Filter Type :
35 Type of filter
36 # Balance :
37 Compression mode. Off, balanced with a fixed signal
38 or balanced with the input source.
39 # Polyphony Voices :
40 Number of voices played simultaneously (polyphony),
41 only available at initialization time
42 # Polyphony Chords :
43 Pitch interval between voices (chords),
44 only available at initialization time
45
46 """
47 def __init__(self):
48 BaseModule.__init__(self)
49 self.snd = self.addSampler("snd")
50 self.degr = Degrade(input=self.snd, bitdepth=self.bit, srscale=self.sr, mul=1)
51 self.wrap = Mirror(self.degr, self.clip*-1, self.clip)
52 self.biquad = Biquadx(self.wrap, freq=self.filter, q=self.filterq, type=self.filttype_index, stages=4, mul=0.7)
53 self.deg = Interp(self.snd, self.biquad, self.drywet, mul=self.env)
54
55 self.osc = Sine(10000,mul=.1)
56 self.balanced = Balance(self.deg, self.osc, freq=10)
57 self.out = Interp(self.deg, self.balanced)
58
59 #INIT
60 self.balance(self.balance_index, self.balance_value)
61
62 def balance(self,index,value):
63 if index == 0:
64 self.out.interp= 0
65 elif index == 1:
66 self.out.interp= 1
67 self.balanced.input2 = self.osc
68 elif index == 2:
69 self.out.interp = 1
70 self.balanced.input2 = self.snd
71
72 def filttype(self, index, value):
73 self.biquad.type = index
74
75 Interface = [ csampler(name="snd"),
76 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
77 cslider(name="bit", label="Bit Depth", min=1, max=32, init=8, rel="lin", unit="bit", col="purple1"),
78 cslider(name="sr", label="Sample Rate Ratio", min=0.01, max=1, init=0.25, rel="log", unit="x", col="purple2"),
79 cslider(name="clip", label="Mirror Threshold", min=0.01, max=1, init=0.8, rel="lin", unit="x", col="purple3"),
80 cslider(name="filter", label="Filter Freq", min=30, max=20000, init=15000, rel="log", unit="Hz", col="green1"),
81 cslider(name="filterq", label="Filter Q", min=0.5, max=10, init=0.707, rel="log", unit="Q", col="green2"),
82 cslider(name="drywet", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue1"),
83 cpopup(name="filttype", label="Filter Type", init="Lowpass", col="green1", value=["Lowpass","Highpass","Bandpass","Bandstop"]),
84 cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Source"]),
85 cpoly()
86 ]
87