move to arecord

This commit is contained in:
Chris Frankland-Wright 2025-06-24 23:18:41 +01:00
parent 4361edd63f
commit 5bd6a822dd

View file

@ -7,35 +7,35 @@ import time
import select import select
def start_ltc_stream(): def start_ltc_stream():
ffmpeg = subprocess.Popen( # Launch arecord piped into ltcdump
["ffmpeg", "-f", "alsa", "-i", "hw:2", "-ac", "1", "-ar", "48000", "-f", "s16le", "-"], arecord = subprocess.Popen(
["arecord", "-f", "S16_LE", "-c", "1", "-r", "48000", "-D", "hw:2,0"],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL stderr=subprocess.DEVNULL
) )
ltcdump = subprocess.Popen( ltcdump = subprocess.Popen(
["ltcdump", "-f", "-"], ["ltcdump", "-f", "-"],
stdin=ffmpeg.stdout, stdin=arecord.stdout,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
text=True, text=True,
bufsize=1 bufsize=1
) )
ffmpeg.stdout.close() arecord.stdout.close() # Let ltcdump consume the pipe
return ffmpeg, ltcdump return arecord, ltcdump
def main(stdscr): def main(stdscr):
curses.curs_set(0) curses.curs_set(0)
stdscr.nodelay(True) stdscr.nodelay(True)
ffmpeg_proc, ltcdump_proc = start_ltc_stream() arecord_proc, ltcdump_proc = start_ltc_stream()
latest_tc = "⌛ Waiting for LTC..." latest_tc = "⌛ Waiting for LTC..."
last_update = time.time() last_update = time.time()
try: try:
while True: while True:
# Check for new LTC output (non-blocking) # Non-blocking read from ltcdump
rlist, _, _ = select.select([ltcdump_proc.stdout], [], [], 0) rlist, _, _ = select.select([ltcdump_proc.stdout], [], [], 0)
if rlist: if rlist:
line = ltcdump_proc.stdout.readline() line = ltcdump_proc.stdout.readline()
@ -45,17 +45,17 @@ def main(stdscr):
latest_tc = line latest_tc = line
last_update = time.time() last_update = time.time()
# Check if signal or subprocess died # Timeout / error detection
if time.time() - last_update > 1: if time.time() - last_update > 1:
if ltcdump_proc.poll() is not None or ffmpeg_proc.poll() is not None: if ltcdump_proc.poll() is not None or arecord_proc.poll() is not None:
latest_tc = "💥 Decoder crashed or stream stopped" latest_tc = "💥 Decoder crashed or stream stopped"
else: else:
latest_tc = "⚠️ No LTC signal" latest_tc = "⚠️ No LTC signal"
# Draw UI # Draw the curses UI
stdscr.erase() stdscr.erase()
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status") stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
stdscr.addstr(3, 4, "Streaming LTC from default input...") stdscr.addstr(3, 4, "Streaming LTC from hw:2,0...")
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {latest_tc}") stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {latest_tc}")
stdscr.refresh() stdscr.refresh()
@ -66,12 +66,12 @@ def main(stdscr):
stdscr.refresh() stdscr.refresh()
time.sleep(1) time.sleep(1)
finally: finally:
ffmpeg_proc.terminate() arecord_proc.terminate()
ltcdump_proc.terminate() ltcdump_proc.terminate()
if __name__ == "__main__": if __name__ == "__main__":
if not shutil.which("ltcdump") or not shutil.which("ffmpeg"): if not shutil.which("ltcdump") or not shutil.which("arecord"):
print("❌ Required tools not found (ltcdump or ffmpeg). Install and retry.") print("❌ Required tools not found (ltcdump or arecord). Install and retry.")
exit(1) exit(1)
curses.wrapper(main) curses.wrapper(main)