diff --git a/sync_audio_test.py b/sync_audio_test.py index 7f61ed6..7937389 100644 --- a/sync_audio_test.py +++ b/sync_audio_test.py @@ -13,7 +13,7 @@ Run: make ast or .venv/bin/python sync_audio_test.py --config config.toml """ from __future__ import annotations -import os, sys, math, argparse +import os, sys, math, argparse, signal import numpy as np # allow tomllib (py3.11+) with tomli fallback @@ -38,7 +38,7 @@ except ImportError: HAS_SD = False 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: @@ -126,9 +126,9 @@ class SyncWindow(QtWidgets.QMainWindow): # load 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}") - 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 self.a_orig = self.a.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) app = QtWidgets.QApplication(sys.argv) + signal.signal(signal.SIGINT, signal.SIG_DFL) # Dark theme: Fusion style + dark palette (works without kvantum) app.setStyle("Fusion") dark = QtGui.QPalette() diff --git a/verify_sync.py b/verify_sync.py index 636dbfd..ed2062e 100644 --- a/verify_sync.py +++ b/verify_sync.py @@ -22,7 +22,7 @@ Usage: """ 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 locale.setlocale(locale.LC_NUMERIC, "C") @@ -57,7 +57,6 @@ except ImportError: HAS_SD = False from sync_audio import load_wav -from waveform_cache import cached_load_wav # ─── Helpers ─── @@ -206,9 +205,9 @@ class VerifyWindow(QtWidgets.QMainWindow): # Load audio 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}") - 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 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") app = QtWidgets.QApplication(sys.argv) + signal.signal(signal.SIGINT, signal.SIG_DFL) apply_dark_theme(app) w = VerifyWindow(video_path, wav_a, wav_b, sr=sr, lag_sec=lag_sec, diff --git a/waveform_cache.py b/waveform_cache.py deleted file mode 100644 index f99b25a..0000000 --- a/waveform_cache.py +++ /dev/null @@ -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()