fix: made crtl+c work
This commit is contained in:
1 parent
4c8ac4f9b7
commit
82f9e6baea
3 files changed
+9
-37
No files matched your search
+5
-4
@@ -13,7 +13,7 @@ Run: make ast or .venv/bin/python sync_audio_test.py --config config.toml
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import os, sys, math, argparse
|
import os, sys, math, argparse, signal
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
# allow tomllib (py3.11+) with tomli fallback
|
# allow tomllib (py3.11+) with tomli fallback
|
||||||
@@ -38,7 +38,7 @@ except ImportError:
|
|||||||
HAS_SD = False
|
HAS_SD = False
|
||||||
|
|
||||||
from sync_audio import load_wav, correlate, device_info, lag_to_seconds
|
from sync_audio import load_wav, correlate, device_info, lag_to_seconds
|
||||||
from waveform_cache import cached_load_wav
|
|
||||||
|
|
||||||
|
|
||||||
def load_config(path: str) -> dict:
|
def load_config(path: str) -> dict:
|
||||||
@@ -126,9 +126,9 @@ class SyncWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
# load
|
# load
|
||||||
print(f"Loading {a_path}")
|
print(f"Loading {a_path}")
|
||||||
self.a, self.sr_a = cached_load_wav(a_path, target_sr=sr)
|
self.a, self.sr_a = load_wav(a_path, target_sr=sr)
|
||||||
print(f"Loading {b_path}")
|
print(f"Loading {b_path}")
|
||||||
self.b, self.sr_b = cached_load_wav(b_path, target_sr=sr)
|
self.b, self.sr_b = load_wav(b_path, target_sr=sr)
|
||||||
# keep originals for lag apply
|
# keep originals for lag apply
|
||||||
self.a_orig = self.a.copy()
|
self.a_orig = self.a.copy()
|
||||||
self.b_orig = self.b.copy()
|
self.b_orig = self.b.copy()
|
||||||
@@ -523,6 +523,7 @@ def main():
|
|||||||
print(f"ERROR: B not found {b_path}", file=sys.stderr); sys.exit(1)
|
print(f"ERROR: B not found {b_path}", file=sys.stderr); sys.exit(1)
|
||||||
|
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
# Dark theme: Fusion style + dark palette (works without kvantum)
|
# Dark theme: Fusion style + dark palette (works without kvantum)
|
||||||
app.setStyle("Fusion")
|
app.setStyle("Fusion")
|
||||||
dark = QtGui.QPalette()
|
dark = QtGui.QPalette()
|
||||||
|
|||||||
+4
-4
@@ -22,7 +22,7 @@ Usage:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import os, sys, math, argparse, subprocess, json, shutil, threading, tempfile, warnings, locale
|
import os, sys, math, argparse, subprocess, json, shutil, threading, tempfile, warnings, locale, signal
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
locale.setlocale(locale.LC_NUMERIC, "C")
|
locale.setlocale(locale.LC_NUMERIC, "C")
|
||||||
@@ -57,7 +57,6 @@ except ImportError:
|
|||||||
HAS_SD = False
|
HAS_SD = False
|
||||||
|
|
||||||
from sync_audio import load_wav
|
from sync_audio import load_wav
|
||||||
from waveform_cache import cached_load_wav
|
|
||||||
|
|
||||||
|
|
||||||
# ─── Helpers ───
|
# ─── Helpers ───
|
||||||
@@ -206,9 +205,9 @@ class VerifyWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
# Load audio
|
# Load audio
|
||||||
print(f"Loading audio A: {wav_a_path}")
|
print(f"Loading audio A: {wav_a_path}")
|
||||||
self.a_orig, _ = cached_load_wav(wav_a_path, target_sr=sr)
|
self.a_orig, _ = load_wav(wav_a_path, target_sr=sr)
|
||||||
print(f"Loading audio B: {wav_b_path}")
|
print(f"Loading audio B: {wav_b_path}")
|
||||||
self.b_orig, _ = cached_load_wav(wav_b_path, target_sr=sr)
|
self.b_orig, _ = load_wav(wav_b_path, target_sr=sr)
|
||||||
|
|
||||||
# Apply lag alignment
|
# Apply lag alignment
|
||||||
self.a_aligned, self.b_aligned = apply_lag(self.a_orig, self.b_orig, self.lag_samples)
|
self.a_aligned, self.b_aligned = apply_lag(self.a_orig, self.b_orig, self.lag_samples)
|
||||||
@@ -649,6 +648,7 @@ def main():
|
|||||||
print(f"Lag: {lag_sec:+.6f}s")
|
print(f"Lag: {lag_sec:+.6f}s")
|
||||||
|
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
apply_dark_theme(app)
|
apply_dark_theme(app)
|
||||||
|
|
||||||
w = VerifyWindow(video_path, wav_a, wav_b, sr=sr, lag_sec=lag_sec,
|
w = VerifyWindow(video_path, wav_a, wav_b, sr=sr, lag_sec=lag_sec,
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
"""
|
|
||||||
Shared waveform cache — avoids re-reading and re-decoding large WAV files
|
|
||||||
when the same file is loaded multiple times (e.g. sync_audio_test → verify).
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
import os
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
_cache: dict[tuple[str, int], np.ndarray] = {}
|
|
||||||
|
|
||||||
|
|
||||||
def cached_load_wav(path: str, target_sr: int = 48000) -> tuple[np.ndarray, int]:
|
|
||||||
"""Load a WAV file with caching. Returns (audio_array, sample_rate)."""
|
|
||||||
real_path = os.path.realpath(path)
|
|
||||||
key = (real_path, target_sr)
|
|
||||||
if key in _cache:
|
|
||||||
print(f" (cached: {os.path.basename(path)})")
|
|
||||||
return _cache[key].copy(), target_sr
|
|
||||||
|
|
||||||
# Import here to avoid circular imports
|
|
||||||
from sync_audio import load_wav
|
|
||||||
data, sr = load_wav(path, target_sr=target_sr)
|
|
||||||
_cache[key] = data
|
|
||||||
return data, sr
|
|
||||||
|
|
||||||
|
|
||||||
def clear_cache():
|
|
||||||
_cache.clear()
|
|
||||||
Reference in new issue
Block a user