Created
May 19, 2016 21:12
-
-
Save bzamecnik/a2d45dc0addb8d602d70b1d8df0f9fd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# ByteBeats - byte-level procedural music | |
# | |
# Source: Jamey at Royal Paw | |
# http://royal-paw.com/2012/01/bytebeats-in-c-and-python-generative-symphonies-from-extremely-small-programs/ | |
# | |
# Adapted to run in a single script. | |
# | |
# run as: | |
# $ python bytebeats.py 0 | sox -r 8000 -b 8 -c 1 -t raw -e signed-integer - -d | |
# | |
# - choose the preset or write your own songs! | |
# - play with various sampling rate (sox -r). | |
from __future__ import print_function | |
import sys | |
def play_loop(f): | |
t = 0 | |
while True: | |
print(chr(int(f(t)) % 256), end="") | |
t += 1 | |
# function of time-step, produces a single byte value | |
kernels = [ | |
lambda t: t*((15&t>>11)%12)&55-(t>>5|t>>12)|t*(t>>10)*32, | |
# blippy, epic | |
lambda t: (t*((15&t>>11)%12)&55-(t>>5|t>>12)|t*(t>>10)*32)-1, | |
# atmospheric, hopeful | |
lambda t: t*3&(t>>10)|t*12&(t>>10)|t*10&((t>>8)*55)&128, | |
# expansive rumbles | |
lambda t: t*4&(t>>10)|t*4&(t*6>>8)&t|64, | |
# electric, repetitive | |
lambda t: t*(t+(t>>9|t>>13))%40&120, | |
] | |
if __name__ == '__main__': | |
play_loop(kernels[int(sys.argv[1])]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment