1
0
Fork 0

Adjusted functions to take offsets over arrays

master
colaclanth 2019-07-17 20:22:53 +01:00
parent 4115fb99ab
commit 77b9821c46
1 changed files with 21 additions and 23 deletions

View File

@ -82,13 +82,11 @@ class SSTVDecoder(object):
if header_end is None: if header_end is None:
return None return None
self.mode = self._decode_vis(header_end)
vis_end = header_end + round(spec.VIS_BIT_SIZE * 9 * self._sample_rate) vis_end = header_end + round(spec.VIS_BIT_SIZE * 9 * self._sample_rate)
vis_section = self._samples[header_end:vis_end]
self.mode = self._decode_vis(vis_section) image_data = self._decode_image_data(vis_end)
transmission_area = self._samples[vis_end:]
image_data = self._decode_image_data(transmission_area)
return self._draw_image(image_data) return self._draw_image(image_data)
@ -165,22 +163,22 @@ class SSTVDecoder(object):
err=True) err=True)
return None return None
def _decode_vis(self, vis_section): def _decode_vis(self, vis_start):
"""Decodes the vis from the audio data and returns the SSTV mode""" """Decodes the vis from the audio data and returns the SSTV mode"""
bit_size = round(spec.VIS_BIT_SIZE * self._sample_rate) bit_size = round(spec.VIS_BIT_SIZE * self._sample_rate)
vis_bits = [] vis_bits = []
for bit_idx in range(8): for bit_idx in range(8):
bit_offset = bit_idx * bit_size bit_offset = vis_start + bit_idx * bit_size
section = vis_section[bit_offset:bit_offset+bit_size] section = self._samples[bit_offset:bit_offset+bit_size]
freq = self._peak_fft_freq(section) freq = self._peak_fft_freq(section)
vis_bits.append(int(freq <= 1200)) vis_bits.append(int(freq <= 1200))
# check for even parity in last bit # Check for even parity in last bit
parity = sum(vis_bits) % 2 == 0 parity = sum(vis_bits) % 2 == 0
if not parity: if not parity:
raise ValueError("error decoding VIS header (invalid parity bit)") raise ValueError("Error decoding VIS header (invalid parity bit)")
# LSB first so we must reverse and ignore the parity bit # LSB first so we must reverse and ignore the parity bit
vis_value = 0 vis_value = 0
@ -196,17 +194,17 @@ class SSTVDecoder(object):
return mode return mode
def _align_sync(self, align_section, start_of_sync=True): def _align_sync(self, align_start, start_of_sync=True):
"""Returns sample where the beginning of the sync pulse was found""" """Returns sample where the beginning of the sync pulse was found"""
# TODO - improve this # TODO - improve this
sync_window = round(self.mode.SYNC_PULSE * 1.4 * self._sample_rate) sync_window = round(self.mode.SYNC_PULSE * 1.4 * self._sample_rate)
search_end = len(align_section) - sync_window align_stop = len(self._samples) - sync_window
for current_sample in range(search_end): for current_sample in range(align_start, align_stop):
align_end = current_sample + sync_window section_end = current_sample + sync_window
search_section = align_section[current_sample:align_end] search_section = self._samples[current_sample:section_end]
if self._peak_fft_freq(search_section) > 1350: if self._peak_fft_freq(search_section) > 1350:
break break
@ -218,7 +216,7 @@ class SSTVDecoder(object):
else: else:
return end_sync return end_sync
def _decode_image_data(self, transmission): def _decode_image_data(self, image_start):
"""Decodes image from the transmission section of an sstv signal""" """Decodes image from the transmission section of an sstv signal"""
window_factor = self.mode.WINDOW_FACTOR window_factor = self.mode.WINDOW_FACTOR
@ -227,10 +225,10 @@ class SSTVDecoder(object):
image_data = [] image_data = []
seq_start = 0 seq_start = image_start
if self.mode.HAS_START_SYNC: if self.mode.HAS_START_SYNC:
# Start at the end of the initial sync pulse # Start at the end of the initial sync pulse
seq_start = self._align_sync(transmission, start_of_sync=False) seq_start = self._align_sync(image_start, start_of_sync=False)
for line in range(self.mode.LINE_COUNT): for line in range(self.mode.LINE_COUNT):
image_data.append([]) image_data.append([])
@ -251,7 +249,7 @@ class SSTVDecoder(object):
self._sample_rate) self._sample_rate)
# Align to start of sync pulse # Align to start of sync pulse
seq_start += self._align_sync(transmission[seq_start:]) seq_start = self._align_sync(seq_start)
pixel_time = self.mode.PIXEL_TIME pixel_time = self.mode.PIXEL_TIME
if self.mode.HAS_HALF_SCAN: if self.mode.HAS_HALF_SCAN:
@ -267,10 +265,10 @@ class SSTVDecoder(object):
chan_offset = self.mode.CHAN_OFFSETS[chan] chan_offset = self.mode.CHAN_OFFSETS[chan]
px_sample = round(seq_start + (chan_offset + px * px_pos = round(seq_start + (chan_offset + px *
pixel_time - centre_window_time) * pixel_time - centre_window_time) *
self._sample_rate) self._sample_rate)
pixel_area = transmission[px_sample:px_sample+pixel_window] pixel_area = self._samples[px_pos:px_pos+pixel_window]
freq = self._peak_fft_freq(pixel_area) freq = self._peak_fft_freq(pixel_area)
image_data[line][chan].append(calc_lum(freq)) image_data[line][chan].append(calc_lum(freq))