From 2a74c8e114cc4030ceb944071d8f463a7ddcef29 Mon Sep 17 00:00:00 2001 From: Shawn Date: Sat, 13 Jun 2026 22:26:27 -0400 Subject: [PATCH] Sync NAM engine block_size with JACK period on profile switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add FastNAMHost.set_block_size() — reloads current model with new block_size, keeping the engine in sync with JACK's period - Wire into POST /api/audio/profile so NAM engine restarts with correct frame count when switching between standard/low/stable - Prevents sample-alignment drift when JACK period changes but NAM engine stays at old block_size (was causing passthrough) --- src/dsp/nam_engine_host.py | 13 +++++++++++++ src/web/server.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/dsp/nam_engine_host.py b/src/dsp/nam_engine_host.py index ad2b5c2..23d7d4e 100644 --- a/src/dsp/nam_engine_host.py +++ b/src/dsp/nam_engine_host.py @@ -93,6 +93,19 @@ class FastNAMHost: return 0.0 return self._engine.avg_inference_ms + @property + def block_size(self) -> int: + return self._block_size + + def set_block_size(self, block_size: int) -> None: + """Update block size. Reloads current model if loaded.""" + if block_size == self._block_size: + return + self._block_size = block_size + if self._loaded_path: + logger.info("Block size changed to %d — reloading model %s", block_size, self._loaded_path) + self.load_model(self._loaded_path) + # ── Model loading ────────────────────────────────────────────── def load_model(self, model_path: str) -> bool: diff --git a/src/web/server.py b/src/web/server.py index ffe292e..77b1544 100644 --- a/src/web/server.py +++ b/src/web/server.py @@ -1361,6 +1361,10 @@ class WebServer: # Restart JACK audio client if jack_client: jack_client.start() + # Sync NAM engine block size with new period + nam_host = self.deps.nam_host + if nam_host and hasattr(nam_host, 'set_block_size'): + nam_host.set_block_size(profile["period"]) await self._manager.broadcast({ "type": "audio_profile_changed", "profile": profile_key,