Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. %pylab
  2. import wave, struct
  3. maxshort=32767
  4. f0=44000 # sampling rate
  5. wsecs=2 # length of sample in seconds
  6. t=r_[0:wsecs:1/f0]
  7. y1=sin(t*2*pi*440) # define left waveform in the [-1;1] range
  8. y2=sin(t*2*pi*445) # define right waveform in the [-1;1] range
  9. wf=wave.open("d:/tmp/sine1.wav",mode="wb")
  10. wf.setframerate(f0)
  11. wf.setsampwidth(2)
  12. wf.setnchannels(2)
  13. wf.writeframes(struct.pack("<%sh" % (2*len(t)),*[short(round(maxshort*y)) for yp in zip(y1,y2) for y in yp]))
  14. wf.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement