Natsukl

sample rate tests

Jan 17th, 2024
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # tests by Scar32
  2.  
  3. import wave, struct, math, random
  4. from PIL import Image
  5.  
  6.  
  7. def addsample(S):
  8.     data = struct.pack('<h', S)
  9.     obj.writeframesraw(data)
  10.  
  11. sampleRate = 8008135  # hertz
  12. duration = 1.0  # seconds, this does nothing
  13. frequency = 500  # hertz, this will change the frequency
  14. wavehight = 65534
  15. obj = wave.open(f'wave.wav', 'w')
  16. obj.setnchannels(1)  # mono
  17. obj.setsampwidth(2)
  18. obj.setframerate(sampleRate)
  19. loop = 65534 # how many samples do you want?
  20. for i in range(loop):
  21.     if i % 10 ** 6 == 0:
  22.     print(f"%{i * 100 / loop}")
  23.     addsample(i % wavehight - 32767)
Tags: sound
Advertisement
Add Comment
Please, Sign In to add comment