Skip to content

Instantly share code, notes, and snippets.

@KaeruCT
Created January 8, 2014 19:33
Show Gist options
  • Save KaeruCT/8323007 to your computer and use it in GitHub Desktop.
Save KaeruCT/8323007 to your computer and use it in GitHub Desktop.
./noise.py | aplay --channels=2 --rate=22500
#!/usr/bin/env python2
# ./noise.py | aplay --channels=2 --rate=22500
import sys
import math
import random
TEMPO=1000
def p(i):
sys.stdout.write(chr(i % 255))
def q(n):
p(int(math.floor(n*100)))
def playfloor(n, freq=1):
a = 0
n *= TEMPO
while a/freq < n:
a += freq
q(math.floor(a))
def playnoise(n):
a = 0
n *= TEMPO
while a < n:
a += 1
q(random.randint(0,254))
def playsin(n, freq=1):
a = 0
n *= TEMPO
while a/freq < n:
a += freq
q(math.cos(a))
def silence(n):
a = 0
n *= TEMPO
while a < n:
a += 1
p(0)
def beat():
playfloor(2, 0.01)
silence(2)
playfloor(2, 0.01)
silence(2)
playnoise(2)
silence(6)
while True:
beat()
for i in range(1, 16):
playsin(1, 0.5*(16-i))
beat()
for i in range(1, 16):
playfloor(1, 0.5*i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment