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