Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created July 2, 2013 16:30
Show Gist options
  • Save thomasballinger/5910849 to your computer and use it in GitHub Desktop.
Save thomasballinger/5910849 to your computer and use it in GitHub Desktop.
example of music stuff
import subprocess
import os
def play_waveform(form):
s = 'echo %s | sox -r 8000 -b 8 -c 1 -t raw -s - -d' % form
print s
os.system(s)
#p = subprocess.Popen(['sox', '-r', '8000', '-b', '8', '-c', '1', '-t', 'raw', '-s', '-', '-d'], stdin=subprocess.PIPE)
#p.stdin.write(form)
print 'asdf'
def make_note(half_steps_above_440, length=1):
cycles = int(8000 / (400 * 2**(float(half_steps_above_440)/12)))
cycle = cycles/2 * 'a' + cycles/2 * 'z'
return int(8000 / len(cycle) * length) * cycle
class Note(object):
def __init__(self, half_steps_above_440, dur):
pass
def get_waveform():
pass
def play(*notes):
play_waveform(''.join([n.get_waveform(8000) for n in notes]))
if __name__ == '__main__':
play_waveform(make_note(0, .5) + make_note(0, .5) + make_note(1, .5) + make_note(3, .5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment