Debian Codegraph @

Resources/modules/Spectral/Shifter.c5

raw
1 class Module(BaseModule):
2 """
3 "Phase Vocoder based frequency shifters"
4
5 Description
6
7 This module implements two voices that linearly moves the analysis bins
8 by the amount, in Hertz, specified by the the `Shift 1` and `Shift 2`
9 parameters.
10
11 Sliders
12
13 # Shift 1 :
14 Shifting, in Hertz, of the first voice
15 # Shift 2 :
16 Shifting, in Hertz, of the second voice
17 # Dry / Wet :
18 Mix between the original signal and the delayed signals
19
20 Popups & Toggles
21
22 # FFT Size :
23 Size, in samples, of the FFT
24 # FFT Envelope :
25 Windowing shape of the FFT
26 # FFT Overlaps :
27 Number of FFT overlaping analysis
28 # Polyphony Voices :
29 Number of voices played simultaneously (polyphony),
30 only available at initialization time
31 # Polyphony Spread :
32 Pitch variation between voices (chorus),
33 only available at initialization time
34
35 """
36 def __init__(self):
37 BaseModule.__init__(self)
38 self.snd = self.addSampler("snd")
39
40 size = int(self.fftsize_value)
41 olaps = int(self.overlaps_value)
42 wintype = self.wtype_index
43 self.oneOverSr = 1.0 / self.sr
44
45 self.delsrc = Delay(self.snd, delay=size*self.oneOverSr)
46
47 self.fin = PVAnal(self.snd, size=size, overlaps=olaps, wintype=wintype)
48 self.tr1 = PVShift(self.fin, shift=self.shift1)
49 self.tr2 = PVShift(self.fin, shift=self.shift2)
50 self.fout1 = PVSynth(self.tr1, wintype=wintype)
51 self.fout2 = PVSynth(self.tr2, wintype=wintype)
52 self.fout = self.fout1 + self.fout2
53 self.fade = SigTo(value=1, time=.05, init=1)
54 self.out = Interp(self.delsrc*0.5, self.fout*0.4, self.mix, mul=self.fade*self.env)
55
56 def fftsize(self, index, value):
57 newsize = int(value)
58 self.fade.value = 0
59 time.sleep(.05)
60 self.delsrc.delay = newsize*self.oneOverSr
61 self.fin.size = newsize
62 time.sleep(.05)
63 self.fade.value = 1
64
65 def overlaps(self, index, value):
66 olaps = int(value)
67 self.fade.value = 0
68 time.sleep(.05)
69 self.fin.overlaps = olaps
70 time.sleep(.05)
71 self.fade.value = 1
72
73 def wtype(self, index, value):
74 self.fin.wintype = index
75 self.fout.wintype = index
76
77 Interface = [ csampler(name="snd"),
78 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
79 cslider(name="shift1", label="Shift 1", min=-8000, max=8000, init=250, rel="lin", unit="Hz", col="green1"),
80 cslider(name="shift2", label="Shift 2", min=-8000, max=8000, init=500, rel="lin", unit="Hz", col="green2"),
81 cslider(name="mix", label="Dry / Wet", min=0, max=1, init=0.5, rel="lin", unit="x", col="blue"),
82 cpopup(name="fftsize", label="FFT Size", init="1024", value=["16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192"], col="red"),
83 cpopup(name="wtype", label="FFT Envelope", init="Hanning", col="red", value=["Rectangular", "Hamming", "Hanning", "Bartlett",
84 "Blackman 3", "Blackman 4", "Blackman 7", "Tuckey", "Sine"]),
85 cpopup(name="overlaps", label="FFT Overlaps", init="4", col="red", value=["1", "2", "4", "8", "16"]),
86 cpoly()
87 ]
88