Skip to content

Instantly share code, notes, and snippets.



Created Jan 16, 2012
What would you like to do?
Function that generates sound of parameter frequency
from struct import pack
from math import sin, pi
import time
from populate import _listen_
def _play_(name, freq, dur, vol, mode='ab'):
""" Generate sound with frequency freq, duration dur, and volume vol """
_dump_ = open(name, mode)
_dump_.write('.snd' + pack('>5L', 24, 8*dur, 2, 8000, 1))
_factor_ = 2 * pi * freq/8000
for count in range(8 * dur):
_wave_ = sin(count * _factor_)
_dump_.write(pack('b', vol * 64 * _wave_))
if __name__=="__main__":
_play_("", 50, 1000, 1, 'ab')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment