Skip to content

Commit

Permalink
move things around so if there's a crash, it's still possible to acce…
Browse files Browse the repository at this point in the history
…ss Field*
  • Loading branch information
happycube committed Jan 13, 2020
1 parent 135bb25 commit 82b3e34
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 62 deletions.
119 changes: 59 additions & 60 deletions lddecode/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ def __init__(self, inputfreq = 40, system = 'NTSC', blocklen_ = 32*1024, decode_
else:
self.DecoderParams = copy.deepcopy(RFParams_PAL)

if not has_analog_audio:
self.SysParams['analog_audio'] = False
self.SysParams['analog_audio'] = has_analog_audio

linelen = self.freq_hz/(1000000.0/self.SysParams['line_period'])
self.linelen = int(np.round(linelen))
Expand Down Expand Up @@ -350,7 +349,6 @@ def computeefmfilter(self):

self.Filters['Fefm'] = coeffs * 8


def computevideofilters(self):
self.Filters = {}

Expand Down Expand Up @@ -1115,6 +1113,52 @@ def downscale_audio(audio, lineinfo, rf, linecount, timeoffset = 0, freq = 48000

# The Field class contains common features used by NTSC and PAL
class Field:
def __init__(self, rf, decode, audio_offset = 0, keepraw = True, prevfield = None, initphase = False):
self.rawdata = decode['input']
self.data = decode
self.initphase = initphase # used for seeking or first field

self.prevfield = prevfield

self.rf = rf
self.freq = self.rf.freq

self.inlinelen = self.rf.linelen
self.outlinelen = self.rf.SysParams['outlinelen']

self.lineoffset = 0

self.valid = False
self.sync_confidence = 100

self.dspicture = None
self.dsaudio = None
self.audio_offset = audio_offset
self.audio_next_offset = audio_offset

# On NTSC linecount rounds up to 263, and PAL 313
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

def process(self):
self.linelocs1, self.linebad, self.nextfieldoffset = self.compute_linelocs()
if self.linelocs1 is None:
if self.nextfieldoffset is None:
self.nextfieldoffset = self.rf.linelen * 200

return

self.linebad = self.compute_deriv_error(self.linelocs1, self.linebad)

self.linelocs2 = self.refine_linelocs_hsync()
self.linebad = self.compute_deriv_error(self.linelocs2, self.linebad)

self.linelocs = self.linelocs2
self.wowfactor = self.computewow(self.linelocs)

self.valid = True

def get_linefreq(self, l = None):
if l is None or l == 0:
return self.freq
Expand Down Expand Up @@ -1719,8 +1763,6 @@ def downscale(self, lineinfo = None, linesout = None, outwidth = None, channel='
# self.lineoffset is an adjustment for 0-based lines *before* downscaling so add 1 here
lineoffset = self.lineoffset + 1

self.wowfactor = self.computewow(lineinfo)

for l in range(lineoffset, linesout + lineoffset):
if lineinfo[l + 1] > lineinfo[l]:
scaled = scale(self.data['video'][channel], lineinfo[l], lineinfo[l + 1], outwidth, self.wowfactor[l])
Expand Down Expand Up @@ -1783,57 +1825,6 @@ def compute_syncconf(self):
self.sync_confidence = min(self.sync_confidence, newconf)
return int(self.sync_confidence)

def __init__(self, rf, decode, audio_offset = 0, keepraw = True, prevfield = None, initphase = False):
self.rawdata = decode['input']
self.data = decode
self.initphase = initphase # used for seeking or first field

self.prevfield = prevfield

self.rf = rf
self.freq = self.rf.freq

self.inlinelen = self.rf.linelen
self.outlinelen = self.rf.SysParams['outlinelen']

self.lineoffset = 0

self.valid = False
self.sync_confidence = 100

self.dspicture = None
self.dsaudio = None
self.audio_offset = audio_offset
self.audio_next_offset = audio_offset

# On NTSC linecount rounds up to 263, and PAL 313
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.linelocs1, self.linebad, self.nextfieldoffset = self.compute_linelocs()
if self.linelocs1 is None:
if self.nextfieldoffset is None:
self.nextfieldoffset = self.rf.linelen * 200

return

self.linebad = self.compute_deriv_error(self.linelocs1, self.linebad)

self.linelocs2 = self.refine_linelocs_hsync()
self.linebad = self.compute_deriv_error(self.linelocs2, self.linebad)

self.linelocs = self.linelocs2

self.wowfactor = np.ones_like(self.linelocs)

# VBI info
self.valid = True

self.prevfield = None

return

def dropout_detect_demod(self):
# current field
f = self
Expand Down Expand Up @@ -2046,6 +2037,9 @@ def downscale(self, final = False, *args, **kwargs):
def __init__(self, *args, **kwargs):
super(FieldPAL, self).__init__(*args, **kwargs)

def process(self):
super(FieldPAL, self).process()

self.out_scale = np.double(0xd300 - 0x0100) / (100 - self.rf.SysParams['vsync_ire'])

if not self.valid:
Expand All @@ -2060,6 +2054,7 @@ def __init__(self, *args, **kwargs):
else:
self.linelocs = self.fix_badlines(self.linelocs2)

self.wowfactor = self.computewow(self.linelocs)
self.burstmedian = self.calc_burstmedian()

self.linecount = 312 if self.isFirstField else 313
Expand Down Expand Up @@ -2296,12 +2291,17 @@ def __init__(self, *args, **kwargs):
self.burst90 = False

super(FieldNTSC, self).__init__(*args, **kwargs)


def process(self):
super(FieldNTSC, self).process()

self.out_scale = np.double(0xc800 - 0x0400) / (100 - self.rf.SysParams['vsync_ire'])

if not self.valid:
return

self.linecount = 263 if self.isFirstField else 262

self.linecode = [self.decodephillipscode(l + self.lineoffset) for l in [16, 17, 18]]

self.linelocs3, self.burstlevel = self.refine_linelocs_burst(self.linelocs2)
Expand All @@ -2314,10 +2314,8 @@ def __init__(self, *args, **kwargs):
# Now adjust 33 degrees (-90 - 33) for color decoding
shift33 = 84 * (np.pi / 180)
self.linelocs = self.apply_offsets(self.linelocs3, -shift33 - 0)

self.linecount = 263 if self.isFirstField else 262

#self.downscale(final=True)
self.wowfactor = self.computewow(self.linelocs)

class CombNTSC:
''' *partial* NTSC comb filter class - only enough to do VITS calculations ATM '''
Expand Down Expand Up @@ -2588,6 +2586,7 @@ def decodefield(self, initphase = False):
self.indata = self.rawdecode['input']

f = self.FieldClass(self.rf, self.rawdecode, audio_offset = self.audio_offset, prevfield = self.curfield, initphase = initphase)
f.process()
self.curfield = f

if not f.valid:
Expand Down
4 changes: 2 additions & 2 deletions notebooks/devbook_base.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -97,7 +97,7 @@
}
],
"source": [
"filename = '../../ld-decode-testdata/he010_cbar.lds'\n",
"filename = '/home/cpage/ld-decode-testdata/he010_cbar.lds'\n",
"outname = 'devbook'\n",
"system = 'NTSC'\n",
"foutput = False\n",
Expand Down

0 comments on commit 82b3e34

Please sign in to comment.