chore: remove unused imports and dead code
This commit is contained in:
1 parent
4404dda926
commit
27a1fc7851
5 files changed
+6
-77
No files matched your search
+3
-19
@@ -15,7 +15,6 @@ Usage:
|
||||
from __future__ import annotations
|
||||
import os
|
||||
import sys
|
||||
import math
|
||||
from typing import Tuple, Literal
|
||||
|
||||
import numpy as np
|
||||
@@ -120,24 +119,14 @@ def correlate(
|
||||
# fftshift to center 0 lag
|
||||
corr_t = torch.roll(corr_t, shifts=N // 2)
|
||||
corr = corr_t.cpu().numpy()
|
||||
# keep only valid length n centered
|
||||
start = N // 2 - (len(b) - 1)
|
||||
# Actually after roll, we want slice; simpler: use raw without roll and map lag later
|
||||
# Recompute without roll for correct indexing, keep roll for display but fix lag calc
|
||||
# For lag calc we need not shift: peak at N - lag etc. So we use shifted version + offset mapping
|
||||
# To avoid confusion, return shifted corr and map lag accordingly
|
||||
peak_idx = int(np.argmax(np.abs(corr)))
|
||||
# lag = peak_idx - (len(b)-1) - (N//2 - (len(b)-1))? Let's instead use unshifted for lag and shifted for display
|
||||
# Fallback: compute lag from unshifted
|
||||
# compute lag from unshifted correlation for correct indexing
|
||||
corr_raw = torch.fft.irfft(R, n=N).cpu().numpy()
|
||||
peak_raw = int(np.argmax(np.abs(corr_raw)))
|
||||
# raw layout: lag 0 at 0, positive lag (b delayed) wraps to end
|
||||
if peak_raw > N // 2:
|
||||
lag = peak_raw - N
|
||||
else:
|
||||
lag = peak_raw
|
||||
peak_val = float(np.abs(corr_raw[peak_raw]))
|
||||
# return shifted display corr + lag
|
||||
return lag, peak_val, corr
|
||||
except Exception as e:
|
||||
print(f"torch cuda failed ({e}), falling back cpu", file=sys.stderr)
|
||||
@@ -156,10 +145,7 @@ def correlate(
|
||||
else:
|
||||
lag = peak_raw
|
||||
peak_val = float(np.abs(corr_raw[peak_raw]))
|
||||
# shifted for display centered at 0
|
||||
corr_shifted = np.fft.fftshift(corr_raw)
|
||||
# but we return raw shifted centered? Provide shifted for plotting
|
||||
# For consistency with torch branch we return shifted display array
|
||||
return lag, peak_val, corr_shifted
|
||||
|
||||
|
||||
@@ -170,9 +156,7 @@ def lag_to_seconds(lag_samples: int, sr: int = 48000) -> float:
|
||||
def apply_lag_with_silence(wav: np.ndarray, lag_samples: int) -> np.ndarray:
|
||||
"""
|
||||
Apply lag by padding silence at start (no sound for delay).
|
||||
lag >0: b delayed vs a => pad b at start with lag silence to align to a, or trim a.
|
||||
For mux: if lag>0 (b starts later), we need to delay a by lag or提前 b.
|
||||
This helper pads with zeros (silence) at start; negative lag pads the other direction.
|
||||
lag > 0: b delayed vs a. lag < 0: a delayed vs b.
|
||||
Caller decides which file to pad.
|
||||
"""
|
||||
if lag_samples == 0:
|
||||
@@ -200,7 +184,7 @@ def device_info() -> str:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse, pathlib
|
||||
import argparse
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("a", help="wav A")
|
||||
ap.add_argument("b", help="wav B")
|
||||
|
||||
Reference in new issue
Block a user