Advertisement
Locoluis

WAV writing sample, a single note in one second (44100 Hz)

Mar 22nd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. import wave
  2. import math
  3. f = wave.open("test.wav", "wb")
  4. f.setnchannels(1)
  5. f.setframerate(44100)
  6. f.setsampwidth(1)
  7. #for frec in [261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.00, 415.30, 440.00, 466.16, 493.88, 523.25]:
  8. ampl = 96.0
  9. for frec in [440.00]:
  10.         data = bytearray()
  11.         for i in range(44100):
  12.                 data += chr(int(math.sin((i / 44100.0) * math.pi * frec * 2.0) * ampl + 128.0))
  13.         f.writeframesraw(data)
  14. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement