Skip to content

Instantly share code, notes, and snippets.

@hecanjog
Created December 25, 2014 03:09
Show Gist options
  • Save hecanjog/53dde3b0e97b5f323262 to your computer and use it in GitHub Desktop.
Save hecanjog/53dde3b0e97b5f323262 to your computer and use it in GitHub Desktop.
skip2.py
from pippi import dsp
class Player:
def __init__(self, snd, position=0, jump_size=dsp.stf(5), skip_length=dsp.mstf(180)):
self.snd = snd
self.position = dsp.randint(position, position + jump_size)
self.jump_size = jump_size # playhead max jump size
self.skip_length = skip_length # buffer length
def choose(self, skip_length=None):
if skip_length is None:
skip_length = self.skip_length
pos = dsp.randint(self.position, (self.position + self.jump_size) - skip_length)
segment = dsp.cut(self.snd, pos, skip_length)
self.position += dsp.randint(0, self.jump_size)
return segment
num_alts = 5
num_sections = 20
section_length = dsp.stf(20)
snd = dsp.read('shadows.wav').data
player = Player(snd, dsp.stf(20))
out = ''
for section in range(num_sections):
elapsed = 0
ost = player.choose()
alts = [ player.choose() for a in range(num_alts) ]
while elapsed < section_length:
if dsp.rand() < 0.95:
buf = ost
else:
num_skips = dsp.randint(2, 3)
buf = ''.join([ dsp.randchoose(alts) for a in range(num_skips) ])
elapsed += dsp.flen(buf)
out += buf
dsp.write(out, 'skipout5')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment