Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2013 16:18
Show Gist options
  • Select an option

  • Save anonymous/5205991 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/5205991 to your computer and use it in GitHub Desktop.
Some kinda glassy piano nonsense with pippi
from pippi import dsp
def spray(snd, bar, numlayers):
# Transpose original sound up an octave
snd = dsp.transpose(snd, 2)
# Choose a set of time offsets in the source sample
offsets = [ dsp.randint(0, dsp.flen(snd) - dsp.stf(1)) for i in range(numlayers) ]
# Possible divisions of a 'bar'
divs = [4, 8, 10, 12, 16, 24, 32]
layers = []
# Loop through the time offsets and assemble streams of events at
# variable divisions of a 'bar'
for offset in offsets:
# Randomly choose the number of segments to divide a bar into
numchunks = dsp.randchoose(divs)
# Determine the length of each chunk
chunk_length = bar / numchunks
# Cut a chunk from the source starting at the given time offset
chunk = dsp.cut(snd, offset, chunk_length)
# Attenuate the sample
chunk = dsp.amp(chunk, 0.3)
# Alias is a simple bitcrush type effect
chunk = dsp.alias(chunk, split_size=2*dsp.randint(1, 2))
# Apply an amplitude envelope to the chunk
chunk = dsp.env(chunk, 'phasor')
# Copy the chunk enough times to fill a bar, and pan each copy
# to a random stereo position.
chunk = ''.join([ dsp.pan(chunk, dsp.rand()) for c in range(numchunks) ])
# Trim the entire layer or loop until it matches the length of a bar
# to the frame.
chunk = dsp.fill(chunk, bar)
layers += [ chunk ]
# Mix down all of the layers and return
return dsp.mix(layers)
# Reads piano.wav from the current directory
piano = dsp.read('piano.wav').data
# Concat 16 iterations of a 6 second bar, with three layers each
sprays = ''.join([ spray(piano, dsp.stf(6), 3) for i in range(16) ])
# Writes a WAV to piano_sprays.wav in the current directory
dsp.write(sprays, 'piano_sprays')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment