def play(voice_id): bpm = config('bpm') beat = dsp.bpm2frames(bpm) root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) bar = beat * dsp.randchoose([8, 16, 32]) groot = tune.ntf('c') scale = tune.fromdegrees([1,3,5,6,8,9], root=root, octave=2, ratios=ratios) v = dsp.read('sounds/vibesc1.wav').data out = '' # lens = [ bar / 5, bar / 8, bar / 12 ] lens = [ bar / 6, bar / 8, bar / 16 ] maxbend = 2 maxbend = 0.02 layers = [] for nlen in lens: layer = '' nlen /= 2 note = dsp.transpose(v, (dsp.randchoose(scale) * 2**dsp.randint(0, 3)) / groot) note = dsp.fill(note, nlen) note = dsp.env(note, 'phasor') note = dsp.amp(note, 0.125) nbeats = bar / nlen for b in range(nbeats): b = dsp.pan(note, dsp.rand()) b = dsp.drift(b, dsp.rand(0, dsp.rand(0.01, maxbend))) if dsp.flen(b) < nlen: b = dsp.pad(b, 0, nlen - dsp.flen(b)) # if dsp.rand() > 0.5: # b = dsp.vsplit(b, dsp.flen(b) / 3, dsp.flen(b) / 2) # b = dsp.randshuffle(b) # b = [ dsp.amp(bb, dsp.rand(0.5, 2)) for bb in b ] # b = ''.join(b) layer += b # layer = dsp.fill(layer, bar) layers += [ layer ] out = dsp.mix(layers) out = dsp.fill(out, bar) return out
def play(voice_id): bpm = config('bpm') key = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) nlen = beat / dsp.randchoose([4,5,6,7,8,9,10]) root = 340.0 target = tune.ntf(key) n = dsp.read('sounds/mike.wav').data n = dsp.transpose(n, target / root) n = dsp.amp(n, 0.4) length = dsp.randint(16, 64) * beat ngrains = length / nlen n = dsp.transpose(n, dsp.randchoose([0.5, 1, 2, 2, 4, 4])) n = dsp.split(n, nlen) snd = dsp.randchoose(n) snd = dsp.env(snd, 'sine') grains = [ snd for i in range(ngrains) ] grains = [ dsp.pan(grain, dsp.rand()) for grain in grains ] out = ''.join(grains) out = dsp.env(out, 'sine') # out = dsp.pad(out, 0, dsp.stf(dsp.randint(0.5, 3))) return out
def singit(lyrics, mult): words = text2wave(lyrics) root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) pitches = [dsp.randint(1, 9) for i in range(dsp.randint(2, 4))] pitches = tune.fromdegrees(pitches, octave=dsp.randint(1, 4), root=root, ratios=ratios, scale=quality) return words sings = [ dsp.pine(words, dsp.flen(words) * mult, pitch) for pitch in pitches ] sings = dsp.mix(sings) # sings = sox("sox %s %s tempo 1.0", sings) return sings
def play(voice_id): bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) bendfactor = 0.05 # bendfactor = 0 bdiv = 4 bdiv *= dsp.randchoose([16, 24, 32]) loctave = 1 hoctave = 4 si = 32 * dsp.randint(1, 2) beat = dsp.bpm2frames(bpm) / bdiv y = [easeOutQuad(float(i), 0, 1, si) for i in range(si)] z = [easeOutQuad(float(i), 0, 1, si) for i in reversed(range(si))] freqs = tune.fromdegrees([1, 2, 3, 4, 5, 6, 7, 8], root=root, octave=dsp.randint(loctave, hoctave), ratios=ratios, scale=quality) freqs = freqs[:dsp.randint(1, len(freqs))] if dsp.rand() > 0.5: freqs = [f for f in reversed(freqs)] freqs = dsp.rotate(freqs, dsp.randint(0, len(freqs))) y = y + z y = [dsp.mstf(v * beat) + dsp.mstf(2) for v in y] x = range(len(y)) def make(length, freq): freq *= dsp.rand(1 - (bendfactor / 2.0), 1 + (bendfactor / 2.0)) out = keys.chippy(length=int(length * dsp.rand(0.01, 0.4)), freq=freq, amp=0.7) out = dsp.env(out, 'phasor') out = dsp.pad(out, 0, length - dsp.flen(out)) return out out = [make(v, freqs[i % len(freqs)]) for i, v in enumerate(y)] out = ''.join(out) out = dsp.pan(out, dsp.rand(0, 1)) return out
def play(voice_id): bpm = config('bpm') key = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) beat = beat / 4 glitch = False alias = False nbeats = P(voice_id, 'multiple', dsp.randchoose([8, 16])) gs = ['gC1', 'gC2'] g = dsp.randchoose(gs) n = dsp.read('sounds/%s.wav' % g).data # speeds = [1, 1.25, 1.5, 1.666, 2, 4] speeds = [1, 1.25, 1.5, 2, 3, 4, 6, 8, 16] root = tune.ntf('c') target = tune.ntf(key) n = dsp.transpose(n, target / root) n = dsp.fill(n, dsp.stf(20)) n = dsp.transpose(n, dsp.randchoose(speeds)) n = dsp.split(n, beat) n = dsp.randshuffle(n) n = n[:nbeats + 1] if alias: n = [ dsp.alias(nn) for nn in n ] n = [ dsp.amp(nn, dsp.rand(0.1, 0.75)) for nn in n ] n = [ dsp.pan(nn, dsp.rand()) for nn in n ] n = ''.join(n) out = n if glitch: out = dsp.vsplit(out, dsp.mstf(dsp.rand(80, 140)), dsp.mstf(500)) out = dsp.randshuffle(out) out = ''.join(out) return out
def play(voice_id): bpm = config('bpm') key = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) beat = beat / 4 glitch = False alias = False nbeats = P(voice_id, 'multiple', dsp.randchoose([8, 16])) gs = ['gC1', 'gC2'] g = dsp.randchoose(gs) n = dsp.read('sounds/%s.wav' % g).data # speeds = [1, 1.25, 1.5, 1.666, 2, 4] speeds = [1, 1.25, 1.5, 2, 3, 4, 6, 8, 16] root = tune.ntf('c') target = tune.ntf(key) n = dsp.transpose(n, target / root) n = dsp.fill(n, dsp.stf(20)) n = dsp.transpose(n, dsp.randchoose(speeds)) n = dsp.split(n, beat) n = dsp.randshuffle(n) n = n[:nbeats + 1] if alias: n = [dsp.alias(nn) for nn in n] n = [dsp.amp(nn, dsp.rand(0.1, 0.75)) for nn in n] n = [dsp.pan(nn, dsp.rand()) for nn in n] n = ''.join(n) out = n if glitch: out = dsp.vsplit(out, dsp.mstf(dsp.rand(80, 140)), dsp.mstf(500)) out = dsp.randshuffle(out) out = ''.join(out) return out
def play(voice_id): bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) bendfactor = 0.05 # bendfactor = 0 bdiv = 4 bdiv *= dsp.randchoose([16, 24, 32]) loctave = 1 hoctave = 4 si = 32 * dsp.randint(1, 2) beat = dsp.bpm2frames(bpm) / bdiv y = [ easeOutQuad(float(i), 0, 1, si) for i in range(si) ] z = [ easeOutQuad(float(i), 0, 1, si) for i in reversed(range(si)) ] freqs = tune.fromdegrees([1,2,3,4,5,6,7,8], root=root, octave=dsp.randint(loctave, hoctave), ratios=ratios, scale=quality) freqs = freqs[:dsp.randint(1, len(freqs))] if dsp.rand() > 0.5: freqs = [ f for f in reversed(freqs) ] freqs = dsp.rotate(freqs, dsp.randint(0, len(freqs))) y = y + z y = [ dsp.mstf(v * beat) + dsp.mstf(2) for v in y ] x = range(len(y)) def make(length, freq): freq *= dsp.rand(1 - (bendfactor / 2.0), 1 + (bendfactor / 2.0)) out = keys.chippy(length=int(length*dsp.rand(0.01, 0.4)), freq=freq, amp=0.7) out = dsp.env(out, 'phasor') out = dsp.pad(out, 0, length - dsp.flen(out)) return out out = [ make(v, freqs[i % len(freqs)]) for i,v in enumerate(y) ] out = ''.join(out) out = dsp.pan(out, dsp.rand(0,1)) return out
def singit(lyrics, mult): words = text2wave(lyrics) root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) pitches = [ dsp.randint(1, 9) for i in range(dsp.randint(2, 4)) ] pitches = tune.fromdegrees(pitches, octave=dsp.randint(1, 4), root=root, ratios=ratios, scale=quality) return words sings = [ dsp.pine(words, dsp.flen(words) * mult, pitch) for pitch in pitches ] sings = dsp.mix(sings) # sings = sox("sox %s %s tempo 1.0", sings) return sings
def play(voice_id): reload(keys) bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) scale = [1,5,8] if dsp.rand() > 0.5: scale = reversed(scale) freqs = tune.fromdegrees(scale, root=root, octave=dsp.randint(1, 3), ratios=ratios, scale=quality) freqs = dsp.rotate(freqs, dsp.randint(0, len(freqs))) out = '' length = int(dsp.bpm2frames(bpm) * dsp.randchoose([0.25, 0.5, 1]) * 0.5) length = dsp.bpm2frames(bpm) * 4 length = dsp.stf(dsp.rand(1, 8)) for n in range(dsp.randint(1, 3)): amp = dsp.rand(0.3, 0.65) freq = dsp.randchoose(freqs) freq = freqs[n%len(freqs)] b = keys.chippy(length=length, freq=freq, amp=amp) b = dsp.split(b, 100) oenvs = dsp.breakpoint([0,0,0,0] + [ dsp.rand() for i in range(len(b) / 10) ], len(b)) opans = dsp.breakpoint([dsp.rand(0.4, 0.6)] + [ dsp.rand() for i in range(len(b) / 100) ] + [0.5], len(b)) b = [ dsp.amp(b[i], oenvs[i]) for i in range(len(b)) ] b = [ dsp.pan(b[i], opans[i]) for i in range(len(b)) ] b = ''.join(b) #b = dsp.env(b, 'phasor') b = dsp.env(b, 'sine') out += b return out
def play(voice_id): bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) length = dsp.randint(dsp.stf(1), dsp.stf(3)) wav = dsp.breakpoint([0] + [dsp.rand(-1, 1) for w in range(10)] + [0], 512) win = dsp.wavetable('sine', 512) mod = dsp.wavetable('vary', 512) root = dsp.randchoose(tune.fromdegrees([1, 3, 5, 8], octave=0, root='a')) pw = dsp.rand(0.1, 1) amp = dsp.rand(0.5, 1.2) mFreq = 0.01 / dsp.fts(length) out = dsp.pulsar(root, length, pw, wav, win, mod, 0.05, mFreq, amp) # out = dsp.env(out, 'vary') out = dsp.vsplit(out, dsp.mstf(1), dsp.mstf(500)) out = dsp.randshuffle(out) out = [dsp.pad(o, 0, dsp.randint(0, 4410)) for o in out] out = [dsp.pan(o, dsp.rand()) for o in out] out = [dsp.alias(o) for o in out] out = [o * dsp.randint(1, 30) for o in out] out = [dsp.env(o, 'random') for o in out] out = [dsp.amp(o, dsp.rand(0.9, 1.5)) for o in out] out = ''.join(out) return out
def play(voice_id): bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) length = dsp.randint(dsp.stf(1), dsp.stf(3)) wav = dsp.breakpoint([0] + [ dsp.rand(-1,1) for w in range(10) ] + [0], 512) win = dsp.wavetable('sine', 512) mod = dsp.wavetable('vary', 512) root = dsp.randchoose(tune.fromdegrees([1,3,5,8], octave=0, root='a')) pw = dsp.rand(0.1, 1) amp = dsp.rand(0.5, 1.2) mFreq = 0.01 / dsp.fts(length) out = dsp.pulsar(root, length, pw, wav, win, mod, 0.05, mFreq, amp) # out = dsp.env(out, 'vary') out = dsp.vsplit(out, dsp.mstf(1), dsp.mstf(500)) out = dsp.randshuffle(out) out = [ dsp.pad(o, 0, dsp.randint(0, 4410)) for o in out ] out = [ dsp.pan(o, dsp.rand()) for o in out ] out = [ dsp.alias(o) for o in out ] out = [ o * dsp.randint(1, 30) for o in out ] out = [ dsp.env(o, 'random') for o in out ] out = [ dsp.amp(o, dsp.rand(0.9, 1.5)) for o in out ] out = ''.join(out) return out
def play(voice_id): bpm = config('bpm') beat = dsp.bpm2frames(bpm) dsl = P(voice_id, 'drum', 'h.c') length = int(P(voice_id, 'length', dsp.stf(dsp.rand(5, 12)))) volume = P(voice_id, 'volume', 70.0) volume = volume / 100.0 # TODO move into param filter octave = P(voice_id, 'octave', 3) notes = P(voice_id, 'note', '["%s"]' % config('key')) notes = json.loads(notes) hertz = P(voice_id, 'hertz', False) alias = P(voice_id, 'alias', False) alias = True bend = P(voice_id, 'bend', False) env = P(voice_id, 'envelope', 'gauss') harmonics = P(voice_id, 'harmonic', '[1,2,3,4]') harmonics = json.loads(harmonics) reps = P(voice_id, 'repeats', 1) waveform = P(voice_id, 'waveform', 'sine2pi') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) glitch = False #glitch = True root = 27.5 pinecone = False bbend = False wild = False if bbend == True: bend = True tune.a0 = float(root) # These are amplitude envelopes for each partial, # randomly selected for each. Not to be confused with # the master 'env' param which is the amplit wtypes = ['sine', 'phasor', 'line', 'saw'] layers = [] if hertz is not False: notes = hertz for note in notes: tones = [] for i in range(dsp.randint(2, 4)): if hertz is not False: freq = float(note) if octave > 1: freq *= octave else: freq = tune.ntf(note, octave) snds = [ dsp.tone(length, freq * h, waveform, 0.05) for h in harmonics ] snds = [ dsp.env(s, dsp.randchoose(wtypes), highval=dsp.rand(0.3, 0.6)) for s in snds ] snds = [dsp.pan(s, dsp.rand()) for s in snds] if bend is not False: def bendit(out=''): if bbend == True: bendtable = dsp.randchoose([ 'impulse', 'sine', 'line', 'phasor', 'cos', 'impulse' ]) lowbend = dsp.rand(0.8, 0.99) highbend = dsp.rand(1.0, 1.25) else: bendtable = 'sine' lowbend = 0.99 # lowbend = 0.75 highbend = 1.01 # highbend = 1.5 out = dsp.split(out, 441) freqs = dsp.wavetable(bendtable, len(out)) freqs = [ math.fabs(f) * (highbend - lowbend) + lowbend for f in freqs ] out = [ dsp.transpose(out[i], freqs[i]) for i in range(len(out)) ] return ''.join(out) snds = [bendit(snd) for snd in snds] tones += [dsp.mix(snds)] layer = dsp.mix(tones) if wild != False: layer = dsp.vsplit(layer, 41, 4410) layer = [dsp.amp(dsp.amp(l, dsp.rand(10, 20)), 0.5) for l in layer] layer = ''.join(layer) if pinecone != False: layer = dsp.pine(layer, length, freq, 4) if glitch == True: layer = dsp.vsplit(layer, dsp.mstf(10), dsp.flen(layer) / 4) layer = dsp.randshuffle(layer) layer = ''.join(layer) layer = dsp.env(layer, env) layers += [layer] out = dsp.mix(layers) * reps return dsp.amp(out, volume)
def play(voice_id): bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) amp = dsp.rand(0.1, 0.65) nlens = [ beat * 4, beat * 3, beat * 2, beat + (beat / 2), beat, beat / 2, beat / 4, ] scale = [2,4,6,9] scale = [1,4,6,8] # scale = [1,3,4,5,6,8,9] # scale = [1,2,3,5,6,8,9] # scale = [1,5,8] freqs = tune.fromdegrees(scale, root=root, octave=dsp.randint(2,4), ratios=ratios, scale=quality) # length of pattern (in beats) elen = 0 tlen = beat * dsp.randint(2, 8) # beat lengths (from a set of bpm-derived note lengths defined in the nlens list) blens = [] while elen < tlen: l = dsp.randchoose(nlens) blens += [ l ] elen += l # beat pulsewidths bpws = [ dsp.rand(0.1, 1) for pw in range(len(blens)) ] out = '' # choose a pitch from the scale freq = dsp.randchoose(freqs) # synthesize the tones for i in range(len(blens)): # find the length of the pulse blen = int(round(blens[i] * bpws[i])) # find the length of the rest brest = blens[i] - blen # make a rhodes tone with a random amplitude #beat = keys.rhodes(length=blen, freq=freq, amp=dsp.rand(0.3, 0.5)) beat = keys.rhodes(length=blen, freq=freq, amp=amp) # pan the tone to a random position beat = dsp.pan(beat, dsp.rand()) # bitcrush the tone a random amount # beat = dsp.alias(beat) # pad the tone with silence beat = dsp.pad(beat, 0, brest) # add it to the output out += beat out *= dsp.randint(1, 2) if dsp.rand() > 0.75: out = dsp.split(out, dsp.bpm2frames(bpm) / dsp.randchoose([1,2,4])) out = dsp.randshuffle(out) out = ''.join(out) return out
def play(voice_id): tel = bot.getTel() bpm = s.config('bpm') #if 'gentle' in tel['name'] or 'upbeat' in tel['name'] or 'full' in tel['name']: #dsp.log('') #dsp.log(voice_id + ' chirps silent') #return dsp.pad('', 0, dsp.stf(dsp.rand(1, 10))) length = int((1.0 / (tel['pace'] / 10.0)) * dsp.stf(3)) def makecurve(length): # freq, length, pulsewidth, waveform, window, mod, modRange, modFreq, amp wf = dsp.breakpoint([0] + [ dsp.rand(-1, 1) for i in range(int(dsp.rand(5, 30))) ] + [0], 1024) win = dsp.breakpoint([0] + [ dsp.rand(0, 1) for i in range(4) ] + [0], 1024) mod = dsp.breakpoint([ dsp.rand(0, 1) for i in range(int(dsp.rand(4, 8))) ], 1024) smaxamp = dsp.rand(0.65, 0.95) amp = dsp.rand(0.01, smaxamp) pw = dsp.rand(0.1, 1.0) if 'upbeat' in tel['name']: wf = dsp.breakpoint([0] + [ dsp.rand(-1, 1) for i in range(int(dsp.rand(5, 30))) ] + [0], 1024) win = dsp.breakpoint([0] + [ dsp.rand(0, 1) for i in range(4) ] + [0], 1024) mod = dsp.breakpoint([ dsp.rand(0, 1) for i in range(int(dsp.rand(5, 80))) ], 1024) pw = 1.0 if 'ballsout' in tel['name']: wf = dsp.breakpoint([0] + [ dsp.rand(-1, 1) for i in range(int(dsp.rand(10, 40))) ] + [0], 1024) win = dsp.breakpoint([0] + [ dsp.rand(0, 1) for i in range(10) ] + [0], 1024) mod = dsp.breakpoint([ dsp.rand(0, 1) for i in range(int(dsp.rand(20, 100))) ], 1024) if 'sparse' in tel['name']: amp = dsp.rand(0.7, 3) freq = tel['register'] * tel['roughness'] * (tel['density'] * tel['pace'] * 0.25) #if dsp.rand(0, 100) > 50: #freq = dsp.rand(2, 20) modR = tel['harmonicity'] modF= tel['pace'] / 10.0 c = dsp.pulsar(freq, length, pw, wf, win, mod, modR, modF, amp) ngrains = len(c) pans = dsp.breakpoint([ dsp.rand(0,1) for i in range(100) ], ngrains) maxPad = dsp.randint(2000, 4000) if 'sparse' in tel['name']: c = dsp.vsplit(c, dsp.mstf(0.5), dsp.mstf(tel['density'] * tel['harmonicity'] * tel['roughness'] * tel['pace'])) c = [ dsp.randchoose(c) for i in range(int(dsp.rand(3, 10))) ] elif 'ballsout' in tel['name']: c = dsp.vsplit(c, dsp.mstf(0.1), dsp.mstf(400)) c = dsp.packet_shuffle(c, dsp.randint(5, 10)) speeds = dsp.breakpoint([ dsp.rand(tel['register'] * 0.1 + 0.2, tel['register'] + 0.2) for i in range(100) ], ngrains) #c = [ dsp.transpose(cg, speeds[i]) for i, cg in enumerate(c) ] #c = [ dsp.amp(cg, dsp.rand(0.25, 1.25)) for i, cg in enumerate(c) ] for ic, cc in enumerate(c): if dsp.rand(0, 100) > 70: c[ic] = dsp.tone(dsp.flen(cc), 11000, amp=0.5) elif 'upbeat' in tel['name']: beat = dsp.bpm2frames(bpm) c = dsp.split(c, beat) maxPad = 0 c = [ dsp.pad(cg, 0, dsp.mstf(dsp.rand(10, beat / 4))) for i, cg in enumerate(c) ] else: c = dsp.vsplit(c, dsp.mstf(10), dsp.mstf(tel['density'] * tel['harmonicity'] * tel['roughness'] * tel['pace'] * dsp.rand(1, 10))) c = [ dsp.pan(cg, pans[i]) for i, cg in enumerate(c) ] c = [ dsp.env(cg, 'sine') for i, cg in enumerate(c) ] if 'sparse' in tel['name'] or 'ballsout' in tel['name']: speeds = dsp.breakpoint([ dsp.rand(0.5, 1.99) for i in range(100) ], ngrains) for ic, cc in enumerate(c): if dsp.flen(cc) < dsp.mstf(100): c[ic] = cc + ''.join([ dsp.amp(cc, dsp.rand(0.1, 1.0)) for buh in range(dsp.randint(1, int(tel['density']))) ]) #c = [ dsp.transpose(cg, speeds[i]) for i, cg in enumerate(c) ] c = [ dsp.pan(cg, dsp.rand(0.0, 1.0)) for i, cg in enumerate(c) ] if 'ballsout' not in tel['name']: c = [ dsp.pad(cg, 0, dsp.mstf(dsp.rand(10, maxPad))) for i, cg in enumerate(c) ] out = ''.join(c) return out out = makecurve(length) if dsp.flen(out) > dsp.mstf(100) and dsp.rand(0, 100) > 30: out = dsp.drift(out, (tel['harmonicity'] - 10.0) * -1 * 0.5, dsp.randint(41, 441)) if dsp.flen(out) > dsp.stf(10): out = dsp.fill(out, dsp.stf(10)) if dsp.rand(0, 100) > 50: out = dsp.vsplit(out, 41, 441) for ii, o in enumerate(out): if dsp.rand(0, 100) > 50: out[ii] = dsp.pad('', 0, dsp.flen(o)) elif dsp.rand(0, 100) > 50: out[ii] = dsp.amp(o, dsp.rand(0.75, 3)) out = [ dsp.pan(o, dsp.rand()) for o in out ] out = ''.join(out) dsp.log('') dsp.log('chirp') dsp.log('%s length: %.2f' % (voice_id, dsp.fts(dsp.flen(out)))) bot.show_telemetry(tel) return out
def play(voice_id): bpm = config('bpm') beat = dsp.bpm2frames(bpm) dsl = P(voice_id, 'drum', '["c","k","h"]') dsp.log(dsl) dsl = json.loads(dsl) def hat(beat): length = beat * 4 nbeats = 16 blen = length / nbeats out = '' for b in range(nbeats): h = dsp.transpose(tape1, 9) h = dsp.fill(h, dsp.mstf(dsp.rand(1, 20))) h = dsp.env(h, 'phasor') h = dsp.amp(h, dsp.rand(0, 0.8)) h = dsp.pad(h, 0, blen - dsp.flen(h)) out += h out *= 8 return out def kick(beat): out = drums.sinekick(length=beat, amp=dsp.rand(0.8, 1)) out = dsp.pad(out, 0, beat * dsp.randint(1, 2)) out *= 2 return out def clap1(beat): c = dsp.read('sounds/mikeclap.wav').data c = dsp.transpose(c, dsp.rand(1, 2.5)) c = dsp.fill(c, dsp.mstf(dsp.rand(10, 100))) c = dsp.env(c, 'phasor') c = dsp.amp(c, dsp.rand(1, 3)) c = dsp.pad(c, 0, beat - dsp.flen(c)) blen = beat / dsp.randchoose([1, 2]) c = dsp.pad(c, blen, 0) c *= 4 return c def clap2(beat): nlens = [ beat * 2, beat, beat / 2, ] # length of pattern (in beats) nbeats = dsp.randint(10, 15) # beat lengths (from a set of bpm-derived note lengths defined in the nlens list) blens = [dsp.randchoose(nlens) for b in range(nbeats)] out = '' # synthesize the tones for i in range(nbeats): beat = dsp.transpose(dsp.randchoose([c1, c2]), dsp.rand(0.25, 40.0)) beat = dsp.pad(beat, 0, blens[i] - dsp.flen(beat)) beat = dsp.amp(beat, dsp.rand(1, 4)) # add it to the output out += beat return out all = [] if 'c' in dsl: clapper = dsp.randchoose([clap1, clap2]) all += [clapper(beat)] if 'k' in dsl: all += [kick(beat)] if 'h' in dsl: all += [hat(beat)] out = dsp.mix(all) # out = dsp.vsplit(out, dsp.mstf(dsp.rand(8, 140)), dsp.mstf(500)) # out = dsp.randshuffle(out) # out = ''.join(out) out = dsp.vsplit(out, 10, 1000) out = [dsp.amp(o, dsp.rand(0, 4)) for o in out] out = [dsp.env(o, 'random') for o in out] out = [dsp.transpose(o, dsp.rand(0.25, 1)) for o in out] out = dsp.randshuffle(out) out = ''.join(out) out = dsp.pine(out, int(dsp.flen(out) * dsp.rand(1.5, 4)), dsp.rand(10, 2000), dsp.randint(0, 2), dsp.rand(1, 3), dsp.randint(0, 2), dsp.rand(1, 3)) out = dsp.amp(out, 0.65) glass = dsp.read('sounds/s/glass2.wav').data glass = dsp.vsplit(glass, dsp.mstf(1), dsp.mstf(100)) glass = dsp.randshuffle(glass) # glass = [ dsp.pad(g, 0, dsp.randint(10, 1000)) for g in glass ] # glass = [ dsp.transpose(g, dsp.rand(0.5, 1.5)) * dsp.randint(1, 3) for g in glass ] glass = ''.join(glass) glass = dsp.fill(glass, dsp.flen(out)) out = dsp.mix([out, glass]) return out
def play(voice_id): bpm = config('bpm') beat = dsp.bpm2frames(bpm) dsl = P(voice_id, 'drum', 'h.c') length = int(P(voice_id, 'length', dsp.stf(dsp.rand(5, 12)))) volume = P(voice_id, 'volume', 70.0) volume = volume / 100.0 # TODO move into param filter octave = P(voice_id, 'octave', 3) notes = P(voice_id, 'note', '["%s"]' % config('key')) notes = json.loads(notes) hertz = P(voice_id, 'hertz', False) alias = P(voice_id, 'alias', False) alias = True bend = P(voice_id, 'bend', False) env = P(voice_id, 'envelope', 'gauss') harmonics = P(voice_id, 'harmonic', '[1,2,3,4]') harmonics = json.loads(harmonics) reps = P(voice_id, 'repeats', 1) waveform = P(voice_id, 'waveform', 'sine2pi') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) glitch = False #glitch = True root = 27.5 pinecone = False bbend = False wild = False if bbend == True: bend = True tune.a0 = float(root) # These are amplitude envelopes for each partial, # randomly selected for each. Not to be confused with # the master 'env' param which is the amplit wtypes = ['sine', 'phasor', 'line', 'saw'] layers = [] if hertz is not False: notes = hertz for note in notes: tones = [] for i in range(dsp.randint(2,4)): if hertz is not False: freq = float(note) if octave > 1: freq *= octave else: freq = tune.ntf(note, octave) snds = [ dsp.tone(length, freq * h, waveform, 0.05) for h in harmonics ] snds = [ dsp.env(s, dsp.randchoose(wtypes), highval=dsp.rand(0.3, 0.6)) for s in snds ] snds = [ dsp.pan(s, dsp.rand()) for s in snds ] if bend is not False: def bendit(out=''): if bbend == True: bendtable = dsp.randchoose(['impulse', 'sine', 'line', 'phasor', 'cos', 'impulse']) lowbend = dsp.rand(0.8, 0.99) highbend = dsp.rand(1.0, 1.25) else: bendtable = 'sine' lowbend = 0.99 # lowbend = 0.75 highbend = 1.01 # highbend = 1.5 out = dsp.split(out, 441) freqs = dsp.wavetable(bendtable, len(out)) freqs = [ math.fabs(f) * (highbend - lowbend) + lowbend for f in freqs ] out = [ dsp.transpose(out[i], freqs[i]) for i in range(len(out)) ] return ''.join(out) snds = [ bendit(snd) for snd in snds ] tones += [ dsp.mix(snds) ] layer = dsp.mix(tones) if wild != False: layer = dsp.vsplit(layer, 41, 4410) layer = [ dsp.amp(dsp.amp(l, dsp.rand(10, 20)), 0.5) for l in layer ] layer = ''.join(layer) if pinecone != False: layer = dsp.pine(layer, length, freq, 4) if glitch == True: layer = dsp.vsplit(layer, dsp.mstf(10), dsp.flen(layer) / 4) layer = dsp.randshuffle(layer) layer = ''.join(layer) layer = dsp.env(layer, env) layers += [ layer ] out = dsp.mix(layers) * reps return dsp.amp(out, volume)
def play(voice_id): bpm = config('bpm') root = config('key') quality = getattr(tune, config('quality')) ratios = getattr(tune, config('tune')) beat = dsp.bpm2frames(bpm) amp = dsp.rand(0.1, 0.65) nlens = [ beat * 4, beat * 3, beat * 2, beat + (beat / 2), beat, beat / 2, beat / 4, ] scale = [2, 4, 6, 9] scale = [1, 4, 6, 8] # scale = [1,3,4,5,6,8,9] # scale = [1,2,3,5,6,8,9] # scale = [1,5,8] freqs = tune.fromdegrees(scale, root=root, octave=dsp.randint(2, 4), ratios=ratios, scale=quality) # length of pattern (in beats) elen = 0 tlen = beat * dsp.randint(2, 8) # beat lengths (from a set of bpm-derived note lengths defined in the nlens list) blens = [] while elen < tlen: l = dsp.randchoose(nlens) blens += [l] elen += l # beat pulsewidths bpws = [dsp.rand(0.1, 1) for pw in range(len(blens))] out = '' # choose a pitch from the scale freq = dsp.randchoose(freqs) # synthesize the tones for i in range(len(blens)): # find the length of the pulse blen = int(round(blens[i] * bpws[i])) # find the length of the rest brest = blens[i] - blen # make a rhodes tone with a random amplitude #beat = keys.rhodes(length=blen, freq=freq, amp=dsp.rand(0.3, 0.5)) beat = keys.rhodes(length=blen, freq=freq, amp=amp) # pan the tone to a random position beat = dsp.pan(beat, dsp.rand()) # bitcrush the tone a random amount # beat = dsp.alias(beat) # pad the tone with silence beat = dsp.pad(beat, 0, brest) # add it to the output out += beat out *= dsp.randint(1, 2) if dsp.rand() > 0.75: out = dsp.split(out, dsp.bpm2frames(bpm) / dsp.randchoose([1, 2, 4])) out = dsp.randshuffle(out) out = ''.join(out) return out
def play(voice_id): bpm = config('bpm') beat = dsp.bpm2frames(bpm) dsl = P(voice_id, 'drum', '["c","k","h"]') dsp.log(dsl) dsl = json.loads(dsl) def hat(beat): length = beat * 4 nbeats = 16 blen = length / nbeats out = '' for b in range(nbeats): h = dsp.transpose(tape1, 9) h = dsp.fill(h, dsp.mstf(dsp.rand(1, 20))) h = dsp.env(h, 'phasor') h = dsp.amp(h, dsp.rand(0, 0.8)) h = dsp.pad(h, 0, blen - dsp.flen(h)) out += h out *= 8 return out def kick(beat): out = drums.sinekick(length=beat, amp=dsp.rand(0.8, 1)) out = dsp.pad(out, 0, beat * dsp.randint(1, 2)) out *= 2 return out def clap1(beat): c = dsp.read('sounds/mikeclap.wav').data c = dsp.transpose(c, dsp.rand(1, 2.5)) c = dsp.fill(c, dsp.mstf(dsp.rand(10, 100))) c = dsp.env(c, 'phasor') c = dsp.amp(c, dsp.rand(1, 3)) c = dsp.pad(c, 0, beat - dsp.flen(c)) blen = beat / dsp.randchoose([1,2]) c = dsp.pad(c, blen, 0) c *= 4 return c def clap2(beat): nlens = [ beat * 2, beat, beat / 2, ] # length of pattern (in beats) nbeats = dsp.randint(10, 15) # beat lengths (from a set of bpm-derived note lengths defined in the nlens list) blens = [ dsp.randchoose(nlens) for b in range(nbeats) ] out = '' # synthesize the tones for i in range(nbeats): beat = dsp.transpose(dsp.randchoose([c1,c2]), dsp.rand(0.25, 40.0)) beat = dsp.pad(beat, 0, blens[i] - dsp.flen(beat)) beat = dsp.amp(beat, dsp.rand(1, 4)) # add it to the output out += beat return out all = [] if 'c' in dsl: clapper = dsp.randchoose([clap1,clap2]) all += [ clapper(beat) ] if 'k' in dsl: all += [ kick(beat) ] if 'h' in dsl: all += [ hat(beat) ] out = dsp.mix(all) # out = dsp.vsplit(out, dsp.mstf(dsp.rand(8, 140)), dsp.mstf(500)) # out = dsp.randshuffle(out) # out = ''.join(out) out = dsp.vsplit(out, 10, 1000) out = [ dsp.amp(o, dsp.rand(0, 4)) for o in out ] out = [ dsp.env(o, 'random') for o in out ] out = [ dsp.transpose(o, dsp.rand(0.25, 1)) for o in out ] out = dsp.randshuffle(out) out = ''.join(out) out = dsp.pine(out, int(dsp.flen(out) * dsp.rand(1.5, 4)), dsp.rand(10, 2000), dsp.randint(0, 2), dsp.rand(1, 3), dsp.randint(0, 2), dsp.rand(1, 3)) out = dsp.amp(out, 0.65) glass = dsp.read('sounds/s/glass2.wav').data glass = dsp.vsplit(glass, dsp.mstf(1), dsp.mstf(100)) glass = dsp.randshuffle(glass) # glass = [ dsp.pad(g, 0, dsp.randint(10, 1000)) for g in glass ] # glass = [ dsp.transpose(g, dsp.rand(0.5, 1.5)) * dsp.randint(1, 3) for g in glass ] glass = ''.join(glass) glass = dsp.fill(glass, dsp.flen(out)) out = dsp.mix([ out, glass ]) return out