Created
August 15, 2011 22:43
-
-
Save adamgreig/1148073 to your computer and use it in GitHub Desktop.
This file contains 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
# Try generating RTTY WAV files in Python | |
import fileinput | |
import wave | |
import numpy | |
string = ''.join(line for line in fileinput.input()) | |
baud = 50.0 | |
tone_duration = 1.0/50.0 | |
samplerate = 8000.0 | |
samples = tone_duration * samplerate | |
frequency_mark = 500.0 | |
frequency_space = 1000.0 | |
period_mark = samplerate / frequency_mark | |
period_space = samplerate / frequency_space | |
omega_mark = numpy.pi * 2.0 / period_mark | |
omega_space = numpy.pi * 2.0 / period_space | |
x_mark = numpy.arange(int(period_mark), dtype=numpy.float) * omega_mark | |
x_space = numpy.arange(int(period_space), dtype=numpy.float) * omega_space | |
y_mark = 2**14 * numpy.sin(x_mark) | |
y_space = 2**14 * numpy.sin(x_space) | |
mark = numpy.resize(y_mark, (samples,)) | |
space = numpy.resize(y_space, (samples,)) | |
binary_mark = '' | |
for i in range(len(mark)): | |
binary_mark += wave.struct.pack('h', mark[i]) | |
binary_space = '' | |
for i in range(len(space)): | |
binary_space += wave.struct.pack('h', space[i]) | |
wav = wave.open('rtty3.wav', 'wb') | |
wav.setnchannels(1) | |
wav.setsampwidth(2) | |
wav.setframerate(samplerate) | |
data = [] | |
for i in xrange(30): | |
wav.writeframes(binary_mark) | |
for char in string: | |
binary = ord(char) | |
wav.writeframes(binary_space) | |
for shift in range(7): | |
if binary & (1<<shift): | |
wav.writeframes(binary_mark) | |
else: | |
wav.writeframes(binary_space) | |
wav.writeframes(binary_mark) | |
wav.writeframes(binary_mark) | |
wav.writeframes(binary_mark) | |
wav.writeframes(binary_mark) | |
wav.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Adam,
Thanks for the code! I can get it to generate tones but I can't get the test strings back. Were you able to produce RTTY files that could be decoded by a software modem? If so, what settings did you use?
-Doug