| 1 |
import random |
| 2 |
class Module(BaseModule): |
| 3 |
""" |
| 4 |
"Granulation module" |
| 5 |
|
| 6 |
Description |
| 7 |
|
| 8 |
A classic granulation module. Useful to stretch a sound without changing |
| 9 |
the pitch or to transpose without changing the duration. |
| 10 |
|
| 11 |
Sliders |
| 12 |
|
| 13 |
# Transpose : |
| 14 |
Base pitch of the grains |
| 15 |
# Grain Position : |
| 16 |
Soundfile index |
| 17 |
# Position Random : |
| 18 |
Jitter applied on the soundfile index |
| 19 |
# Pitch Random : |
| 20 |
Jitter applied on the pitch of the grains using the discreet transpo list |
| 21 |
# Grain Duration : |
| 22 |
Length of the grains |
| 23 |
# Num of Grains : |
| 24 |
Number of overlapping grains |
| 25 |
|
| 26 |
Graph Only |
| 27 |
|
| 28 |
# Overall Amplitude : |
| 29 |
The amplitude curve applied on the total duration of the performance |
| 30 |
# Grain Envelope : |
| 31 |
Emplitude envelope of the grains |
| 32 |
|
| 33 |
Popups & Toggles |
| 34 |
|
| 35 |
# Filter Type : |
| 36 |
Type of the post filter |
| 37 |
# Discreet Transpo : |
| 38 |
List of pitch ratios |
| 39 |
# Balance : |
| 40 |
Compression mode. Off, balanced with a fixed signal |
| 41 |
or balanced with the input source. |
| 42 |
# Polyphony Voices : |
| 43 |
Number of voices played simultaneously (polyphony), |
| 44 |
only available at initialization time |
| 45 |
# Polyphony Spread : |
| 46 |
Pitch variation between voices (chorus), |
| 47 |
only available at initialization time |
| 48 |
|
| 49 |
""" |
| 50 |
def __init__(self): |
| 51 |
BaseModule.__init__(self) |
| 52 |
self.amp_scl = Map(350, 1, "lin") |
| 53 |
firstamp = self.amp_scl.set(self.num.get()) |
| 54 |
pitrnds = self.polyphony_spread |
| 55 |
self.table = self.addFilein("sndtable") |
| 56 |
self.posr = Noise(self.posrnd*self.table.getSize(False)) |
| 57 |
self.pitr = Noise(self.pitrnd, add=1) |
| 58 |
self.discr = Choice(choice=self.discreet_value, freq=1000) |
| 59 |
self.pitch = CentsToTranspo(self.transp, mul=pitrnds) |
| 60 |
self.pospos = Sig(self.pos, mul=self.table.getSize(False), add=self.posr) |
| 61 |
self.gr = Granulator(self.table, self.grainenv, pitch=self.pitch, pos=self.pospos, |
| 62 |
dur=self.dur.get()*self.pitr*self.discr, grains=int(self.num.get()), |
| 63 |
basedur=self.dur.get(), mul=self.env* 0.1 * firstamp) |
| 64 |
self.gro = Biquadx(self.gr.mix(self.nchnls), freq=self.cut, q=self.filterq, type=self.filttype_index, stages=2, mul=self.polyphony_scaling) |
| 65 |
|
| 66 |
self.osc = Sine(10000,mul=.1) |
| 67 |
self.balanced = Balance(self.gro, self.osc, freq=10) |
| 68 |
self.out = Interp(self.gro, self.balanced) |
| 69 |
|
| 70 |
#INIT |
| 71 |
self.balance(self.balance_index, self.balance_value) |
| 72 |
|
| 73 |
def balance(self, index, value): |
| 74 |
if index == 0: |
| 75 |
self.out.interp = 0 |
| 76 |
elif index ==1: |
| 77 |
self.out.interp = 1 |
| 78 |
self.balanced.input2 = self.osc |
| 79 |
elif index == 2: |
| 80 |
self.out.interp = 1 |
| 81 |
self.balanced.input2 = self.gr |
| 82 |
|
| 83 |
def filttype(self, index, value): |
| 84 |
self.gro.type = index |
| 85 |
|
| 86 |
def dur_up(self, value): |
| 87 |
self.gr.basedur = value |
| 88 |
self.gr.dur = value * self.pitr * self.discr |
| 89 |
|
| 90 |
def num_up(self, value): |
| 91 |
gr = int(value) |
| 92 |
self.gr.grains = gr |
| 93 |
self.gr.mul = self.env * 0.1 * self.amp_scl.set(gr) |
| 94 |
|
| 95 |
def discreet(self, value): |
| 96 |
self.discr.choice = value |
| 97 |
|
| 98 |
Interface = [ cfilein(name="sndtable", label="Audio"), |
| 99 |
cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"), |
| 100 |
cgraph(name="grainenv", label="Grain Envelope", func=[(0,0),(0.5,1),(1,0)], table=True, curved=True, col="purple1"), |
| 101 |
cslider(name="transp", label="Transpose", min=-4800, max=4800, init=0, rel="lin", unit="cnts", col="red1"), |
| 102 |
cslider(name="pos", label="Grain Position", min=0, max=1, init=0, func=[(0,0),(1,1)], rel="lin", unit="x", col="purple1"), |
| 103 |
cslider(name="posrnd", label="Position Random", min=0.00001, max=0.5, init=0.001, rel="log", unit="x", col="orange2", half=True), |
| 104 |
cslider(name="pitrnd", label="Pitch Random", min=0.00001, max=0.5, init=0.001, rel="log", unit="x", col="orange3", half=True), |
| 105 |
cslider(name="cut", label="Filter Freq", min=100, max=18000, init=20000, rel="log", unit="Hz", col="green1"), |
| 106 |
cslider(name="filterq", label="Filter Q", min=0.5, max=10, init=0.707, rel="log", unit="Q", col="green2"), |
| 107 |
cslider(name="dur", label="Grain Duration", min=0.01, max=10, init=0.1, up=True, rel="log", unit="sec", half=True), |
| 108 |
cslider(name="num", label="Num of Grains", min=1, max=256, init=32, rel="lin", gliss=0, res="int", up=True, unit="grs", half=True), |
| 109 |
cpopup(name="filttype", label="Filter Type", init="Lowpass", col="green1", value=["Lowpass","Highpass","Bandpass","Bandstop"]), |
| 110 |
cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Source"]), |
| 111 |
cgen(name="discreet", label="Discreet Transpo", init=[1], col="red1"), |
| 112 |
cpoly() |
| 113 |
] |
| 114 |
|