From 2a207cf3b8898b2c90ba1f044b4c75cdfe063542 Mon Sep 17 00:00:00 2001 From: Chad Date: Sun, 17 Oct 2021 11:56:26 -0700 Subject: [PATCH 1/3] Fix off-by-one error in PAL RF TBC --- lddecode/core.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lddecode/core.py b/lddecode/core.py index 638df189b..d3271c708 100644 --- a/lddecode/core.py +++ b/lddecode/core.py @@ -1432,11 +1432,12 @@ def downscale_audio( # 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, rf, decode, audio_offset=0, keepraw=True, prevfield=None, initphase=False, readloc = 0 ): self.rawdata = decode["input"] self.data = decode self.initphase = initphase # used for seeking or first field + self.readloc = readloc self.prevfield = prevfield @@ -2496,13 +2497,17 @@ def rf_tbc(self, linelocs=None): # For output consistency reasons, linecount is set to 313 (i.e. 626 lines) # in PAL mode. This needs to be corrected for RF TBC. + startline = self.lineoffset lc = self.linecount - if self.rf.system == "PAL" and not self.isFirstField: - lc = 312 + endline = startline + lc + + if self.rf.system == 'PAL' and lc == 312: + startline += 1 + endline += 1 output = [] - for l in range(self.lineoffset, self.lineoffset + lc): + for l in range(startline, endline): scaled = scale(fdata, linelocs[l] - delay, linelocs[l + 1] - delay, linelen) output.append(np.round(scaled).astype(np.int16)) @@ -3455,6 +3460,7 @@ def decodefield(self, initphase=False): audio_offset=self.audio_offset, prevfield=self.curfield, initphase=initphase, + readloc = self.rawdecode['startloc'] ) try: From 9d8761fd8da5797191858396995e9a9145e36c44 Mon Sep 17 00:00:00 2001 From: Chad Date: Sun, 17 Oct 2021 11:58:55 -0700 Subject: [PATCH 2/3] comment fix --- lddecode/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lddecode/core.py b/lddecode/core.py index d3271c708..a10f8cd59 100644 --- a/lddecode/core.py +++ b/lddecode/core.py @@ -2495,13 +2495,12 @@ def rf_tbc(self, linelocs=None): # Adjust for the demodulation/filtering delays delay = self.rf.delays["video_white"] - # For output consistency reasons, linecount is set to 313 (i.e. 626 lines) - # in PAL mode. This needs to be corrected for RF TBC. startline = self.lineoffset lc = self.linecount endline = startline + lc if self.rf.system == 'PAL' and lc == 312: + # Adjust the first and last lines for PAL so the RF TBC lines up startline += 1 endline += 1 From 7d2c0a26ff96cc41f862ee59939dfee385b26134 Mon Sep 17 00:00:00 2001 From: Chad Date: Sun, 17 Oct 2021 12:04:03 -0700 Subject: [PATCH 3/3] Fix it in a cleaner way, using EFM processing as example --- lddecode/core.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lddecode/core.py b/lddecode/core.py index a10f8cd59..afc65ea74 100644 --- a/lddecode/core.py +++ b/lddecode/core.py @@ -2495,14 +2495,9 @@ def rf_tbc(self, linelocs=None): # Adjust for the demodulation/filtering delays delay = self.rf.delays["video_white"] - startline = self.lineoffset - lc = self.linecount - endline = startline + lc - - if self.rf.system == 'PAL' and lc == 312: - # Adjust the first and last lines for PAL so the RF TBC lines up - startline += 1 - endline += 1 + # On PAL, always ignore self.lineoffset + startline = self.lineoffset if self.rf.system == 'NTSC' else 1 + endline = startline + self.linecount output = []