mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
decoding, removing the temp wav file and now live decodes
This commit is contained in:
parent
9415bf04eb
commit
632c5be35e
1 changed files with 44 additions and 39 deletions
|
|
@ -2,61 +2,66 @@
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import time
|
||||||
import os
|
|
||||||
|
|
||||||
def read_ltc():
|
def start_ltc_stream():
|
||||||
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
# Launch ffmpeg piped into ltcdump
|
||||||
wav_path = tmp.name
|
ffmpeg = subprocess.Popen(
|
||||||
|
["ffmpeg", "-f", "alsa", "-i", "default", "-ac", "1", "-ar", "48000", "-f", "s16le", "-"],
|
||||||
try:
|
stdout=subprocess.PIPE,
|
||||||
# Record 1 second of audio from default device
|
stderr=subprocess.DEVNULL
|
||||||
subprocess.run([
|
)
|
||||||
"ffmpeg", "-f", "alsa", "-i", "default",
|
ltcdump = subprocess.Popen(
|
||||||
"-t", "1", "-ac", "1", "-ar", "48000", "-y", wav_path
|
["ltcdump", "-f", "-"],
|
||||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
stdin=ffmpeg.stdout,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
# Decode LTC from the recorded file
|
stderr=subprocess.DEVNULL,
|
||||||
result = subprocess.run(
|
text=True
|
||||||
["ltcdump", wav_path],
|
)
|
||||||
capture_output=True,
|
ffmpeg.stdout.close() # Let ltcdump consume the pipe
|
||||||
text=True
|
return ffmpeg, ltcdump
|
||||||
)
|
|
||||||
|
|
||||||
lines = result.stdout.strip().splitlines()
|
|
||||||
ltc_lines = [line for line in lines if line and line[0].isdigit()]
|
|
||||||
|
|
||||||
return ltc_lines[-1] if ltc_lines else "⚠️ No LTC decoded"
|
|
||||||
|
|
||||||
finally:
|
|
||||||
os.remove(wav_path)
|
|
||||||
|
|
||||||
def main(stdscr):
|
def main(stdscr):
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
stdscr.nodelay(True)
|
stdscr.nodelay(True)
|
||||||
|
|
||||||
while True:
|
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
||||||
stdscr.clear()
|
stdscr.addstr(3, 4, "Streaming LTC from default input...")
|
||||||
|
|
||||||
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
ffmpeg_proc, ltcdump_proc = start_ltc_stream()
|
||||||
stdscr.addstr(3, 4, "Reading LTC from default audio input...")
|
|
||||||
|
|
||||||
try:
|
latest_tc = "⌛ Waiting for LTC..."
|
||||||
ltc_timecode = read_ltc()
|
last_refresh = time.time()
|
||||||
except Exception as e:
|
|
||||||
ltc_timecode = f"❌ Error: {e}"
|
|
||||||
|
|
||||||
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {ltc_timecode}")
|
try:
|
||||||
|
while True:
|
||||||
|
stdscr.clear()
|
||||||
|
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
||||||
|
stdscr.addstr(3, 4, "Streaming LTC from default input...")
|
||||||
|
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {latest_tc}")
|
||||||
|
stdscr.refresh()
|
||||||
|
|
||||||
|
# Check if new LTC line available
|
||||||
|
if ltcdump_proc.stdout.readable():
|
||||||
|
line = ltcdump_proc.stdout.readline().strip()
|
||||||
|
if line and line[0].isdigit():
|
||||||
|
latest_tc = line
|
||||||
|
|
||||||
|
# Limit screen redraw to ~10fps
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
stdscr.addstr(8, 6, "🔚 Shutting down...")
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
finally:
|
||||||
|
ffmpeg_proc.terminate()
|
||||||
|
ltcdump_proc.terminate()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Pre-flight check
|
|
||||||
if not shutil.which("ltcdump") or not shutil.which("ffmpeg"):
|
if not shutil.which("ltcdump") or not shutil.which("ffmpeg"):
|
||||||
print("❌ Required tools not found (ltcdump or ffmpeg). Install them and retry.")
|
print("❌ Required tools not found (ltcdump or ffmpeg). Install and retry.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
curses.wrapper(main)
|
curses.wrapper(main)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue