def makeGrains(): guitar = dsp.randchoose(guitars) guitar = dsp.transpose(guitar, dsp.randchoose([1, 2, 3, 4, 8])) max_grain_length = dsp.mstf(dsp.rand(10, 500)) positions = [ math.floor(pos * (dsp.flen(guitar) - max_grain_length)) for pos in makeShape() ] lengths = [ math.floor(length * (max_grain_length - 1) + 1) for length in makeShape() ] pans = makeShape() amps = [amp * dsp.rand(0, 10) for amp in makeShape()] num_grains = dsp.randint(500, 1000) grains = [] for i in range(num_grains): grain = dsp.cut(guitar, positions[i % len(positions)], lengths[i % len(lengths)]) grain = dsp.pan(grain, pans[i % len(pans)]) grain = dsp.amp(grain, amps[i % len(amps)]) grain = dsp.taper(grain, 20) grains += [grain] return ''.join(grains)
def play(voice_id): tel = bot.getTel() b = dsp.read('sounds/birds.wav').data b = dsp.split(b, dsp.randint(100, 1000)) b = b[:dsp.randint(len(b) / 10, len(b))] blen = len(b) pans = dsp.breakpoint([ dsp.rand() for i in range(dsp.randint(10, 100)) ], blen) speeds = dsp.breakpoint([ dsp.rand(0.25, 1.5) for i in range(dsp.randint(10, 100)) ], blen) amps = dsp.breakpoint([ dsp.rand(0.05, 1.5) for i in range(dsp.randint(10, 100)) ], blen) b = [ dsp.pan(b[i], pans[i]) for i in range(blen) ] b = [ dsp.transpose(b[i], speeds[i]) for i in range(blen) ] b = [ dsp.amp(b[i], amps[i]) for i in range(blen) ] b = dsp.packet_shuffle(b, dsp.randint(4, 30)) for i, bb in enumerate(b): if dsp.rand(0, 100) > 60: b[i] = bb * dsp.randint(2, 10) out = ''.join(b) dsp.log('') dsp.log('birds') dsp.log(blen) dsp.log('%s length: %.2f' % (voice_id, dsp.fts(dsp.flen(out)))) bot.show_telemetry(tel) return out
def chord(length, freqs, amp): layers = [ keys.rhodes(length, freq, amp * dsp.rand(0.25, 0.5)) for freq in freqs ] layers = [dsp.pan(layer, dsp.rand()) for layer in layers] return dsp.mix(layers)
def smear(input, mingrain=2205, maxgrain=4410, waveform='hann', spread=0.1, drift=0.05, minpan=0.0, maxpan=1.0, minamp=0.0, maxamp=1.0): out = dsp.vsplit(input, mingrain, maxgrain) out = [ dsp.amp(grain, dsp.rand(minamp, maxamp)) for grain in out ] out = [ dsp.env(grain, waveform) for grain in out ] out = [ dsp.pan(grain, dsp.rand(minpan, maxpan)) for grain in out ] drift_delta = drift / 2.0 minspeed = 1.0 - drift_delta maxspeed = 1.0 + drift_delta out = [ dsp.transpose(grain, dsp.rand(minspeed, maxspeed)) for grain in out ] num_shuffled_grains = int(len(out) * spread) # Pull a random set of grains shuffled_grains = [] for i in range(num_shuffled_grains): index = dsp.randint(0, len(out) - 1) shuffled_grains += [ out.pop(index) ] # Insert them back into random positions for grain in shuffled_grains: index = dsp.randint(0, len(out) - 1) out.insert(index, grain) out = ''.join(out) return out
def ding(tone, tlength=88200, nlength=1000): def sequence(tonic='g'): numdegrees = dsp.randint(2, 8) degrees = [1, 5, 8, 11, 12] #scale = [ dsp.randchoose(degrees) for i in range(numdegrees) ] scale = degrees[dsp.randint(0, 3):] scale = dsp.randshuffle(scale) scale = tune.fromdegrees(scale, 1, tonic, tune.major, tune.terry) return scale numtones = tlength / nlength numtones = 1 if numtones < 1 else numtones freqs = [note / tune.ntf('g', 4) for note in sequence('g')] tones = [dsp.transpose(tone, freq) for freq in freqs] #tones = [ dsp.cut(tones[i % len(tones)], dsp.mstf(dsp.rand(0, 100)), nlength + dsp.randint(0, 500)) for i in range(numtones) ] tones = [ dsp.cut(tones[i % len(tones)], dsp.mstf(dsp.rand(0, 100)), nlength) for i in range(numtones) ] #tones = [ dsp.drift(tone, 0.03) for tone in tones ] curve = dsp.breakpoint([0] + [dsp.rand(0, 0.01) for i in range(3)], len(tones)) tones = [ dsp.drift(tone, curve[index % len(curve)]) for index, tone in enumerate(tones) ] tones = [fade(tone) for tone in tones] return dsp.amp(''.join(tones), 0.5)
def play(ctl): def stream(length, numsegments, freq): out = [] seglength = dsp.randint(100, 300) points = [ dsp.rand(-1, 1) for _ in range(dsp.randint(10, 20)) ] for _ in range(numsegments): seglength = dsp.cap(seglength + dsp.randint(-5, 5), 1000, 100) points = [ dsp.cap(p + dsp.randint(-0.1, 0.1), 1, -1) for p in points ] out += dsp.breakpoint([0] + points + [0], seglength) print len(out), freq, length out = dsp.ctone(freq, dsp.stf(length), out, dsp.rand(0.1, 0.5)) #out = dsp.env(out, 'random') return out numstreams = dsp.randint(20, 30) out = '' for _ in range(numstreams): length = dsp.rand(100, 500) / 1000.0 numsegments = dsp.randint(100, 200) freq = dsp.rand(200, 1000) out += stream(length, numsegments, freq) #out = dsp.env(out, 'random') return out
def worker(gens, tick): while time.time() < started + (60 * 15): dsp.delay(dsp.stf(dsp.rand(2, 20))) if dsp.rand(0, 100) > 50: if dsp.rand(0, 100) > 80: voice_id, generator_name = settings.add_voice("pp re qu") dsp.log("") dsp.log("starting pulsar voice %s" % voice_id) elif dsp.rand(0, 100) > 50: voice_id, generator_name = settings.add_voice("ch re qu") dsp.log("") dsp.log("starting chirp voice %s" % voice_id) else: voice_id, generator_name = settings.add_voice("bo re qu") dsp.log("") dsp.log("starting boone voice %s" % voice_id) playback_process = mp.Process(name=voice_id, target=rt.out, args=(gens[generator_name], tick)) playback_process.start() dsp.delay(dsp.stf(dsp.rand(6, 35))) dsp.log("") dsp.log("stopping voice %s" % voice_id) settings.voice(voice_id, "loop", 0)
def test_sandwich_board(self): l = dsp.read('tests/sounds/linux.wav') g = dsp.read('tests/sounds/guitar1s.wav') f = fx.crossover(l, dsp.win('phasor', 0, 1), dsp.rand(0.1, 0.3), dsp.win('rnd', 0, 1)).graph(fontsize=50, label='Weird FX') ws = Waveset(g).substitute('sine').graph(fontsize=50, label='Waveset Manipulation') ps = oscs.Pulsar2d(freq=dsp.rand(10, 80), pulsewidth=shapes.win('hann')).play(2).graph( fontsize=50, label='Pulsar Synthesis') wt = shapes.win('hann', length=0.4) * shapes.win('sine') * shapes.win('rnd') wt.graph( 'tests/renders/graph_sandwich_board.png', insets=[ps, ws, f], width=900, height=340, label='Pippi: Computer Music With Python', stroke=30, fontsize=30, ) # For the readme shutil.copy('tests/renders/graph_sandwich_board.png', 'banner.png')
def spider(snd, numlayers=10, numgrains=20, minlen=40, lenranges=(300,500), reverse=False, env='hann'): layers = [] for layer in range(numlayers): lenrange = dsp.rand(lenranges[0], lenranges[1]) if reverse: lengths = dsp.wavetable(env, numgrains * 2)[numgrains:] else: lengths = dsp.wavetable(env, numgrains * 2)[:numgrains] lengths = [ dsp.mstf(l * lenrange + minlen) for l in lengths ] pans = dsp.breakpoint([ dsp.rand() for p in range(numgrains / 3)], numgrains) startpoint = dsp.randint(0, dsp.flen(snd) - max(lengths)) grains = '' for l, p in zip(lengths, pans): grain = dsp.cut(snd, startpoint, l) grain = dsp.env(grain, 'phasor') grain = dsp.taper(grain, dsp.mstf(10)) grain = dsp.pan(grain, p) grains += grain if reverse: layers += [ dsp.env(grains, 'line') ] else: layers += [ dsp.env(grains, 'phasor') ] return dsp.mix(layers)
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
def smear(snd): snd = dsp.split(snd, dsp.mstf(dsp.rand(5000, 10000))) snd = dsp.randshuffle(snd) snd = [ dsp.env(s) for s in snd ] snd = [ s * dsp.randint(1, 8) for s in snd ] return dsp.drift(''.join(snd), dsp.rand(0.01, 0.1))
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(ctl): freq = tune.ntf(dsp.randchoose(['eb']), octave=dsp.randint(0,2)) synth = keys.rhodes(dsp.stf(4), freq) s = dsp.vsplit(synth, dsp.mstf(50), dsp.mstf(2000)) s = dsp.randshuffle(s) #s = [ dsp.alias(ss) for ss in s ] s = [ dsp.amp(ss, dsp.rand(0.5, 0.75)) for ss in s ] s = [ dsp.pan(ss, dsp.rand(0, 1)) for ss in s ] s = ''.join(s) s = dsp.fill(s, dsp.flen(synth)) s2 = dsp.vsplit(synth, dsp.mstf(150), dsp.mstf(1500)) s2 = dsp.randshuffle(s2) s2 = [ dsp.transpose(ss, dsp.randchoose([1,1.5,2,3,4,8])) for ss in s2 ] s2 = [ dsp.env(ss, 'phasor') for ss in s2 ] s2 = ''.join(s2) out = dsp.mix([ s, s2 ]) out = dsp.amp(out, 1.5) out = dsp.transpose(out, 1.01) #synth = dsp.fill(synth, dsp.flen(main)) #out = synth return out
def makeRhodes(length, beat, freqs): root = tune.ntf(key, 2) for i, freq in enumerate(freqs): if freq > root * 2.5: freqs[i] = freq * 0.5 chord = [ keys.rhodes(length, freq, dsp.rand(0.4, 0.6)) for freq in freqs ] chord = dsp.randshuffle(chord) pause = 0 for i, c in enumerate(chord): pause = pause + (dsp.randint(1, 4) * beat) c = dsp.pan(c, dsp.rand()) chord[i] = dsp.pad(dsp.fill(c, length - pause), pause, 0) chord = dsp.mix(chord) chord = dsp.split(chord, dsp.flen(chord) / 16) chord = dsp.randshuffle(chord) chord = [ dsp.env(ch, 'phasor') for ch in chord ] chord = [ dsp.mix([ dsp.amp(dsp.pan(grain, dsp.rand()), dsp.rand(0.1, 0.8)), dsp.amp(dsp.pan(dsp.randchoose(chord), dsp.rand()), dsp.rand(0.1, 0.8)) ]) for grain in chord ] chord = ''.join(chord) return chord
def smear(snd): snd = dsp.split(snd, dsp.mstf(dsp.rand(5000, 10000))) snd = dsp.randshuffle(snd) snd = [dsp.env(s) for s in snd] snd = [s * dsp.randint(1, 8) for s in snd] return dsp.drift(''.join(snd), dsp.rand(0.01, 0.1))
def roll(snd, length=None, numlayers=2, minlen=10, maxlen=80, env=True, bend=True): layers = [] for _ in range(numlayers): if length is None: numbeats = dsp.randint(20, 50) else: numbeats = length / dsp.mstf(minlen) lengths = dsp.breakpoint([ dsp.rand(minlen, maxlen) for _ in range(dsp.randint(5, numbeats/2)) ], numbeats) layer = '' for l in lengths: layer += dsp.fill(snd, dsp.mstf(l), silence=True) if bend: layer = fx.bend(layer, [ dsp.rand(0, 1) for _ in range(dsp.randint(5, 20)) ], dsp.rand(0.02, 1)) if env: layer = fx.penv(layer) layers += [ layer ] out = dsp.mix(layers) out = dsp.fill(out, length) return out
def makeHat(length, i): h = dsp.bln(length / 4, dsp.rand(6000, 8000), dsp.rand(9000, 16000)) h = dsp.amp(h, dsp.rand(0.5, 1)) h = dsp.env(h, 'phasor') h = dsp.fill(h, length, silence=True) return h
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
def ding(tone, tlength=88200, nlength=1000): def sequence(tonic='g'): numdegrees = dsp.randint(2, 8) degrees = [1,5,8,11,12] #scale = [ dsp.randchoose(degrees) for i in range(numdegrees) ] scale = degrees[dsp.randint(0, 3):] scale = dsp.randshuffle(scale) scale = tune.fromdegrees(scale, 1, tonic, tune.major, tune.terry) return scale numtones = tlength / nlength numtones = 1 if numtones < 1 else numtones freqs = [ note / tune.ntf('g', 4) for note in sequence('g') ] tones = [ dsp.transpose(tone, freq) for freq in freqs ] #tones = [ dsp.cut(tones[i % len(tones)], dsp.mstf(dsp.rand(0, 100)), nlength + dsp.randint(0, 500)) for i in range(numtones) ] tones = [ dsp.cut(tones[i % len(tones)], dsp.mstf(dsp.rand(0, 100)), nlength) for i in range(numtones) ] #tones = [ dsp.drift(tone, 0.03) for tone in tones ] curve = dsp.breakpoint([0] + [ dsp.rand(0, 0.01) for i in range(3) ], len(tones)) tones = [ dsp.drift(tone, curve[index % len(curve)]) for index, tone in enumerate(tones) ] tones = [ fade(tone) for tone in tones ] return dsp.amp(''.join(tones), 0.5)
def play(ctl): #out = snds.load('genie/piano.wav') lenrange = 300 minlen = 1 if dsp.rand() > 0.5: lengths = dsp.breakpoint([dsp.rand(0, 1) for _ in range(5)], 50) else: lengths = dsp.wavetable('sine', 50) lengths = [dsp.mstf(l * lenrange + minlen) for l in lengths] out = '' for length in lengths: freq = tune.ntf('f', octave=dsp.randint(2, 5)) if dsp.rand() > 10.85: length = dsp.stf(dsp.rand(0.5, 3)) freq = dsp.randchoose( tune.fromdegrees([1, 3, 4, 5, 6], octave=4, root='f')) out += keys.pulsar(freq=freq, length=length, env='phasor') if dsp.rand() > 10.75: freq = dsp.randchoose( tune.fromdegrees([1, 3, 4, 5, 6], octave=4, root='f')) return out
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)
def ping(maxlen=44100, freqs=None): out = '' if freqs is None: freqs = [ dsp.rand(20,10000) for i in range(4) ] tlen = dsp.randint(10, maxlen) tones = [ dsp.tone(length=tlen, freq=freq, amp=0.1, wavetype='random') for freq in freqs ] tones = [ dsp.split(tone, 64) for tone in tones ] pcurves = [ dsp.breakpoint([ dsp.rand() for t in range(len(tones[i]) / 20) ], len(tones[i])) for i in range(len(tones)) ] tones = [ [ dsp.pan(t, pcurves[i][ti]) for ti, t in enumerate(tones[i]) ] for i in range(len(tones)) ] fcurves = [ dsp.breakpoint([ dsp.rand(0.0, 0.1) + 0.9 for t in range(len(tones[i]) / 20) ], len(tones[i])) for i in range(len(tones)) ] tones = [ [ dsp.transpose(t, fcurves[i][ti] + 0.1) for ti, t in enumerate(tones[i]) ] for i in range(len(tones)) ] out = dsp.mix([ dsp.env(''.join(tone), 'random') for tone in tones ]) out = dsp.env(out, 'random') out = dsp.pad(out, 0, dsp.randint(0, maxlen * 3)) return out
def play(ctl): dpc = ctl.get('midi').get('dpc') lpd = ctl.get('midi').get('lpd') print lpd.get(1) dpc.setOffset(111) pw = dpc.get(1, low=0.01, high=1) scale = [1, 2, 3, 6, 9] scale = [1, 4, 6, 8] scale = [1, 3, 5, 9] scale = tune.fromdegrees(scale, octave = dpc.geti(4, low=0, high=4)) freq = dsp.randchoose(scale) length = dsp.stf(dpc.get(2, low=0.1, high=8) * dsp.rand(0.5, 1.5)) wf = dsp.wavetable('sine2pi') win = dsp.wavetable('sine') mod = [ dsp.rand(0, 1) for m in range(1000) ] modr = dpc.get(5, low=0, high=0.3) modf = dpc.get(6, low=0.001, high=10) amp = dpc.get(3, low=0, high=1) out = dsp.pulsar(freq, length, pw, wf, win, mod, modr, modf, amp) out = dsp.env(out, dsp.randchoose(['sine', 'tri'])) out = dsp.pan(out, dsp.rand()) return out
def play(voice_id): tel = bot.getTel() degrees = [ dsp.randchoose([1, 2, 3, 5, 6, 8]) for f in range(dsp.randint(2, 20)) ] #degrees = [ dsp.randchoose([1, 5, 6, 7, 8]) for f in range(dsp.randint(2, 10)) ] octave = dsp.randint(1, 4) freqs = tune.fromdegrees(degrees, root='c', octave=octave, ratios=tune.terry) out = '' for r in range(dsp.randint(2, 20)): freq = dsp.randchoose(freqs) waveform = dsp.randchoose(['tri', 'sine2pi']) length = dsp.randint(dsp.mstf(1), dsp.mstf(4000)) #length = dsp.mstf(1500) #length = dsp.mstf(2500) pulsewidth = dsp.rand(0.01, 1) mod = dsp.breakpoint([ dsp.rand() for b in range(int(round(tel['density'])) + 3) ], 512) window = dsp.breakpoint([0] + [ dsp.rand() for b in range(int(round(tel['harmonicity'] * 2)) + 3) ] + [0], 512) waveform = dsp.breakpoint([0] + [ dsp.rand(-1, 1) for b in range(int(round(tel['roughness'] * dsp.randint(1, 4))) + 3) ] + [0], 512) modRange = dsp.rand(0.01, 100.08) modFreq = dsp.rand(0.0001, 5) volume = dsp.rand(0.2, 0.3) * (tel['density'] / 10.0) #volume = dsp.rand(0.2, 0.8) t = dsp.pulsar(freq, length, pulsewidth, waveform, window, mod, modRange, modFreq, volume) #t = dsp.tone(length, freq, waveform) t = dsp.pan(t, dsp.rand()) t = dsp.alias(t) t = dsp.amp(t, dsp.rand(0.5, 15.0)) t = dsp.pad(t, 0, dsp.randint(dsp.mstf(1), dsp.mstf(10))) t = dsp.amp(t, dsp.rand(0.5, 0.95)) t = dsp.env(t, 'sine') #t = dsp.env(t, 'phasor') #t = dsp.pine(t, dsp.flen(t) * 4, freq) out += t dsp.log('') dsp.log('boone') dsp.log('%s length: %.2f' % (voice_id, dsp.fts(dsp.flen(out)))) bot.show_telemetry(tel) return out
def test_create_bar(self): length = 1 out = dsp.buffer(length=length) params = [(0.21, 1, 0), (0.3, 0.9, 0.5), (0.22, 0.8, 1)] for beat, inc, pan in params: pos = 0 stiffness = 280 while pos < length: duration = dsp.rand(1, 4) decay = dsp.rand(0.1, 10) velocity = dsp.rand(500, 2000) barpos = dsp.rand(0.2, 0.8) width = dsp.rand(0.1, 0.8) stiffness = max(1, stiffness) note = Bar(decay=decay, stiffness=stiffness, velocity=velocity, barpos=barpos, width=width).play(duration).env('hannout').pan(pan) out.dub(note, pos) pos += beat stiffness -= inc out = fx.norm(out, 1) out.write('tests/renders/osc_bar.wav')
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
def makePulse(length, i): freqs = tune.fromdegrees([ dsp.randchoose([1,2,3,4,5,6,8]) for _ in range(dsp.randint(2,4)) ], octave=2, root=key) pulse = chord(length, freqs, dsp.rand(0.5, 0.75)) pulse = dsp.taper(pulse, 40) pulse = dsp.amp(pulse, dsp.rand(0.5, 1)) pulse = dsp.fill(pulse, length, silence=True) return pulse
def makeSnare(length, i, amp): s = ssnd s = dsp.amp(s, 10) s = dsp.transpose(s, dsp.rand(0.8, 1)) s = dsp.fill(s, length, silence=True) ss = dsp.drift(s, dsp.rand(0.001, 0.1)) s = dsp.mix([s, ss]) return s
def makeSnare(length, i): burst = dsp.bln(length, dsp.rand(400, 800), dsp.rand(8000, 10000)) burst = dsp.env(burst, 'phasor') s = dsp.mix([snare, burst]) s = dsp.transpose(s, dsp.rand(0.9, 1.1)) s = dsp.fill(s, length, silence=True) return dsp.taper(s, 40)
def play(ctx): length = dsp.rand(6, 12) highfreq = dsp.rand(10000, 20000) lowfreq = highfreq - dsp.rand(1000, 5000) out = noise.bln('sine', length, lowfreq, highfreq) out = out.env('hann') * dsp.rand(0.01, 0.04) out = out.pan('rnd') yield out
def makePulse(length, i): chord = tune.fromdegrees([ dsp.randchoose([1,4,5,8]) for _ in range(dsp.randint(2,4)) ], octave=2, root=key) pulse = rhodesChord(length, chord, dsp.rand(0.5, 0.75)) #pulse = dsp.mix([ pulse, kick ]) pulse = dsp.taper(pulse, 40) pulse = dsp.amp(pulse, dsp.rand(0.9, 1.5)) pulse = dsp.fill(pulse, length, silence=True) return pulse
def penv(snd, low=4, high=20): packets = dsp.split(snd, dsp.dsp_grain) ptable = dsp.breakpoint([ dsp.rand() for _ in range(dsp.randint(low, high)) ], len(packets)) etable = dsp.breakpoint([0] + [ dsp.rand() for _ in range(dsp.randint(low, high)) ] + [0], len(packets)) packets = [ dsp.pan(p, ptable[i], etable[i]) for i, p in enumerate(packets) ] return ''.join(packets)
def chirp(): r = dsp.rand(3.6, 3.99) numpoints = dsp.randint(10, 30) freq = dsp.rand(200, 1000) slength = dsp.rand(0.05, 0.5) length = dsp.stf(slength) log = data.Logistic(r, size=numpoints) mod = dsp.breakpoint([0] + [dsp.rand() for r in range(numpoints / 3)] + [0], numpoints) mod = [p * log.get() for p in mod] modr = dsp.rand(1, 5) modf = 1.0 / slength wf = dsp.wavetable('sine2pi', 512) win = dsp.wavetable('sine', 512) pw = dsp.rand(0.5, 1) amp = dsp.rand(0.1, 0.3) out = dsp.pulsar(freq, length, pw, wf, win, mod, modr, modf, amp) out = dsp.env(out, 'random') out = dsp.taper(out, dsp.mstf(10)) out = dsp.pan(out, dsp.rand()) out = dsp.pad(out, 0, dsp.stf(dsp.rand(0.1, 0.3))) return out
def test_insets(self): wt1 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt1_graph = wt1.graph(label='LFO 1') wt2 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt2_graph = wt2.graph(label='LFO 2') wt3 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt3_graph = wt3.graph(label='LFO 3') snd = dsp.read('tests/sounds/linux.wav')
def hat(length): lowf = dsp.rand(6000, 11000) highf = dsp.rand(11000, 17000) if dsp.rand() > 0.5: length *= 0.05 out = bln(length, lowf, highf) out = out.env(dsp.choice(['rsaw', 'phasor', 'hannout'])) return out
def chippy(length=22050, freq=220, amp=0.5): wfrm = dsp.wavetable('sine2pi', 512) wndw = dsp.wavetable('tri', 512) modw = [ 1 for u in range(256) ] + [ 0 for d in range(256) ] modr = 1 modf = dsp.rand(10, 20) pw = dsp.rand() out = dsp.pulsar(freq, length, pw, wfrm, wndw, modw, modr, modf, amp) return out
def test_insets(self): wt1 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt1_graph = wt1.graph(stroke=10) wt2 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt2_graph = wt2.graph(stroke=10) wt3 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt3_graph = wt3.graph(stroke=10) snd = dsp.read('tests/sounds/linux.wav') snd.graph('tests/renders/graph_insets.png', insets=[wt1_graph, wt2_graph, wt3_graph], stroke=3, width=1200, height=500)
def test_insets(self): wt1 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt1_graph = wt1.graph(label='LFO 1') wt2 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt2_graph = wt2.graph(label='LFO 2') wt3 = wavetables.seesaw('rnd', 4096, dsp.rand(0, 1)) wt3_graph = wt3.graph(label='LFO 3') snd = dsp.read('tests/sounds/linux.wav') snd.graph('tests/renders/graph_insets.png', insets=[wt1_graph, wt2_graph, wt3_graph], stroke=3, width=900, height=250, label='I pronounce Linux as Linux')
def makeLayer(freq): pw = dsp.rand() wf = dsp.wavetable('tri', 512) win = dsp.wavetable('hann', 512) mod = dsp.breakpoint([ dsp.rand() for m in range(dsp.randint(4,8)) ], 512) modf = dsp.rand(0.1, 2) modr = dsp.rand(0, 0.01) amp = dsp.rand(0.1, 0.5) layer = dsp.pulsar(freq, length, pw, wf, win, mod, modf, modr, amp) return layer
def makePulse(length, i): freqs = tune.fromdegrees([ dsp.randchoose([1, 2, 3, 4, 5, 6, 8]) for _ in range(dsp.randint(2, 4)) ], octave=2, root=key) pulse = chord(length, freqs, dsp.rand(0.5, 0.75)) pulse = dsp.taper(pulse, 40) pulse = dsp.amp(pulse, dsp.rand(0.5, 1)) pulse = dsp.fill(pulse, length, silence=True) return pulse
def play(voice_id): volume = P(voice_id, 'volume', 100.0) volume = volume / 100.0 # TODO: move into param filter volume = volume * 0.65 length = P(voice_id, 'length', 40) env = False wii = False # wii = True speed = False numcycles = dsp.randint(1, 200) # Make breakpoint env with 2-10 vals between 0.1 and 1.0 curve_a = dsp.breakpoint([1.0] + [dsp.rand(0.1, 1.0) for r in range(dsp.randint(2, 10))] + [0], numcycles) # Make wavetable with single cycle from given wave types curve_types = ['vary', 'phasor', 'sine', 'cos', 'impulse'] curve_b = dsp.wavetable(dsp.randchoose(curve_types), numcycles) # Make pan curve - always cosine pan = dsp.breakpoint([ dsp.rand() for i in range(dsp.randint(5, 50)) ], numcycles) amps = dsp.breakpoint([ dsp.rand(0.1, 0.75) for i in range(dsp.randint(5, 30)) ], numcycles) # Multiply breakpoint curve with simple wavetable wtable = [ curve_a[i] * curve_b[i] for i in range(numcycles) ] # Scale to max frequency wtable = [ (f * 20000) + length for f in wtable ] # Possible osc wavetypes wtypes = ['sine2pi'] # wtypes = ['tri', 'sine2pi', 'impulse'] # wtypes = ['impulse', 'tri', 'cos', 'sine2pi', 'vary'] if wii is True: out = [ dsp.pan(dsp.cycle(wtable[i], dsp.randchoose(wtypes)), pan[i]) for i in range(numcycles) ] else: wtype = dsp.randchoose(wtypes) out = [ dsp.pan(dsp.cycle(wtable[i], wtype), pan[i]) for i in range(numcycles) ] out = [ dsp.amp(oo, amps[i]) for i, oo in enumerate(out) ] out = dsp.amp(''.join(out), volume) if speed != False and speed > 0.0: out = dsp.transpose(out, speed) if env != False: out = dsp.env(out, env) return out
def make_tracks(numtracks): tracks = range(numtracks) g.db.execute('delete from `blocks`;') # Testing out display of rendered blocks for i, track in enumerate(tracks): blocks = range(dsp.randint(1, 5)) # for each sound: for j, snd in enumerate(blocks): # render it. snd = dsp.tone(dsp.stf(dsp.rand(0.5, 5))) # filename is track_id-block_id.wav for now filename = "%i-%i-%i" % (i, j, 0) # write it to disk dsp.write(snd, 'static/sounds/%s' % filename) # Calc length in pixels from frames length = dsp.flen(snd) pxlength = "%ipx" % (length / 441,) slength = "%02fs" % dsp.fts(length) offset = dsp.stf(dsp.rand(0, 60)) # save in the db block = ( 0, 0, i, length, length, offset, filename, ) g.db.execute('insert into `blocks` (version, generator_id, track_id, length, range, offset, filename) values (?, ?, ?, ?, ?, ?, ?)', block) c = g.db.cursor() block_id = c.lastrowid() # block is a tuple: # (block index, filename, length in pixels, offset in pixels) blocks[j] = (block_id, filename, slength, ftpx(length), ftpx(offset)) tracks[i] = blocks g.db.commit() return tracks
def hat(length): lowf = dsp.rand(6000, 11000) highf = dsp.rand(11000, 17000) if dsp.randint(0, 6) == 0: out = bln(length, lowf, highf) out = dsp.env(out, 'line') else: out = bln(int(length * 0.05), lowf, highf) out = dsp.env(out, 'phasor') out = dsp.pad(out, 0, length - dsp.flen(out)) return out
def makeRhodes(length, beat, freqs, maxbend=0.05): backup = Sampler(snds.load('tones/nycrhodes01.wav'), tune.ntf('c'), direction='fw-bw-loop', tails=False) chord = [ keys.rhodes(length, freq, dsp.rand(0.4, 0.7)) for freq in freqs ] chord = dsp.randshuffle(chord) chord = [ dsp.mix([ dsp.env(fx.penv(backup.play(freq * 2**dsp.randint(0,2), length, dsp.rand(0.4, 0.6))), 'line'), c ]) for freq, c in zip(freqs, chord) ] pause = 0 for i, c in enumerate(chord): pause = pause + (dsp.randint(1, 4) * beat) c = dsp.pan(c, dsp.rand()) c = fx.bend(c, [ dsp.rand() for _ in range(dsp.randint(5, 10)) ], dsp.rand(0, maxbend)) chord[i] = dsp.pad(dsp.fill(c, length - pause), pause, 0) return dsp.mix(chord)
def hat(length): lowf = dsp.rand(600, 7000) highf = dsp.rand(7000, 19000) if dsp.randint(0, 6) == 0: out = dsp.bln(length, lowf, highf) out = dsp.env(out, 'line') else: out = dsp.bln(int(length * 0.05), lowf, highf) out = dsp.env(out, 'phasor') out = dsp.pad(out, 0, length - dsp.flen(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 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 makeTails(self, freq, length): freq *= 0.5 harmonics = [ dsp.randint(1, 8) for _ in range(2, 4) ] layers = [] for harmonic in harmonics: layer = dsp.tone(length, freq * harmonic, amp=dsp.rand(0.1, 0.3)) layer = fx.penv(layer) layer = dsp.env(layer, 'sine') layers += [ layer ] layers = dsp.mix(layers) layers = dsp.amp(layers, dsp.rand(0.25, 1)) return layers
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 play(voice_id): tel = bot.getTel() freqs = tune.fromdegrees([ dsp.randchoose([1, 2, 3, 5, 6, 8]) for f in range(dsp.randint(2, 5)) ], root='c', octave=dsp.randint(1, 3), ratios=tune.just) out = '' for freq in freqs: waveform = dsp.randchoose(['tri', 'sine2pi']) length = dsp.randint(dsp.mstf(10), dsp.mstf(300)) #length = dsp.mstf(150) pulsewidth = dsp.rand() mod = dsp.breakpoint([ dsp.rand() for b in range(int(round(tel['density'])) + 3) ], 512) window = dsp.breakpoint([0] + [ dsp.rand() for b in range(int(round(tel['harmonicity'] * 2)) + 3) ] + [0], 512) waveform = dsp.breakpoint([0] + [ dsp.rand(-1, 1) for b in range(int(round(tel['roughness'] * 3)) + 3) ] + [0], 512) modRange = 0.005 modFreq = dsp.rand(0.0001, 5) volume = dsp.rand(0.2, 0.3) if dsp.rand(0, 100) > 50: t = dsp.pulsar(freq, length, pulsewidth, waveform, window, mod, modRange, modFreq, volume) else: t = dsp.tone(length, freq, waveform) #t = dsp.pulsar(freq, length, pulsewidth, waveform, window, mod, modRange, modFreq, volume) #t = dsp.tone(length, freq, waveform) t = dsp.pan(t, dsp.rand()) t = dsp.alias(t) t = dsp.amp(t, dsp.rand(0.5, 5.0)) t = dsp.pad(t, 0, dsp.randint(dsp.mstf(1), dsp.mstf(500))) #t = dsp.pad(t, 0, dsp.mstf(100)) t = dsp.amp(t, dsp.rand(0.5, 0.75)) #out += dsp.env(t, 'sine') out += t #out = dsp.env(t, 'sine') dsp.log('') dsp.log('boone') dsp.log('%s length: %.2f' % (voice_id, dsp.fts(dsp.flen(out)))) bot.show_telemetry(tel) return out
def clap(amp, length): if amp == 0: return dsp.pad('', 0, length) # Two layers of noise: lowmid and high lowlow, lowhigh = dsp.rand(300, 600), dsp.rand(700, 1200) highlow, highhigh = dsp.rand(3000, 7000), dsp.rand(7000, 9000) out = dsp.mix([ dsp.bln(int(length * 0.2), lowlow, lowhigh), dsp.bln(int(length * 0.2), 7000, 9000) ]) out = dsp.env(out, 'phasor') out = dsp.pad(out, 0, length - dsp.flen(out)) out = dsp.amp(out, amp) return out
def test_shape_pulsar(self): dsp.seed() for i in range(4): wts = [shapes.wt('sine', length=1) for _ in range(3)] wins = [shapes.win('sine', length=1) for _ in range(3)] wins = [w * dsp.win('hann') for w in wins] amp = shapes.win('sine', length=1) pw = dsp.win(shapes.win('sine', length=1), 0.1, 1) freq = dsp.win(shapes.win('sine', length=1), 20, 260) grid = dsp.win(shapes.win('sine', length=1), 0.001, 0.75) gl = dsp.win(shapes.win('sine', length=1), 0.03, 0.3) win = shapes.win('sine', length=1) * dsp.win('hann') out = oscs.Pulsar2d( wts, windows=wins, freq=freq, pulsewidth=pw, amp=amp, ).play(dsp.rand(0.2, 1)).cloud(length=20, window=win, grainlength=gl, grid=grid, speed=dsp.win( shapes.win('sine', length=1), 0.03, 2), spread='rnd', jitter='rnd') out.write('tests/renders/shape_pulsar%s.wav' % i)
def test_principle_tones(self): note = 110 intervals = range(1, 12) #intervals = [5] events = [] pos = 0 voice = 1 for interval in intervals: scale = slonimsky.principle_tones(interval) freqs = [ ((deg+12)//12, tune.JUST[deg % 12]) for deg in scale ] freqs = [ (r[1][0] / r[1][1]) * r[0] * note for r in freqs ] for freq in freqs: print(interval, freq) events += [dict( start=pos, length=0.5, freq=freq, amp=dsp.rand(0.5, 0.55), voice=voice, )] pos += 0.2 out = soundfont.playall("tests/sounds/florestan-gm.sf2", events) out = fx.norm(out, 0.75) out.write('tests/renders/slonimsky_intervals-1-12-principle-scales.wav')
def makeSnare(length, i, amp): s = dsp.cut(snare, 0, dsp.randint(dsp.mstf(40), dsp.flen(snare))) s = dsp.alias(s, dsp.randint(4, 12)) s = dsp.taper(s) s = dsp.fill(s, length, silence=True) s = dsp.amp(s, dsp.rand(2, 4)) return s
def bass_and_lead(length, pos, total_length): numbeats = int(length//BEAT) maxbeats = dsp.randint(2, 16) layers = [] def bass(amp, length, oct=2): if amp == 0: return dsp.buffer(length=length) bass_note = dsp.choice(scale) * 0.25 stack = Waveset(rmx, limit=dsp.randint(5, 20), offset=dsp.randint(0, 100)) stack.normalize() out = oscs.Pulsar2d(stack, windows=['sine'], freq=bass_note).play(length) * dsp.rand(0.02, 0.2) out = fx.lpf(out, bass_note*2) return out.env('hannout').taper(dsp.MS*10) if dsp.rand() > 0.5: basses = bass(0.5, length, 1) else: bpat = drums.eu(numbeats, maxbeats) basses = drums.make(bass, bpat, [BEAT]*numbeats) layers += [ basses ] lead_note = dsp.choice(scale) stack = Waveset(rmx, limit=dsp.randint(5, 20), offset=dsp.randint(0, 100)) stack.normalize() lead = oscs.Pulsar2d(stack, windows=['tri'], freq=lead_note*2, pulsewidth=dsp.win('rnd', 0.1, 1)).play(length/dsp.rand(1,5)).env('hannout').taper(0.01) * dsp.rand(0.02, 0.2) layers += [ lead ] return fx.norm(dsp.mix(layers), 1)
def makeArps(seg, oct=3, reps=4): arp_degrees = [1,2,3,5,8,9,10] if dsp.randint(0,1) == 0: arp_degrees.reverse() arp_degrees = rotate(arp_degrees, vary=True) arp_notes = tune.fromdegrees(arp_degrees[:reps], octave=oct, root='e') arps = [] arp_count = 0 for arp_length in seg: arp_length /= 2 arp_pair = arp_notes[ arp_count % len(arp_notes) ], arp_notes[ (arp_count + 1) % len(arp_notes) ] stack = Waveset(rmx, limit=dsp.randint(5, 20), offset=dsp.randint(0, 100)) stack.normalize() arp_one = oscs.Pulsar2d(stack, windows=['tri'], freq=arp_pair[0]*dsp.choice([1,2]), pulsewidth=dsp.win('rnd', 0.1, 1)).play(arp_length).env('hannout').taper(0.01) * dsp.rand(0.02, 0.2) arp_two = oscs.Pulsar2d(stack, windows=['tri'], freq=arp_pair[1]*dsp.choice([1,2]), pulsewidth=dsp.win('rnd', 0.1, 1)).play(arp_length).env('hannout').taper(0.01) * dsp.rand(0.02, 0.2) arp_one.dub(arp_two) arps += [ arp_one ] arp_count += 2 return dsp.join(arps).env('rnd').pan(dsp.rand())
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 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