Debian Codegraph @

Resources/modules/Filters/Vocoder.c5

raw
1 class Module(BaseModule):
2 """
3 "Time domain vocoder effect"
4
5 Description
6
7 Applies the spectral envelope of a first sound to the spectrum of a second sound.
8
9 The vocoder is an analysis/synthesis system, historically used to reproduce
10 human speech. In the encoder, the first input (spectral envelope) is passed
11 through a multiband filter, each band is passed through an envelope follower,
12 and the control signals from the envelope followers are communicated to the
13 decoder. The decoder applies these (amplitude) control signals to corresponding
14 filters modifying the second source (exciter).
15
16 Sliders
17
18 # Base Frequency :
19 Center frequency of the first band. This is the base
20 frequency used tocompute the upper bands.
21 # Frequency Spread :
22 Spreading factor for upper band frequencies. Each band is
23 `freq * pow(order, spread)`, where order is the harmonic rank of the band.
24 # Q Factor :
25 Q of the filters as `center frequency / bandwidth`. Higher values
26 imply more resonance around the center frequency.
27 # Time Response :
28 Time response of the envelope follower. Lower values mean smoother changes,
29 while higher values mean a better time accuracy.
30 # Gain :
31 Output gain of the process in dB.
32 # Num of Bands :
33 The number of bands in the filter bank. Defines the number of notches in
34 the spectrum.
35
36 Graph Only
37
38 # Overall Amplitude :
39 The amplitude curve applied on the total duration of the performance
40
41 Popups & Toggles
42
43 # Balance :
44 Compression mode. Off, balanced with a fixed signal
45 or balanced with the input source.
46 # Polyphony Voices :
47 Number of voices played simultaneously (polyphony),
48 only available at initialization time
49 # Polyphony Spread :
50 Pitch variation between voices (chorus),
51 only available at initialization time
52
53 """
54 def __init__(self):
55 BaseModule.__init__(self)
56 self.spec = self.addSampler("spec")
57 self.exci = self.addSampler("exci")
58 self.proc = Vocoder(self.spec, self.exci, freq=self.freq, spread=self.spread,
59 q=self.q, slope=self.slope, stages=int(self.stages.get()), mul=DBToA(self.gain))
60 self.deg = Mix(self.proc, voices=self.nchnls, mul=self.env)
61
62 self.osc = Sine(10000,mul=.1)
63 self.balanced = Balance(self.deg, self.osc, freq=10)
64 self.out = Interp(self.deg, self.balanced)
65
66 #INIT
67 self.balance(self.balance_index, self.balance_value)
68
69 def balance(self,index,value):
70 if index == 0:
71 self.out.interp= 0
72 elif index ==1:
73 self.out.interp= 1
74 self.balanced.input2 = self.osc
75 elif index == 2:
76 self.out.interp = 1
77 self.balanced.input2 = self.spec
78 else:
79 self.out.interp = 1
80 self.balanced.input2 = self.exci
81
82 def stages_up(self, value):
83 self.proc.stages = int(value)
84
85 Interface = [
86 csampler(name="spec", label="Spectral Envelope"),
87 csampler(name="exci", label="Exciter"),
88 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
89 cslider(name="freq", label="Base Frequency", min=10, max=1000, init=80, rel="log", unit="Hz", col="green1"),
90 cslider(name="spread", label="Frequency Spread", min=0.25, max=2, init=1.25, rel="log", unit="x", col="green2"),
91 cslider(name="q", label="Q Factor", min=0.5, max=200, init=20, rel="log", unit="Q", col="green3"),
92 cslider(name="slope", label="Time Response", min=0, max=1, init=0.5, rel="lin", unit="x", col="orange1"),
93 cslider(name="gain", label="Gain", min=-90, max=18, init=0, rel="lin", unit="dB", col="purple1"),
94 cslider(name="stages", label="Num of bands", min=4, max=64, init=20, rel="lin", res="int", unit="x", up=True),
95 cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Spectral", "Exciter"]),
96 cpoly()
97 ]
98