Debian Codegraph @

Resources/modules/Spectral/BinModulator.c5

raw
1 class Module(BaseModule):
2 """
3 "Frequency independent amplitude and frequency modulations"
4
5 Description
6
7 This module modulates both the amplitude and the frequency of
8 each bin from a phase vocoder analysis with an independent
9 oscillator. Power series are used to compute modulating
10 oscillator frequencies.
11
12 Sliders
13
14 # AM Base Freq :
15 Base amplitude modulation frequency, in Hertz.
16 # AM Spread :
17 Spreading factor for AM oscillator frequencies. 0 means every
18 oscillator has the same frequency.
19 # FM Base Freq :
20 Base frequency modulation frequency, in Hertz.
21 # FM Spread :
22 Spreading factor for FM oscillator frequencies. 0 means every
23 oscillator has the same frequency.
24 # FM Depth :
25 Amplitude of the modulating oscillators.
26 # Dry / Wet :
27 Mix between the original signal and the delayed signals
28
29 Graph Only
30
31 # Overall Amplitude :
32 The amplitude curve applied on the total duration of the performance
33
34 Popups & Toggles
35
36 # Reset :
37 On mouse down, this button reset the phase of all
38 bin's oscillators to 0.
39 # Routing :
40 Path of the sound
41 # AM Shape :
42 Waveform of the amplitude modulators. Possible shapes are:
43 Sine, Sawtooth, Ramp, Square, Triangle, Brown Noise, Pink Noise, White Noise
44 # FM Shape :
45 Waveform of the frequency modulators. Possible shapes are:
46 Sine, Sawtooth, Ramp, Square, Triangle, Brown Noise, Pink Noise, White Noise
47 # FFT Size :
48 Size, in samples, of the FFT
49 # FFT Envelope :
50 Windowing shape of the FFT
51 # FFT Overlaps :
52 Number of FFT overlaping analysis
53 # Polyphony Voices :
54 Number of voices played simultaneously (polyphony),
55 only available at initialization time
56 # Polyphony Spread :
57 Pitch variation between voices (chorus),
58 only available at initialization time
59
60 """
61 def __init__(self):
62 BaseModule.__init__(self)
63 self.snd = self.addSampler("snd")
64
65 size = int(self.fftsize_value)
66 olaps = int(self.overlaps_value)
67 wintype = self.wtype_index
68 self.oneOverSr = 1.0 / self.sr
69 routing = self.routing_index
70
71 self.delsrc = Delay(self.snd, delay=size*self.oneOverSr)
72
73 self.fin = PVAnal(self.snd, size=size, overlaps=olaps, wintype=wintype)
74
75 self.tr1 = PVAmpMod(self.fin, basefreq=self.amfreq, spread=self.amspread,
76 shape=self.ampmodshape_index)
77 self.tr2 = PVFreqMod(self.tr1, basefreq=self.fmfreq, spread=self.fmspread,
78 depth=self.fmdepth, shape=self.freqmodshape_index)
79
80 self.fout = PVSynth(self.tr2, wintype=wintype)
81
82 self.fade = SigTo(value=1, time=.05, init=1)
83 self.out = Interp(self.delsrc*0.5, self.fout*0.4, self.mix, mul=self.fade*self.env)
84
85 self.setRouting(routing)
86
87 def setRouting(self, x):
88 if x == 0:
89 self.tr1.input = self.fin
90 self.fout.input = self.tr1
91 self.tr1.play()
92 self.tr2.stop()
93 elif x == 1:
94 self.tr2.input = self.fin
95 self.fout.input = self.tr2
96 self.tr1.stop()
97 self.tr2.play()
98 else:
99 self.tr1.input = self.fin
100 self.tr2.input = self.tr1
101 self.fout.input = self.tr2
102 self.tr1.play()
103 self.tr2.play()
104
105 def routing(self, index, value):
106 self.setRouting(index)
107
108 def ampmodshape(self, index, value):
109 self.tr1.shape = index
110
111 def freqmodshape(self, index, value):
112 self.tr2.shape = index
113
114 def reset(self, value):
115 if value:
116 if self.tr1.isPlaying():
117 self.tr1.reset()
118 if self.tr2.isPlaying():
119 self.tr2.reset()
120
121 def fftsize(self, index, value):
122 newsize = int(value)
123 self.fade.value = 0
124 time.sleep(.05)
125 self.delsrc.delay = newsize*self.oneOverSr
126 self.fin.size = newsize
127 time.sleep(.05)
128 self.fade.value = 1
129
130 def overlaps(self, index, value):
131 olaps = int(value)
132 self.fade.value = 0
133 time.sleep(.05)
134 self.fin.overlaps = olaps
135 time.sleep(.05)
136 self.fade.value = 1
137
138 def wtype(self, index, value):
139 self.fin.wintype = index
140 self.fout.wintype = index
141
142 Interface = [ csampler(name="snd"),
143 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
144 cslider(name="amfreq", label="AM Base Freq", min=0.0001, max=100, init=4, rel="log", unit="Hz", col="green1"),
145 cslider(name="amspread", label="AM Spread", min=-1, max=1, init=0.5, rel="lin", unit="x", col="green2"),
146 cslider(name="fmfreq", label="FM Base Freq", min=0.0001, max=100, init=2, rel="log", unit="Hz", col="orange1"),
147 cslider(name="fmspread", label="FM Spread", min=-1, max=1, init=0.1, rel="lin", unit="x", col="orange2"),
148 cslider(name="fmdepth", label="FM Depth", min=0, max=1, init=0.1, rel="lin", unit="x", col="orange3"),
149 cslider(name="mix", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue"),
150 cbutton(name="reset", label="Reset", col="blue2"),
151 cpopup(name="routing", label="Routing", init="Amp Only", value=["Amp Only", "Freq Only", "Amp -> Freq"], col="blue2"),
152 cpopup(name="ampmodshape", label="AM Shape", init="Sine",
153 value=["Sine", "Sawtooth", "Ramp", "Square", "Triangle", "Brown Noise", "Pink Noise", "White Noise"], col="green1"),
154 cpopup(name="freqmodshape", label="FM Shape", init="Sine",
155 value=["Sine", "Sawtooth", "Ramp", "Square", "Triangle", "Brown Noise", "Pink Noise", "White Noise"], col="orange1"),
156 cpopup(name="fftsize", label="FFT Size", init="1024", value=["16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"], col="red"),
157 cpopup(name="wtype", label="FFT Envelope", init="Hanning", col="red", value=["Rectangular", "Hamming", "Hanning", "Bartlett",
158 "Blackman 3", "Blackman 4", "Blackman 7", "Tuckey", "Sine"]),
159 cpopup(name="overlaps", label="FFT Overlaps", init="4", col="red", value=["1", "2", "4", "8", "16"]),
160 cpoly()
161 ]
162