Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lddecode/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,21 @@ def __init__(
self.outlinecount = (self.rf.SysParams["frame_lines"] // 2) + 1
# this is eventually set to 262/263 and 312/313 for audio timing
self.linecount = None
self.out_scale = np.double(0xD300 - 0x0100) / (
100 - self.rf.DecoderParams["vsync_ire"]
)

@property
def estimated_nextfieldoffset(self):
return self.rf.linelen * 200

#@profile
def process(self):
self.linelocs1, self.linebad, self.nextfieldoffset = self.compute_linelocs()
#print(self.readloc, self.linelocs1, self.nextfieldoffset)
if self.linelocs1 is None:
if self.nextfieldoffset is None:
self.nextfieldoffset = self.rf.linelen * 200
self.nextfieldoffset = self.estimated_nextfieldoffset()

return

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dynamic = ["version"]
[project.optional-dependencies]
hifi_gui = [ "PyQt5>=5.14.1" ]
hifi_gnuradio = [ "pyzmq" ]
fftw3 = [ 'pyfftw' ]

[project.scripts]
ld-decode = "lddecode.main:main"
Expand Down
97 changes: 97 additions & 0 deletions vhsdecode/fft_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import threading
import numpy
from pyfftw.builders._utils import _default_effort, _default_threads, _norm_args
import pyfftw.builders as builders
from pyfftw.pyfftw import empty_aligned, simd_alignment


# Default number of threads to use for FFT
_FFT_DEFAULT_THREADS = 1
_FFT_OBJECTS = dict()


def _Xfftn(a, s, axes, overwrite_input, planner_effort,
threads, auto_align_input, auto_contiguous,
calling_func, normalise_idft=True, ortho=False,
real_direction_flag=None):

calling_thread_id = id(threading.current_thread())
a = numpy.asanyarray(a)

args = (overwrite_input, planner_effort, threads,
auto_align_input, auto_contiguous)

if not a.flags.writeable and overwrite_input:
raise ValueError('overwrite_input cannot be True when the ' +
'input array flags.writeable is False')

alignment = a.ctypes.data % simd_alignment
key = (calling_func, a.shape, a.strides, a.dtype, s.__hash__(),
axes.__hash__(), alignment, args, calling_thread_id)

if key not in _FFT_OBJECTS:
planner_args = (a, s, axes) + args
FFTW_object = getattr(builders, calling_func)(*planner_args)

_FFT_OBJECTS[key] = FFTW_object
return _FFT_OBJECTS[key](normalise_idft=normalise_idft, ortho=ortho)

else:
FFTW_object = _FFT_OBJECTS[key]
orig_output_array = FFTW_object.output_array
output_shape = orig_output_array.shape
output_dtype = orig_output_array.dtype
output_alignment = FFTW_object.output_alignment

output_array = empty_aligned(
output_shape, output_dtype, n=output_alignment)

FFTW_object(input_array=a, output_array=output_array,
normalise_idft=normalise_idft, ortho=ortho)

return output_array


# Wrapper for pyfftw numpy interface
class ThreadSafeFFTW(object):

@staticmethod
def fft(x, axis=-1, threads=_FFT_DEFAULT_THREADS):
calling_func = 'fft'
planner_effort = _default_effort(None)
threads = _default_threads(threads)

return _Xfftn(x, None, axis, False, planner_effort,
threads, False, False,
calling_func, **_norm_args(None))

@staticmethod
def ifft(x, axis=-1, threads=_FFT_DEFAULT_THREADS):
calling_func = 'ifft'
planner_effort = _default_effort(None)
threads = _default_threads(threads)

return _Xfftn(x, None, axis, False, planner_effort,
threads, False, False,
calling_func, **_norm_args(None))

@staticmethod
def rfft(x, threads=_FFT_DEFAULT_THREADS):
calling_func = 'rfft'
planner_effort = _default_effort(None)
threads = _default_threads(threads)

return _Xfftn(x, None, -1, False, planner_effort,
threads, False, False,
calling_func, **_norm_args(None))

@staticmethod
def irfft(x, threads=_FFT_DEFAULT_THREADS):
calling_func = 'irfft'
planner_effort = _default_effort(None)
threads = _default_threads(threads)

return _Xfftn(x, None, -1, False, planner_effort,
threads, False, False,
calling_func, **_norm_args(None))

50 changes: 50 additions & 0 deletions vhsdecode/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,31 @@ def fix_badlines(self, linelocs_in, linelocs_backup_in=None):
class FieldPALShared(FieldShared, ldd.FieldPAL):
def __init__(self, *args, **kwargs):
super(FieldPALShared, self).__init__(*args, **kwargs)
self._start: int = 0
self._startloc: int = 0

@property
def start(self) -> int:
return self._start

@start.setter
def start(self, value: int):
self._start = value

@property
def startloc(self) -> int:
return self._startloc

@startloc.setter
def startloc(self, value: int):
self._startloc = value

@property
def offset(self):
readloc = int(self.start - self.rf.blockcut)
if readloc < 0:
readloc = 0
return self.nextfieldoffset - (readloc - self.startloc)

def refine_linelocs_pilot(self, linelocs=None):
"""Override this as most regular band tape formats does not use have a pilot burst.
Expand All @@ -1089,6 +1114,31 @@ class FieldNTSCShared(FieldShared, ldd.FieldNTSC):
def __init__(self, *args, **kwargs):
super(FieldNTSCShared, self).__init__(*args, **kwargs)
self.fieldPhaseID = 0
self._start: int = 0
self._startloc: int = 0

@property
def start(self) -> int:
return self._start

@start.setter
def start(self, value: int):
self._start = value

@property
def startloc(self) -> int:
return self._startloc

@startloc.setter
def startloc(self, value: int):
self._startloc = value

@property
def offset(self):
readloc = int(self.start - self.rf.blockcut)
if readloc < 0:
readloc = 0
return self.nextfieldoffset - (readloc - self.startloc)

def refine_linelocs_burst(self, linelocs=None):
"""Override this as it's LD specific
Expand Down
5 changes: 2 additions & 3 deletions vhsdecode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,11 @@ def cleanup():

if vhsd.fields_written:
timeused = time.time() - firstdecode
timeused2 = time.time() - seconddecode
frames = vhsd.fields_written // 2
fps = frames / timeused2
fps = frames / timeused

print(
f"\nCompleted: saving JSON and exiting. Took {timeused:.2f} seconds to decode {frames} frames ({fps:.2f} FPS post-setup)",
f"\nCompleted: saving JSON and exiting. Took {timeused:.2f} seconds to decode {frames} frames ({fps:.2f} average FPS)",
file=sys.stderr,
)
else:
Expand Down
Loading