Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various bug fixes from a working branch #563

Merged
merged 4 commits into from
Oct 18, 2020
Merged
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
15 changes: 11 additions & 4 deletions ld-decode
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parser.add_argument('--start_fileloc', metavar='start_fileloc', type=float, defa
parser.add_argument('-S', '--seek', metavar='seek', type=int, default=-1, help='seek to frame n of capture')
#parser.add_argument('-E', '--end', metavar='end', type=int, default=-1, help='cutting: last frame')
parser.add_argument('-l', '--length', metavar='length', type=int, default = 110000, help='limit length to n frames')
parser.add_argument('-p', '--pal', dest='pal', action='store_true', help='source is in PAL format')
parser.add_argument('-p', '--pal', '--PAL', dest='pal', action='store_true', help='source is in PAL format')
parser.add_argument('-n', '--ntsc', dest='ntsc', action='store_true', help='source is in NTSC format')
#parser.add_argument('-c', '--cut', dest='cut', action='store_true', help='cut (to r16) instead of decode')
parser.add_argument('-m', '--MTF', metavar='mtf', type=float, default=None, help='mtf compensation multiplier')
Expand All @@ -38,7 +38,10 @@ parser.add_argument('--ignoreleadout', dest='ignoreleadout', action='store_true'
parser.add_argument('--verboseVITS', dest='verboseVITS', action='store_true', default=False, help='Enable additional JSON fields')

parser.add_argument('--lowband', dest='lowband', action='store_true', default=False, help='Use more restricted RF settings for noisier disks')
parser.add_argument('--WibbleRemover', dest='WibbleRemover', action='store_true', default=False, help='PAL/digital sound: (try to) remove spurious ~8.5mhz signal. Mitigate interference from analog audio in reds on NTSC')

parser.add_argument('--NTSC_color_notch_filter', dest='NTSC_color_notch_filter', action='store_true', default=False, help='Mitigate interference from analog audio in reds in NTSC captures')
parser.add_argument('--V4300D_notch_filter', dest='V4300D_notch_filter', action='store_true', default=False, help='LD-V4300D PAL/digital audio captures: remove spurious ~8.5mhz signal')

parser.add_argument('-d', '--deemp_adjust', metavar='deemp_adjust', type=float, default=1.0, help='mtf compensation multiplier')

parser.add_argument('-t', '--threads', metavar='threads', type=int, default=5, help='number of CPU threads to use')
Expand All @@ -62,8 +65,12 @@ if args.pal and args.ntsc:

extra_options = {'useAGC': not args.noAGC, 'deemp_level': (args.deemp_adjust, args.deemp_adjust)}

if args.WibbleRemover:
extra_options['WibbleRemover'] = True
if vid_standard == 'NTSC' and args.NTSC_color_notch_filter:
extra_options['NTSC_ColorNotchFilter'] = True

if vid_standard == 'PAL' and args.V4300D_notch_filter:
extra_options['PAL_V4300D_NotchFilter'] = True

if args.lowband:
extra_options['lowband'] = True

Expand Down
27 changes: 16 additions & 11 deletions lddecode/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def __init__(self, inputfreq = 40, system = 'NTSC', blocklen = 32*1024, decode_d
has_analog_audio -- Whether or not analog(ue) audio channels are on the disk

extra_options -- Dictionary of additional options (typically boolean) - these include:
- WibbleRemover - PAL: cut 8.5mhz spurious signal, NTSC: notch filter on decoded video
- PAL_V4300D_NotchFilter - cut 8.5mhz spurious signal
- NTSC_ColorNotchFilter: notch filter on decoded video to reduce color 'wobble'
- lowband: Substitute different decode settings for lower-bandwidth disks

"""
Expand All @@ -323,7 +324,8 @@ def __init__(self, inputfreq = 40, system = 'NTSC', blocklen = 32*1024, decode_d
self.blockcut_end = 0
self.system = system

self.WibbleRemover = True if extra_options.get('WibbleRemover') == True else False
self.NTSC_ColorNotchFilter = True if extra_options.get('NTSC_ColorNotchFilter') == True else False
self.PAL_V4300D_NotchFilter = True if extra_options.get('PAL_V4300D_NotchFilter') == True else False
lowband = True if extra_options.get('lowband') == True else False

freq = inputfreq
Expand Down Expand Up @@ -467,7 +469,7 @@ def computevideofilters(self):
video_lpf = sps.butter(DP['video_lpf_order'], DP['video_lpf_freq']/self.freq_hz_half, 'low')
SF['Fvideo_lpf'] = filtfft(video_lpf, self.blocklen)

if self.system == 'NTSC' and self.WibbleRemover:
if self.system == 'NTSC' and self.NTSC_ColorNotchFilter:
video_notch = sps.butter(3, [DP['video_lpf_freq']/1000000/self.freq_half, 5.0/self.freq_half], 'bandstop')
SF['Fvideo_lpf'] *= filtfft(video_notch, self.blocklen)

Expand Down Expand Up @@ -597,7 +599,7 @@ def demodblock(self, data = None, mtf_level = 0, fftdata = None, cut=False):
rv['rfhpf'] = npfft.ifft(indata_fft * self.Filters['Frfhpf']).real
rv['rfhpf'] = rv['rfhpf'][self.blockcut-rotdelay:-self.blockcut_end-rotdelay]

if self.system == 'PAL' and self.WibbleRemover:
if self.system == 'PAL' and self.PAL_V4300D_NotchFilter:
''' This routine works around an 'interesting' issue seen with LD-V4300D players and
some PAL digital audio disks, where there is a signal somewhere between 8.47 and 8.57mhz.

Expand Down Expand Up @@ -2210,13 +2212,13 @@ def compute_line_bursts(self, linelocs, _line):
print('null')

burstarea = burstarea - nb_mean(burstarea)
threshold = 8 * self.rf.SysParams['hz_ire']
threshold = 5 * self.rf.SysParams['hz_ire']

burstarea_demod = self.data['video']['demod'][s+bstart:s+bend]
burstarea_demod = burstarea_demod - nb_mean(burstarea_demod)

if np.max(np.abs(burstarea_demod)) > (30 * self.rf.SysParams['hz_ire']):
return None, None
return None, None, None

fsc_n1 = (1 / self.rf.SysParams['fsc_mhz'])
zcburstdiv = (lfreq * fsc_n1) / 2
Expand Down Expand Up @@ -2275,7 +2277,7 @@ def refine_linelocs_pilot(self, linelocs = None):
plen = {}

zcs = []
for l in range(0, 312):
for l in range(0, 313):
adjfreq = self.rf.freq
if l > 1:
adjfreq /= (linelocs[l] - linelocs[l - 1]) / self.rf.linelen
Expand All @@ -2299,7 +2301,7 @@ def refine_linelocs_pilot(self, linelocs = None):

am = angular_mean(zcs)

for l in range(0, 312):
for l in range(0, 313):
linelocs[l] += (phase_distance(zcs[l], am) * plen[l]) * 1

return np.array(linelocs)
Expand Down Expand Up @@ -2416,7 +2418,7 @@ def process(self):
self.wowfactor = self.computewow(self.linelocs)
self.burstmedian = self.calc_burstmedian()

self.linecount = 312 if self.isFirstField else 313
self.linecount = 313 #if self.isFirstField else 313
self.lineoffset = 2 if self.isFirstField else 3

self.linecode = [self.decodephillipscode(l + self.lineoffset) for l in [16, 17, 18]]
Expand Down Expand Up @@ -2552,8 +2554,6 @@ def compute_burst_offsets(self, linelocs):
if clb[0] == None:
continue

#print(l, clb)

adjs[l] = clb[1] / 2
burstlevel[l] = self.get_burstlevel(l, linelocs)

Expand Down Expand Up @@ -2666,6 +2666,8 @@ class LDdecode:
def __init__(self, fname_in, fname_out, freader, analog_audio = 0, digital_audio = False, system = 'NTSC', doDOD = True, threads=4, extra_options = {}):
self.demodcache = None

self.branch, self.commit = get_git_info()

self.infile = open(fname_in, 'rb')
self.freader = freader

Expand Down Expand Up @@ -3323,6 +3325,9 @@ def build_json(self, f):
if f is None:
return

vp['gitBranch'] = self.branch
vp['gitCommit'] = self.commit

vp['isSourcePal'] = True if f.rf.system == 'PAL' else False

vp['fsc'] = int(f.rf.SysParams['fsc_mhz'] * 1000000)
Expand Down
18 changes: 18 additions & 0 deletions lddecode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,24 @@ def __call__(self, infile, sample, readlen):
assert len(data) == readlen * 2
return np.frombuffer(data, '<i2')

# Git helpers

def get_git_info():
''' Return git branch and commit for current directory, iff available. '''

branch = 'UNKNOWN'
commit = 'UNKNOWN'

try:
sp = subprocess.run('git rev-parse --abbrev-ref HEAD', shell=True, capture_output=True)
branch = sp.stdout.decode('utf-8').strip() if not sp.returncode else 'UNKNOWN'

sp = subprocess.run('git rev-parse --short HEAD', shell=True, capture_output=True)
commit = sp.stdout.decode('utf-8').strip() if not sp.returncode else 'UNKNOWN'
except:
pass

return branch, commit

# Essential standalone routines

Expand Down