Home

dev / openkara

publicthedavidweng/OpenKara· sync paused
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

feat(separator): native STFT/ISTFT for the spectral contract v1 (#172) (#186)

2 months ago

ec4f86f
Authored
Davy7/25/2026, 6:10:07 AM
Implement the pure DSP layer of openkara.spectral-contract/v1 (issue #172
PR 1): a native FFT port of the float64 numpy reference that defines the
waveform<->spectral transform semantics of the shipped HTDemucs graphs.

- Add `realfft` (already resolved transitively via rubato; pure Rust,
  MIT/Apache-2.0, cargo-deny clean) as a direct dependency.
- New `separator::spectral` module with reusable `SpectralPlans`
  (forward/inverse FFT plans, periodic-Hann window, ISTFT window-square
  envelope, and scratch buffers created once and reused): `spec`, `ispec`,
  and the `magnitude` neural-core view helper, plus the contract constants
  and `SPECTRAL_CONTRACT_VERSION`.
- Transforms run in f64 internally and cast to f32 at the boundary, landing
  far under the 1e-3 fp32 contract gate (worst achieved max-abs: spec/mag
  1.2e-10, ispec 7.3e-12 across the golden fixtures).
- Torch/numpy-style reflect padding (no repeated edge sample; repeated
  reflection for very short inputs is documented as out of the validated
  regime).
- Commit the five digest-pinned golden `.npz` fixtures plus
  spectral-golden-v1.json / manifest.json under tests/fixtures/spectral/.
- `tests/phase7_spectral.rs` verifies every fixture's SHA-256 before use and
  validates spec / magnitude / ispec against the golden vectors; unit tests
  cover window periodicity, the COLA envelope, envelope clamp, reflect-pad
  edge cases, shape math, and plan reuse.
- Document the native contract in docs/references/contracts/spectral.md.

No production model / ORT session path in this PR (issue #172 PR 2, blocked
on openkara-models#23).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

Parentbd90d76

13 files changed
  • docs/references/contracts/spectral.md+74−0
  • src-tauri/Cargo.lock+1−0
  • src-tauri/Cargo.toml+1−0
  • src-tauri/src/separator/mod.rs+1−0
  • src-tauri/src/separator/spectral.rs+580−0
  • src-tauri/tests/fixtures/spectral/bandlimited-noise-10240.npz——
  • src-tauri/tests/fixtures/spectral/impulse-10240.npz——
  • src-tauri/tests/fixtures/spectral/manifest.json
+218
−0
  • src-tauri/tests/fixtures/spectral/silence-10240.npz——
  • src-tauri/tests/fixtures/spectral/spectral-golden-v1.json+272−0
  • src-tauri/tests/fixtures/spectral/sweep-10000.npz——
  • src-tauri/tests/fixtures/spectral/tone440-10240.npz——
  • src-tauri/tests/phase7_spectral.rs+241−0