Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from struct import pack
- from math import sin, pi
- import time
- x=0
- lines=[0,0,0,0,0,0]
- f=[523.25,587.33,659.26,783.99,880]
- def freq(i):
- return f[i%len(f)] * 2**(i/len(f))
- def saw(phase):
- phase = phase%2
- return phase-1
- def tri(phase):
- phase = phase%2
- if(phase>1):
- phase = 2-phase
- return -1 + 2*phase
- fout = open('output.au', 'wb')
- rate = 44100
- leng = 750
- phase = 0.0
- phase2 = 0.0
- dur = rate/10
- # header needs size, encoding=2(8 bit pcm), sampling_rate=8000, channel=1
- fout.write('.snd' + pack('>5L', 24, dur*leng, 2, rate, 1))
- for i in range(leng):
- lines[x] = raw_input().count(" ");
- x2 = (x+1)%len(lines)
- for seg in range(dur):
- #step = 2**(lines[x]/6.0) * 880 / rate
- step = freq(lines[x]) / rate
- phase = phase + step
- #sin_seg = tri(phase)
- #step = 2**(lines[x]/6.0) * 880 / rate
- step = freq(lines[x2]) / rate
- phase2 = phase2 + step
- sin_seg = tri(phase) + tri(phase2)
- fout.write(pack('b', 63 * sin_seg))
- x=x2
- fout.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement