aboutsummaryrefslogtreecommitdiff
path: root/visualize.py
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-14 21:40:35 -0500
committerDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-14 21:40:35 -0500
commitd7384329b2ae615ef7d637e31f214dbe648ae418 (patch)
tree7f0fb02210a2da8b820372f5ea3a78041f390433 /visualize.py
parent0fef1fc043bddbcaf467d1f35027bde60326e227 (diff)
parentb66e659ba40b84dbf75e09d5463e2aef1a39b718 (diff)
pull
Diffstat (limited to 'visualize.py')
-rw-r--r--visualize.py35
1 files changed, 3 insertions, 32 deletions
diff --git a/visualize.py b/visualize.py
index 759cf34..23016a0 100644
--- a/visualize.py
+++ b/visualize.py
@@ -45,37 +45,8 @@ class Test(object):
scaled_spectrum = np.abs(spectrum)
scaled_spectrum = scaled_spectrum / (np.linalg.norm(scaled_spectrum) + 1e-16)
- # FIXME: update to self values, given if ur a sender or receiver
- starting_freq = 19800
- end_freq = 20000
- freq_to_index_ratio = self.CHUNK / self.RATE
- # only accept the scaled spectrum from our starting range to 20000 Hz
- starting_range_index = int(starting_freq * freq_to_index_ratio)
- ending_range_index = int(end_freq * freq_to_index_ratio)
- print(starting_freq, end_freq, starting_range_index, ending_range_index)
- restricted_spectrum = scaled_spectrum[starting_range_index:ending_range_index + 1]
-
- # normalize the restricted spectrum
- indices = np.argwhere(restricted_spectrum > .125)
- print(indices)
-
- freqs = [int((indices[i] + starting_range_index) / freq_to_index_ratio) for i in range(len(indices))]
- print(freqs)
-
- p = u.frequencies_to_bytes(freqs, u.calculate_send_frequencies(19800, 200, 1))
- data = p[:8]
- print(data)
- u.receive_string(data)
-
- # get the n indices of the max peaks, within our confined spectrum
- # FIXME: update to self values
- bytes = 1
- num_bits = bytes * 8 + 2
- if num_bits > len(restricted_spectrum):
- print("ERROR: num_bits > len(restricted_spectrum)")
-
- # print(index_to_freq[max_index], max_index, max_index * self.RATE / (self.CHUNK - 1))
- return freqs, scaled_spectrum
+ # get the index of the max
+ return scaled_spectrum
def read_audio_stream(self):
data = self.stream.read(self.CHUNK)
@@ -86,7 +57,7 @@ class Test(object):
self.init_plots()
while not self.pause:
waveform = self.read_audio_stream()
- freq_max, scaled_spectrum = self.get_fundamental_frequency(waveform)
+ scaled_spectrum = self.get_fundamental_frequency(waveform)
# update figure canvas if wanted
if graphics: