Commit
·
dfa1fc4
1
Parent(s):
db001c3
smarter loudness matching in /jam/start
Browse files- jam_worker.py +32 -6
jam_worker.py
CHANGED
|
@@ -625,12 +625,38 @@ class JamWorker(threading.Thread):
|
|
| 625 |
break # need more audio
|
| 626 |
loop = self._spool[start:end]
|
| 627 |
|
| 628 |
-
# Loudness match
|
| 629 |
-
if self.params.
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
audio_b64, total_samples, channels = wav_bytes_base64(loop, int(self.params.target_sr))
|
| 636 |
meta = {
|
|
|
|
| 625 |
break # need more audio
|
| 626 |
loop = self._spool[start:end]
|
| 627 |
|
| 628 |
+
# Loudness match per chunk (bar-aligned reference)
|
| 629 |
+
if self.params.loudness_mode != "none" and self.params.combined_loop is not None:
|
| 630 |
+
sr = int(self.params.target_sr)
|
| 631 |
+
|
| 632 |
+
# 1) Get the combined loop at target SR (stereo, float32)
|
| 633 |
+
comb = self.params.combined_loop.as_stereo().resample(sr).samples.astype(np.float32, copy=False)
|
| 634 |
+
if comb.ndim == 1:
|
| 635 |
+
comb = comb[:, None]
|
| 636 |
+
if comb.shape[1] == 1:
|
| 637 |
+
comb = np.repeat(comb, 2, axis=1)
|
| 638 |
+
|
| 639 |
+
# 2) Build a reference slice aligned to this outgoing chunk [start:end]
|
| 640 |
+
# We wrap/tile the combined loop so it always covers the needed range.
|
| 641 |
+
need = end - start
|
| 642 |
+
if comb.shape[0] > 0 and need > 0:
|
| 643 |
+
s = start % comb.shape[0]
|
| 644 |
+
if s + need <= comb.shape[0]:
|
| 645 |
+
ref_slice = comb[s:s+need]
|
| 646 |
+
else:
|
| 647 |
+
part1 = comb[s:]
|
| 648 |
+
part2 = comb[:max(0, need - part1.shape[0])]
|
| 649 |
+
ref_slice = np.vstack([part1, part2])
|
| 650 |
+
|
| 651 |
+
ref = au.Waveform(ref_slice, sr)
|
| 652 |
+
tgt = au.Waveform(loop.copy(), sr)
|
| 653 |
+
|
| 654 |
+
matched, _stats = match_loudness_to_reference(
|
| 655 |
+
ref, tgt,
|
| 656 |
+
method=self.params.loudness_mode,
|
| 657 |
+
headroom_db=self.params.headroom_db
|
| 658 |
+
)
|
| 659 |
+
loop = matched.samples
|
| 660 |
|
| 661 |
audio_b64, total_samples, channels = wav_bytes_base64(loop, int(self.params.target_sr))
|
| 662 |
meta = {
|