Using python to play two sine tones at once
Posted
by Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-04-03T20:57:12Z
Indexed on
2010/04/03
21:13 UTC
Read the original article
Hit count: 473
I'm using python to play a sine tone. The tone is based off the computer's internal time in minutes, but I'd like to simultaneously play one based off the second for a harmonized or dualing sound.
This is what I have so far; can someone point me in the right direction?
from struct import pack
from math import sin, pi
import time
def au_file(name, freq, dur, vol):
fout = open(name, 'wb')
# header needs size, encoding=2, sampling_rate=8000, channel=1
fout.write('.snd' + pack('>5L', 24, 8*dur, 2, 8000, 1))
factor = 2 * pi * freq/8000
# write data
for seg in range(8 * dur):
# sine wave calculations
sin_seg = sin(seg * factor)
fout.write(pack('b', vol * 127 * sin_seg))
fout.close()
t = time.strftime("%S", time.localtime())
ti = time.strftime("%M", time.localtime())
tis = float(t)
tis = tis * 100
tim = float(ti)
tim = tim * 100
if __name__ == '__main__':
au_file(name='timeSound1.au', freq = tim, dur=1000, vol=1.0)
import os
os.startfile('timeSound1.au')
© Stack Overflow or respective owner