import random class Module(BaseModule): """ "Another granulation module" Description A granulation module where the number of grains (density) and the grain duration can be set independently. Useful to stretch a sound without changing the pitch or to transposition without changing the duration. Sliders # Transpose : Base pitch of the grains # Density of grains : Number of grains per second # Grain Position : Grain start position in the position # Grain Duration : Duration of the grain in seconds # Pitch Random : Jitter applied on the pitch of the grains # Density Random : Jitter applied on the density # Position Random : Jitter applied on the grain start position # Duration Random : Jitter applied on the duration of the grain # Filter Freq : Cutoff or center frequency of the filter (post-processing) # Filter Q : Q of the filter Graph Only # Overall Amplitude : The amplitude curve applied on the total duration of the performance # Grain Envelope : Emplitude envelope of the grains Popups & Toggles # Filter Type : Type of the post filter # Balance : Compression mode. Off, balanced with a fixed signal or balanced with the input source. # Discreet Transpo : List of pitch ratios # Polyphony Voices : Number of voices played simultaneously (polyphony), only available at initialization time # Polyphony Spread : Pitch variation between voices (chorus), only available at initialization time """ def __init__(self): BaseModule.__init__(self) pitrnds = self.polyphony_spread * self.nchnls self.t = self.addFilein("sndtable") self.drng = self.densrnd*self.dens self.densr = Randi(-self.drng, self.drng, freq=.2, add=self.dens) self.posr = Noise(self.posrnd*self.t.getSize(False)) self.pitr = Noise(self.pitrnd, add=pitrnds) self.discr = Choice(choice=self.discreet_value, freq=1000) self.pitch = CentsToTranspo(self.transp, mul=self.pitr) self.pospos = Sig(self.pos, mul=self.t.getSize(False), add=self.posr) self.durr = Noise(self.durrnd*self.dur, add=self.dur) 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) self.gro = Biquadx(self.gr, freq=self.cut, q=self.filterq, type=self.filttype_index, stages=2, mul=self.polyphony_scaling) self.osc = Sine(10000,mul=.1) self.balanced = Balance(self.gro, self.osc, freq=10) self.out = Interp(self.gro, self.balanced) #INIT self.balance(self.balance_index, self.balance_value) def balance(self,index,value): if index == 0: self.out.interp = 0 elif index ==1: self.out.interp = 1 self.balanced.input2 = self.osc elif index == 2: self.out.interp = 1 self.balanced.input2 = self.gr def filttype(self, index, value): self.gro.type = index def discreet(self, value): self.discr.choice = value Interface = [ cfilein(name="sndtable", label="Audio"), cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"), cgraph(name="grainenv", label="Grain Envelope", func=[(0,0),(0.5,1),(1,0)], table=True, curved=True, col="purple1"), cslider(name="transp", label="Transpose", min=-4800, max=4800, init=0, rel="lin", unit="cnts", col="red1"), cslider(name="dens", label="Density of grains", min=1, max=250, init=30, rel="log", unit="x", col="purple1"), cslider(name="pos", label="Grain Position", min=0, max=1, init=0, func=[(0,0),(1,1)], rel="lin", unit="x", col="blue1"), cslider(name="dur", label="Grain Duration", min=0.001, max=10, init=0.2, rel="log", unit="sec", col="orange1"), cslider(name="pitrnd", label="Pitch Random", min=0.0001, max=0.5, init=0.0005, rel="log", unit="x", col="red2",half=True), cslider(name="densrnd", label="Density Random", min=0.0001, max=1, init=0.0005, rel="log", unit="x", col="purple2",half=True), cslider(name="posrnd", label="Position Random", min=0.0001, max=0.5, init=0.0005, rel="log", unit="x", col="blue2",half=True), cslider(name="durrnd", label="Duration Random", min=0.0001, max=1, init=0.0005, rel="log", unit="x", col="orange2",half=True), cslider(name="cut", label="Filter Freq", min=100, max=18000, init=20000, rel="log", unit="Hz", col="green1"), cslider(name="filterq", label="Filter Q", min=0.5, max=10, init=0.707, rel="log", unit="Q", col="green2"), cpopup(name="filttype", label="Filter Type", init="Lowpass", col="green1", value=["Lowpass","Highpass","Bandpass","Bandstop"]), cpopup(name="balance", label = "Balance", init= "Off", col="blue1", value=["Off","Compress", "Source"]), cgen(name="discreet", label="Discreet Transpo", init=[1], col="red1"), cpoly() ]