Skip to content

Commit

Permalink
fix #650 and (hopefully) #646
Browse files Browse the repository at this point in the history
  • Loading branch information
happycube committed Jul 18, 2021
1 parent d8a7669 commit 6c47c3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
30 changes: 7 additions & 23 deletions ld-decode
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from multiprocessing import Process, Pool, Queue, JoinableQueue, Pipe
import threading
import queue

import lddecode.audio as audio
from lddecode.core import *
from lddecode.utils import *
from lddecode.utils_logging import init_logging
Expand Down Expand Up @@ -268,33 +269,17 @@ if args.pal and (args.ntsc or args.ntscj):
audio_pipe = None

if args.newaudio:
spath = os.path.dirname(os.path.realpath(__file__))
cmd = [os.path.join(spath, 'lddecode', 'audio.py'),
'-i', '-',
'-o', outname + '-n']

if args.daa:
cmd.append('--daa')

if args.pal:
cmd.append('--PAL')

if args.prefm:
cmd.append('--preEFM')

if args.noefm:
cmd.append('--noEFM')

if False: # Flip this around when it becomes the default, remove when only
args.daa = True
args.noefm = True
args.prefm = False

audio_process = subprocess.Popen(cmd, stdin=subprocess.PIPE)
if audio_process is None:
print("ERROR: unable to open audio subprocess")

audio_pipe = audio_process.stdin
audio_pipe = Pipe()
audio_process = Process(
target=audio.startprocess, daemon=True, args=(audio_pipe[1], args)
)
audio_process.start()
audio_pipe = audio_pipe[0]

extra_options = {
"useAGC": not args.noAGC,
Expand Down Expand Up @@ -392,7 +377,6 @@ def cleanup():
if audio_pipe is not None:
audio_pipe.close()


while not done and ldd.fields_written < (req_frames * 2):
try:
f = ldd.readfield()
Expand Down
18 changes: 12 additions & 6 deletions lddecode/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class AudioDecoder:
def __init__(self, args):
global blocklen, blockskip

self.args = args
self.efm_fd = None

if args.outfile == '-':
Expand All @@ -170,6 +169,8 @@ def __init__(self, args):
self.efm_pll_object = efm_pll.EFM_PLL()
self.efm_fd = open(args.outfile + '.efm', 'wb')

self.args = args

# Have input_buffer store 8-bit bytes, then convert afterwards
self.input_buffer = utils.StridedCollector(blocklen*2, blockskip*2)

Expand Down Expand Up @@ -198,7 +199,7 @@ def process_input_buffer(self):

fft_in = npfft.fft(s16)

if not args.daa:
if not self.args.daa:

outputs = []

Expand Down Expand Up @@ -249,18 +250,23 @@ def process_input_buffer(self):
def startprocess(inpipe, args):
''' Hook for Multiprocessing.Process()
procargs is a tuple containing the input pipe and args from ld-decode
(The input pipe is expected to be int16 RF data, with provision for odd # of bytes passed)
'''
args.vid_standard = "PAL" if args.pal else "NTSC"

args.inputfreq = 40 if args.inputfreq is None else args.inputfreq
args.outfile = args.outfile + '-new'

ad = AudioDecoder(args)

while True:
data = inpipe.recv()
if data is None:
return

ad.input_buffer.add(np.frombuffer(data, 'int8', len(data)))
# XXX: for now convert to the binary format
data_bytes = data.tobytes()
data_int8 = np.frombuffer(data_bytes, 'int8', len(data_bytes))
ad.input_buffer.add(data_int8)

ad.process_input_buffer()

if __name__ == "__main__":
Expand Down Expand Up @@ -327,7 +333,7 @@ def handle_options(argstring = sys.argv):
exit(1)

args.vid_standard = "PAL" if args.pal else "NTSC"

return args

args = handle_options(sys.argv)
Expand Down
4 changes: 2 additions & 2 deletions lddecode/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2906,7 +2906,7 @@ def process(self):
self.wowfactor = self.computewow(self.linelocs)
self.burstmedian = self.calc_burstmedian()

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

self.linecode = [
Expand Down Expand Up @@ -3379,7 +3379,7 @@ def writeout(self, dataset):
self.outfile_rftbc.write(rftbc)

if self.pipe_rftbc is not None:
self.pipe_rftbc.write(rftbc)
self.pipe_rftbc.send(rftbc)

if audio is not None and self.outfile_audio is not None:
self.outfile_audio.write(audio)
Expand Down

0 comments on commit 6c47c3a

Please sign in to comment.