Created
February 8, 2019 16:11
-
-
Save chadmiller/3a692e3c7b1ee863c9564d96698fca6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
""":" | |
# Run a pulseaudio wrapper. Fancy ugly hack. | |
exec padsp -d python3 "$0" "$@" | |
""" | |
import struct | |
import numpy | |
from scipy import signal | |
sampling_rate_hz = 8000 | |
freq_hz = 261.63 | |
sample_count = 8000 | |
sample_positions = numpy.arange(sample_count) | |
sinewave = 100 * numpy.sin(2*numpy.pi * freq_hz * sample_positions / sampling_rate_hz) | |
# squarewave = 100 * signal.square(2*numpy.pi * freq_hz * sample_positions / sampling_rate_hz) # square wave | |
# y = 100 * signal.square(2*numpy.pi * freq_hz * sample_positions / sampling_rate_hz, duty = 0.8) # square wave with Duty Cycle | |
# y = 100 * signal.sawtooth(2*numpy.pi * freq_hz * sample_positions / sampling_rate_hz) # Sawtooth wave | |
with open('/dev/dsp','wb') as dsp: | |
while True: | |
for each_value in sinewave: | |
dsp.write(struct.pack('b', int(round(each_value)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment