aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-15 03:12:09 -0500
committerDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-15 03:12:09 -0500
commit5c191f4ac00c28b5fa9e971bda68ead235a8fcc0 (patch)
tree22f48dbc0f2d72dde54c7fb9e6373d15641df973 /utils.py
parentdb626076acc73fbcd499b3235bf4503c22b47e2b (diff)
code cleanup
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py19
1 files changed, 10 insertions, 9 deletions
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