From 5c191f4ac00c28b5fa9e971bda68ead235a8fcc0 Mon Sep 17 00:00:00 2001 From: David Doan Date: Fri, 15 Dec 2023 03:12:09 -0500 Subject: code cleanup --- utils.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'utils.py') diff --git a/utils.py b/utils.py index 253bad6..d6651b3 100644 --- a/utils.py +++ b/utils.py @@ -1,18 +1,13 @@ -# given the cmdline arg, turns the byte sequencies into a list of frequencies, and vice versa -# 1875 1924 +24, -25, range/2, 1, flipping new info 2 sending or not import numpy as np -import pyaudio -import threading from scipy.fftpack import fft - +# converts frequencies to bits def wave_to_bits(wave, starting_freq, freq_range, bytes_per_transmit, chunk=4096, rate=44100): spectrum = fft(wave) spectrum = np.abs(spectrum) spectrum = spectrum / (np.linalg.norm(spectrum) + 1e-16) - # FIXME: update to self values, given if ur a sender or receiver starting_freq = starting_freq end_freq = starting_freq + freq_range freq_to_index_ratio = (chunk - 1) / rate @@ -65,7 +60,7 @@ def play_data(data, start_freq, freq_step, bytes_per_transmit, stream): send_duration = .35 - flip_flag = 0 # TODO: make this global between plays + flip_flag = 0 for byte in data: byte = byte + str(flip_flag) + '1' samples = None @@ -84,8 +79,14 @@ def play_data(data, start_freq, freq_step, bytes_per_transmit, stream): def receive_string(binary): binary_string = ''.join(binary) try: - # print(chr(int(binary_string, 2))) return chr(int(binary_string, 2)) except ValueError: - # print("Warn: Invalid binary data: ", binary_string) return '' + + +def string_to_binary(data): + data_list = [] + for char in data: + binary_representation = format(ord(char), 'b').zfill(8) + data_list.append(binary_representation) + return data_list \ No newline at end of file -- cgit v1.2.3-70-g09d2