Debian Codegraph @

Resources/modules/Synthesis/Pulsar.c5

raw
1 import random
2 class Module(BaseModule):
3 """
4 "Pulsar synthesis module"
5
6 Description
7
8 This module implements the classic pulsar synthesis.
9
10 Sliders
11
12 # Base Frequency :
13 Base pitch of the synthesis
14 # Pulsar Width :
15 Amount of silence added to one period
16 # Detune Factor :
17 Amount of jitter applied to the pitch
18 # Detune Speed :
19 Speed of the jitter applied to the pitch
20
21 Graph Only
22
23 # Overall Amplitude :
24 The amplitude curve applied on the total duration of the performance
25
26 Popups & Toggles
27
28 # Wave Shape :
29 Shape used for the synthesis
30 # Custom Wave :
31 Define a custom wave shape by entering amplitude values
32 # Window Type :
33 Pulsar envelope
34
35 """
36 def __init__(self):
37 BaseModule.__init__(self)
38 self.customtable = self.custom_value
39 self.wavetable = HarmTable(size=8192)
40 self.wind = WinTable(type=self.wtype_index, size=8192)
41 self.rnd1 = Randi(min=1-self.detune, max=1+self.detune, freq=self.detunesp)
42 self.rnd2 = Randi(min=1-self.detune, max=1+self.detune, freq=self.detunesp)
43 self.polyfreqs = self.polyphony_spread
44 self.ply1 = [self.bfreq*i*self.rnd1 for i in self.polyfreqs]
45 self.ply2 = [self.bfreq*i*self.rnd2 for i in self.polyfreqs]
46 self.ply3 = [self.bfreq*i for i in self.polyfreqs for j in range(self.nchnls)]
47 self.pfreqs = self.ply3+self.ply1+self.ply2
48 self.pul = Pulsar(self.wavetable, self.wind, freq=self.pfreqs, frac=self.width,
49 phase=0, interp=4, mul=0.1*self.polyphony_scaling*self.env)
50 self.out = Mix(self.pul, voices=self.nchnls)
51
52 #INIT
53 self.wavedict = {'Sine':[1], 'Sawtooth':[1, 0.5, 0.333, 0.25, 0.2, 0.167, 0.143, 0.111, 0.1], 'Square':[1, 0, 0.333, 0, 0.2, 0, 0.143, 0, 0.111],
54 'Complex1':[1, 0, 0, 0, 0.3, 0, 0, 0, 0.2, 0, 0, 0.05], 'Complex2':[1, 0, 0, 0.3, 0, 0, 0.2, 0, 0, 0, 0, 0.1, 0, 0, 0.05, 0, 0, 0.02],
55 'Complex3':[1, 0, 0, 0.2, 0, 0.1, 0, 0, 0, 0.3, 0, 0.1, 0, 0, 0.05, 0, 0, 0.1, 0, 0.05, 0, 0, 0, 0.05, 0, 0, 0.02],
56 'Custom':self.customtable}
57
58 self.shape(self.shape_index, self.shape_value)
59
60 def shape(self, index, value):
61 self.wavetable.replace(self.wavedict[value])
62
63 def custom(self, value):
64 self.wavedict['Custom'] = value
65
66 def wtype(self, index, value):
67 self.wind.type = index
68
69 Interface = [ cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
70 cslider(name="bfreq", label="Base Frequency", min=0.1, max=1000, init=100, rel="log", unit="Hz", col="blue"),
71 cslider(name="width", label="Pulsar Width", min=0.01, max=1, init=0.5, rel="lin", unit="x", col="green4"),
72 cslider(name="detune", label="Detune Factor", min=0.0001, max=0.999, init=0.005, rel="log", unit="x", col="red"),
73 cslider(name="detunesp", label="Detune Speed", min=0.0001, max=100, init=0.3, rel="log", unit="Hz", col="red"),
74 cpopup(name="wtype", label="Window Type", init="Tuckey", col="orange4", value=["Rectangular", "Hamming", "Hanning",
75 "Bartlett", "Blackman 3", "Blackman 4", "Blackman 7", "Tuckey", "Sine"]),
76 cpopup(name="shape", label="Wave Shape", init="Sine", col="green", value=["Sine","Sawtooth","Square","Complex1", "Complex2", "Complex3", "Custom"]),
77 cgen(name="custom", label="Custom Wave", init=[1,0,0.5,0.3,0,0,0.2,0,0.1,0,0.09,0,0.05], popup=("shape", 6), col="green2"),
78 cpoly()
79 ]
80