fix: pad delayed signal instead of trimming leading samples in apply_lag
This commit is contained in:
1 parent
a8ff659bd3
commit
1a2deb88a0
1 file changed
+4
-2
+4
-2
@@ -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]
|
||||
|
||||
|
||||
Reference in new issue
Block a user