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_rand_1000(self): dsp.seed(1000) for m in methods: dsp.randmethod(m) values = [] for _ in range(1000): values += [dsp.rand()] dsp.win(values).graph('tests/renders/rand_%s_1000values.png' % m) # teardown dsp.randmethod('normal')
def test_smear(self): dsp.seed() g = dsp.read('tests/sounds/guitar10s.wav').rcut(1) out = multiband.smear(g) out.write('tests/renders/multiband_smear-guitar-0.01.wav') dsp.seed() g = dsp.read('tests/sounds/living.wav') out = multiband.smear(g) out.write('tests/renders/multiband_smear-living-0.01.wav')
def test_shape_synth(self): dsp.seed() out = shapes.synth('sine', minfreq=80, maxfreq=800, stability=0.99, length=10) amp = shapes.win('sine', length=10) out = out * amp out.write('tests/renders/shape_synth.wav')
def test_shape_wt(self): dsp.seed() wt = shapes.wt('sine', length=10, density='rnd', stability='rnd', periodicity='rnd') amp = shapes.wt('sine', length=10, density='rnd', stability='rnd', periodicity='rnd') wt = wt * amp wt.graph('tests/renders/shape_wt.png')
def test_shape_wt(self): dsp.seed() for i in range(4): wt = shapes.wt('sine', length=10, density='rnd', stability='rnd', periodicity='rnd') amp = shapes.wt('sine', length=10, density='rnd', stability='rnd', periodicity='rnd') wt = wt * amp wt.graph('tests/renders/shape_wt%s.png' % i, width=1024)
from pippi import dsp, shapes dsp.seed(111) minval = 0. maxval = 1. grainsperbranch = 4 passes = (4, 8, 12, 18, 40, 400) for numgrains in passes: A = dsp.rand(minval, maxval) B = dsp.rand(minval, maxval) numbranches = numgrains // grainsperbranch if A > B: A, B = B, A trunk = dsp.win('rsaw', A, B) trunk.graph('trunk-%s-rsaw.png' % numgrains, y=(0,1)) branches = [] for _ in range(numbranches): bD = dsp.rand(0.001, 0.999) # delta bA = dsp.rand(max(A - (bD/2), 0), min(A + (bD/2), 1)) branches += [ dsp.buffer(dsp.win('rsaw', bA, B), channels=1) ] branches = dsp.stack(branches) branches.graph('branches-%s-rsaw.png' % numgrains, y=(0,1))
def test_spread(self): dsp.seed() g = dsp.read('tests/sounds/guitar1s.wav') out = multiband.spread(g) out.write('tests/renders/multiband_spread-guitar-0.5.wav') """
from pippi import dsp from pippi import tune import math dsp.quiet = False dsp.timer('start') dsp.seed('jbutler') cathedral = dsp.read('sounds/cathedral.wav') tone = dsp.read('sounds/ding.wav').data def fade(snd, time=dsp.mstf(1)): first = dsp.cut(snd, 0, time) middle = dsp.cut(snd, time, dsp.flen(snd) - (time * 2)) last = dsp.cut(snd, dsp.flen(middle) + time, time) snd = dsp.env(first, 'line') + middle + dsp.env(last, 'phasor') return snd 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)
from unittest import TestCase from pippi import dsp, soundfont, fx dsp.seed() class TestSoundfont(TestCase): def test_play(self): length = 10 freq = 660 amp = 1 voice = 1 out = soundfont.play("tests/sounds/florestan-gm.sf2", length, freq, amp, voice) out.write('tests/renders/soundfont_play.wav') def test_playall(self): events = [] pos = 0 length = 10 while pos < length: events += [ dict(start=pos, length=dsp.rand(0.2, 3), freq=30 * dsp.randint(1, 10), amp=dsp.rand(), voice=dsp.randint(0, 127)) ] pos += dsp.rand(0.01, 0.1)
def test_create_breakpoint(self): dsp.seed(1000) b = Breakpoint(10) wt = b.towavetable() wt.graph('tests/renders/breakpoint_default.png', y=(-1, 1))
from pippi import dsp from pippi import tune import math dsp.quiet = False dsp.timer('start') dsp.seed('jbutler') cathedral = dsp.read('sounds/cathedral.wav') tone = dsp.read('sounds/ding.wav').data def fade(snd, time=dsp.mstf(1)): first = dsp.cut(snd, 0, time) middle = dsp.cut(snd, time, dsp.flen(snd) - (time * 2)) last = dsp.cut(snd, dsp.flen(middle) + time, time) snd = dsp.env(first, 'line') + middle + dsp.env(last, 'phasor') return snd 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
def play(ctl): p = ctl.get('param') key = p.get('key', 'c') mpk = ctl.get('midi').get('mpk') bpm = p.get('bpm', 100) beat = dsp.bpm2frames(bpm) length = beat * 2 * mpk.geti(6, low=1, high=6) gamut = mpk.geti(20) poly = mpk.geti(21) logistic = mpk.geti(22) layered = mpk.geti(23) fixed = mpk.get(24) perc = mpk.get(25) wobble = mpk.get(26) min_octave = mpk.geti(4, low=1, high=4) max_octave = mpk.geti(4, low=3, high=7) octave = dsp.randint(min_octave, max_octave) k = dsp.randchoose(snds.search('mc303/*kick*')) h = dsp.randchoose(snds.search('mc303/*hat*')) c = dsp.randchoose(snds.search('mc303/*clap*')) pointer = p.get('pointer', default=0) log = data.Logistic(r=dsp.rand(3.9, 3.99), x=0.5, size=1024, pointer=pointer) if fixed: seed = mpk.get(5) else: seed = time.time() dsp.seed(str(seed)) def makeOnsets(length, wobble, div, num_beats, offset=False): if offset: offset = dsp.randint(0, 3) else: offset = 0 pattern = dsp.eu(num_beats, dsp.randint(1, num_beats/div), offset) dsp.log(pattern) if wobble: points = [ dsp.mstf(100, 500) for _ in range(dsp.randint(2, 8)) ] plength = sum(points) mult = length / float(plength) onsets = curves.bezier(points, num_beats) onsets = [ int(o * mult) for o in onsets ] else: beat = float(length) / num_beats num_beats = length / beat beat = int(round(beat)) onsets = [ beat * i for i in range(int(round(num_beats))) ] return onsets def makeKicks(length, wobble): out = Tracks() onsets = makeOnsets(length, wobble, 2, 4, True) kick = dsp.taper(k, 20) kick = dsp.transpose(kick, dsp.rand(1, 2)) for onset in onsets: out.add(kick, onset) out = out.mix() out = dsp.fill(out, length, silence=False) return dsp.taper(out, 40) def makeHats(length, wobble): out = Tracks() onsets = makeOnsets(length, wobble, 1, 16, True) for onset in onsets: out.add(h, onset) out = out.mix() out = dsp.split(out, dsp.flen(out) / dsp.randchoose([2, 3, 4])) out = dsp.randshuffle(out) out = ''.join(out) out = dsp.fill(out, length, silence=False) return dsp.taper(out, 40) def makeClaps(length, wobble): out = Tracks() onsets = makeOnsets(length, wobble, 2, 8, True) for onset in onsets: clap = dsp.stretch(c, int(dsp.flen(c) * log.get(1, 10)), grain_size=dsp.randint(20, 120)) out.add(clap, onset) out = out.mix() out = dsp.split(out, dsp.flen(out) / dsp.randchoose([2, 3, 4])) out = [ dsp.taper(o, 20) for o in out ] out = dsp.randshuffle(out) out = ''.join(out) out = dsp.fill(out, length, silence=False) return dsp.taper(out, 40) if mpk.get(8) == 0: return dsp.pad('', 0, dsp.mstf(100)) def randomScale(): scale = [1,2,3,4,5,6,7,8] freqs = tune.fromdegrees(scale, octave=octave, root=key) return freqs def gamutScale(): num_notes = dsp.randint(3, 6) scale = [ dsp.randchoose([1,2,3,4,5,6,7,8]) for _ in range(num_notes) ] freqs = tune.fromdegrees(scale, octave=octave, root=key) return freqs if gamut: freqs = gamutScale() else: freqs = randomScale() if layered: num_layers = dsp.randint(2, 4) else: num_layers = 1 layers = [] for _ in range(num_layers): layer = '' elapsed = 0 while elapsed < length: if poly: num_poly = dsp.randint(1, 3) else: num_poly = 1 note_length = beat / dsp.randchoose([1, 2, 3, 4]) notes = [] for _ in range(num_poly): freq = dsp.randchoose(freqs) if logistic: pulsewidth = log.get(low=0.05, high=1) if log.get() > 0.5: wf = log.choose(['sine', 'tri', 'saw']) wf = dsp.wavetable(wf, 512) else: points = [ log.get(-1, 1) for _ in range(log.geti(4, 20)) ] wf = dsp.breakpoint(points, 512) else: pulsewidth = 1 wf = dsp.wavetable('sine', 512) note = keys.pulsar(length=note_length, freq=freq, wf=wf, env='phasor', pulsewidth=pulsewidth) notes += [ note ] notes = dsp.mix(notes) layer += notes elapsed += dsp.flen(notes) layers += [ layer ] out = dsp.mix(layers) out = dsp.amp(out, 0.75) out = dsp.fill(out, length) #out = dsp.pad(out, 0, int(dsp.stf(0.5, 1) * mpk.get(7))) p.set('pointer', log.pointer) if perc: kicks = makeKicks(length, wobble) hats = makeHats(length, wobble) claps = makeClaps(length, wobble) out = dsp.mix([ out, kicks, hats, claps ]) out = dsp.amp(out, mpk.get(8)) return out
def play(ctl): p = ctl.get('param') key = p.get('key', 'c') mpk = ctl.get('midi').get('mpk') bpm = p.get('bpm', 100) beat = dsp.bpm2frames(bpm) length = beat * 2 * mpk.geti(6, low=1, high=6) gamut = mpk.geti(20) poly = mpk.geti(21) logistic = mpk.geti(22) layered = mpk.geti(23) fixed = mpk.get(24) perc = mpk.get(25) wobble = mpk.get(26) min_octave = mpk.geti(4, low=1, high=4) max_octave = mpk.geti(4, low=3, high=7) octave = dsp.randint(min_octave, max_octave) k = dsp.randchoose(snds.search('mc303/*kick*')) h = dsp.randchoose(snds.search('mc303/*hat*')) c = dsp.randchoose(snds.search('mc303/*clap*')) pointer = p.get('pointer', default=0) log = data.Logistic(r=dsp.rand(3.9, 3.99), x=0.5, size=1024, pointer=pointer) if fixed: seed = mpk.get(5) else: seed = time.time() dsp.seed(str(seed)) def makeOnsets(length, wobble, div, num_beats, offset=False): if offset: offset = dsp.randint(0, 3) else: offset = 0 pattern = dsp.eu(num_beats, dsp.randint(1, num_beats / div), offset) dsp.log(pattern) if wobble: points = [dsp.mstf(100, 500) for _ in range(dsp.randint(2, 8))] plength = sum(points) mult = length / float(plength) onsets = curves.bezier(points, num_beats) onsets = [int(o * mult) for o in onsets] else: beat = float(length) / num_beats num_beats = length / beat beat = int(round(beat)) onsets = [beat * i for i in range(int(round(num_beats)))] return onsets def makeKicks(length, wobble): out = Tracks() onsets = makeOnsets(length, wobble, 2, 4, True) kick = dsp.taper(k, 20) kick = dsp.transpose(kick, dsp.rand(1, 2)) for onset in onsets: out.add(kick, onset) out = out.mix() out = dsp.fill(out, length, silence=False) return dsp.taper(out, 40) def makeHats(length, wobble): out = Tracks() onsets = makeOnsets(length, wobble, 1, 16, True) for onset in onsets: out.add(h, onset) out = out.mix() out = dsp.split(out, dsp.flen(out) / dsp.randchoose([2, 3, 4])) out = dsp.randshuffle(out) out = ''.join(out) out = dsp.fill(out, length, silence=False) return dsp.taper(out, 40) def makeClaps(length, wobble): out = Tracks() onsets = makeOnsets(length, wobble, 2, 8, True) for onset in onsets: clap = dsp.stretch(c, int(dsp.flen(c) * log.get(1, 10)), grain_size=dsp.randint(20, 120)) out.add(clap, onset) out = out.mix() out = dsp.split(out, dsp.flen(out) / dsp.randchoose([2, 3, 4])) out = [dsp.taper(o, 20) for o in out] out = dsp.randshuffle(out) out = ''.join(out) out = dsp.fill(out, length, silence=False) return dsp.taper(out, 40) if mpk.get(8) == 0: return dsp.pad('', 0, dsp.mstf(100)) def randomScale(): scale = [1, 2, 3, 4, 5, 6, 7, 8] freqs = tune.fromdegrees(scale, octave=octave, root=key) return freqs def gamutScale(): num_notes = dsp.randint(3, 6) scale = [ dsp.randchoose([1, 2, 3, 4, 5, 6, 7, 8]) for _ in range(num_notes) ] freqs = tune.fromdegrees(scale, octave=octave, root=key) return freqs if gamut: freqs = gamutScale() else: freqs = randomScale() if layered: num_layers = dsp.randint(2, 4) else: num_layers = 1 layers = [] for _ in range(num_layers): layer = '' elapsed = 0 while elapsed < length: if poly: num_poly = dsp.randint(1, 3) else: num_poly = 1 note_length = beat / dsp.randchoose([1, 2, 3, 4]) notes = [] for _ in range(num_poly): freq = dsp.randchoose(freqs) if logistic: pulsewidth = log.get(low=0.05, high=1) if log.get() > 0.5: wf = log.choose(['sine', 'tri', 'saw']) wf = dsp.wavetable(wf, 512) else: points = [ log.get(-1, 1) for _ in range(log.geti(4, 20)) ] wf = dsp.breakpoint(points, 512) else: pulsewidth = 1 wf = dsp.wavetable('sine', 512) note = keys.pulsar(length=note_length, freq=freq, wf=wf, env='phasor', pulsewidth=pulsewidth) notes += [note] notes = dsp.mix(notes) layer += notes elapsed += dsp.flen(notes) layers += [layer] out = dsp.mix(layers) out = dsp.amp(out, 0.75) out = dsp.fill(out, length) #out = dsp.pad(out, 0, int(dsp.stf(0.5, 1) * mpk.get(7))) p.set('pointer', log.pointer) if perc: kicks = makeKicks(length, wobble) hats = makeHats(length, wobble) claps = makeClaps(length, wobble) out = dsp.mix([out, kicks, hats, claps]) out = dsp.amp(out, mpk.get(8)) return out