Commit
·
6460c54
1
Parent(s):
a9330a3
lets gooooo
Browse files- jam_worker.py +20 -6
jam_worker.py
CHANGED
@@ -298,24 +298,28 @@ class JamWorker(threading.Thread):
|
|
298 |
out = out[:, :depth]
|
299 |
return out
|
300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
def _prepare_stream_for_reseed_handoff(self):
|
302 |
-
"""
|
303 |
-
Keep only a tiny tail to crossfade against the FIRST post-reseed chunk.
|
304 |
-
Reset the emit pointer so the next emitted window starts fresh.
|
305 |
-
"""
|
306 |
sr = int(self.mrt.sample_rate)
|
307 |
xfade_s = float(self.mrt.config.crossfade_length)
|
308 |
xfade_n = int(round(xfade_s * sr))
|
309 |
|
310 |
-
# If we have a stream, keep just a tail to crossfade with
|
311 |
if getattr(self, "_stream", None) is not None and self._stream.shape[0] > 0:
|
312 |
tail = self._stream[-xfade_n:] if self._stream.shape[0] > xfade_n else self._stream
|
313 |
self._stream = tail.copy()
|
314 |
else:
|
315 |
self._stream = None
|
316 |
|
317 |
-
# Start a new emission sequence aligned to the new context
|
318 |
self._next_emit_start = 0
|
|
|
319 |
|
320 |
def reseed_splice(self, recent_wav, anchor_bars: float):
|
321 |
"""
|
@@ -371,6 +375,16 @@ class JamWorker(threading.Thread):
|
|
371 |
self.last_chunk_started_at = time.time()
|
372 |
wav, self.state = self.mrt.generate_chunk(state=self.state, style=style_vec)
|
373 |
self._append_model_chunk_to_stream(wav)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
374 |
self.last_chunk_completed_at = time.time()
|
375 |
|
376 |
# While we have at least one full 8-bar window available, emit it
|
|
|
298 |
out = out[:, :depth]
|
299 |
return out
|
300 |
|
301 |
+
def _realign_emit_pointer_to_bar(self, sr_model: int):
|
302 |
+
"""Advance _next_emit_start to the next bar boundary in model-sample space."""
|
303 |
+
bar_samps = int(round(self._seconds_per_bar() * sr_model))
|
304 |
+
if bar_samps <= 0:
|
305 |
+
return
|
306 |
+
phase = self._next_emit_start % bar_samps
|
307 |
+
if phase != 0:
|
308 |
+
self._next_emit_start += (bar_samps - phase)
|
309 |
+
|
310 |
def _prepare_stream_for_reseed_handoff(self):
|
|
|
|
|
|
|
|
|
311 |
sr = int(self.mrt.sample_rate)
|
312 |
xfade_s = float(self.mrt.config.crossfade_length)
|
313 |
xfade_n = int(round(xfade_s * sr))
|
314 |
|
|
|
315 |
if getattr(self, "_stream", None) is not None and self._stream.shape[0] > 0:
|
316 |
tail = self._stream[-xfade_n:] if self._stream.shape[0] > xfade_n else self._stream
|
317 |
self._stream = tail.copy()
|
318 |
else:
|
319 |
self._stream = None
|
320 |
|
|
|
321 |
self._next_emit_start = 0
|
322 |
+
self._needs_bar_realign = True # NEW FLAG
|
323 |
|
324 |
def reseed_splice(self, recent_wav, anchor_bars: float):
|
325 |
"""
|
|
|
375 |
self.last_chunk_started_at = time.time()
|
376 |
wav, self.state = self.mrt.generate_chunk(state=self.state, style=style_vec)
|
377 |
self._append_model_chunk_to_stream(wav)
|
378 |
+
if getattr(self, "_needs_bar_realign", False):
|
379 |
+
self._realign_emit_pointer_to_bar(sr_model)
|
380 |
+
self._needs_bar_realign = False
|
381 |
+
# DEBUG
|
382 |
+
bar_samps = int(round(self._seconds_per_bar() * sr_model))
|
383 |
+
if bar_samps > 0 and (self._next_emit_start % bar_samps) != 0:
|
384 |
+
print(f"⚠️ emit pointer not aligned: phase={self._next_emit_start % bar_samps}")
|
385 |
+
else:
|
386 |
+
print("✅ emit pointer aligned to bar")
|
387 |
+
|
388 |
self.last_chunk_completed_at = time.time()
|
389 |
|
390 |
# While we have at least one full 8-bar window available, emit it
|