mirror of
https://git.exozy.me/a/Never-Gonna-Give-Beep-Up
synced 2026-03-04 03:01:35 +00:00
Commit all testing programs
This commit is contained in:
parent
ef083f3740
commit
80e92d1cab
5 changed files with 151 additions and 6 deletions
46
beepemu-pyaudio
Executable file
46
beepemu-pyaudio
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import pyaudio
|
||||
|
||||
p = pyaudio.PyAudio()
|
||||
sample_rate=44100
|
||||
stream = p.open(
|
||||
format=pyaudio.paInt16,
|
||||
channels=1,
|
||||
rate=sample_rate,
|
||||
output=True
|
||||
)
|
||||
stream.start_stream()
|
||||
|
||||
i = 1
|
||||
f = 0
|
||||
l = 0
|
||||
while i < len(sys.argv):
|
||||
if sys.argv[i] == '-f':
|
||||
i += 1
|
||||
f = float(sys.argv[i])
|
||||
elif sys.argv[i] == '-l':
|
||||
i += 1
|
||||
l = float(sys.argv[i])/1000
|
||||
elif sys.argv[i] == '-D':
|
||||
i += 1
|
||||
time.sleep(float(sys.argv[i])/1000)
|
||||
if f != 0 and l != 0:
|
||||
print(f, l)
|
||||
# https://stackoverflow.com/questions/974071/python-library-for-playing-fixed-frequency-sound
|
||||
num_samples = int(sample_rate * l)
|
||||
rest_frames = num_samples % sample_rate
|
||||
s = lambda i: 0.25 * math.sin(2 * math.pi * f * i / sample_rate)
|
||||
samples = (int(s(i) * 0x7F + 0x80) for i in range(num_samples))
|
||||
# write several samples at a time
|
||||
for buf in zip( *([samples] * sample_rate) ):
|
||||
stream.write(bytes(buf))
|
||||
# fill remainder of frameset with silence
|
||||
stream.write(b'\x80' * rest_frames)
|
||||
f = 0
|
||||
l = 0
|
||||
i += 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue