diff --git a/verify_sync.py b/verify_sync.py index 0cd5d00..72d8294 100644 --- a/verify_sync.py +++ b/verify_sync.py @@ -103,12 +103,14 @@ def extract_audio_from_mkv(mkv_path: str, stream_index: int, out_wav: str, sr: i def apply_lag(a: np.ndarray, b: np.ndarray, lag_samples: int) -> tuple[np.ndarray, np.ndarray]: if lag_samples >= 0: - a_out = a[lag_samples:] + # B is delayed by lag_samples — pad B with silence, A stays in place b_out = np.concatenate([np.zeros(lag_samples, dtype=np.float32), b]) + a_out = a else: + # A is delayed by |lag_samples| — pad A with silence, B stays in place pad = -lag_samples a_out = np.concatenate([np.zeros(pad, dtype=np.float32), a]) - b_out = b[pad:] + b_out = b ml = min(len(a_out), len(b_out)) return a_out[:ml], b_out[:ml]