thecollabagepatch commited on
Commit
1355fb6
·
1 Parent(s): 8ba62a7

reintroducing better loudness matching in /generate

Browse files
Files changed (1) hide show
  1. one_shot_generation.py +13 -9
one_shot_generation.py CHANGED
@@ -124,9 +124,14 @@ def generate_loop_continuation_with_mrt(
124
  apply_micro_fades(out, 5)
125
 
126
  # Loudness match to input (after drop) so bar 1 sits right
127
- out, loud_stats = match_loudness_to_reference(
128
- ref=loop, target=out,
129
- method=loudness_mode, headroom_db=loudness_headroom_db
 
 
 
 
 
130
  )
131
 
132
  return out, loud_stats
@@ -239,8 +244,6 @@ def apply_barwise_loudness_match(
239
  reps = int(np.ceil(need / float(ref.shape[0]))) if ref.shape[0] else 1
240
  ref_tiled = np.tile(ref, (max(1, reps), 1))[:need]
241
 
242
- from .utils import match_loudness_to_reference # same module in your tree
243
-
244
  gains_db = []
245
  out_adj = y.copy()
246
  n_bars = max(1, int(np.ceil(need / float(bar_len))))
@@ -269,10 +272,11 @@ def apply_barwise_loudness_match(
269
 
270
  # write with a short cross-ramp from previous bar
271
  if i > 0 and ramp > 0:
272
- r0 = max(s, s + ramp - (e - s)) # clamp if last bar shorter
273
- t = np.linspace(0.0, 1.0, r0 - s, dtype=np.float32)[:, None]
274
- out_adj[s:r0] = (1.0 - t) * out_adj[s:r0] + t * g[:r0-s]
275
- out_adj[r0:e] = g[r0-s:e-s]
 
276
  else:
277
  out_adj[s:e] = g
278
 
 
124
  apply_micro_fades(out, 5)
125
 
126
  # Loudness match to input (after drop) so bar 1 sits right
127
+ out, loud_stats = apply_barwise_loudness_match(
128
+ out=out,
129
+ ref_loop=loop,
130
+ bpm=bpm,
131
+ beats_per_bar=beats_per_bar,
132
+ method=loudness_mode,
133
+ headroom_db=loudness_headroom_db,
134
+ smooth_ms=50, # 50ms crossfade between bars
135
  )
136
 
137
  return out, loud_stats
 
244
  reps = int(np.ceil(need / float(ref.shape[0]))) if ref.shape[0] else 1
245
  ref_tiled = np.tile(ref, (max(1, reps), 1))[:need]
246
 
 
 
247
  gains_db = []
248
  out_adj = y.copy()
249
  n_bars = max(1, int(np.ceil(need / float(bar_len))))
 
272
 
273
  # write with a short cross-ramp from previous bar
274
  if i > 0 and ramp > 0:
275
+ ramp_len = min(ramp, e - s) # Don't ramp longer than the bar
276
+ t = np.linspace(0.0, 1.0, ramp_len, dtype=np.float32)[:, None]
277
+ # Blend from previous gain (already in out_adj) to current bar's gain
278
+ out_adj[s:s+ramp_len] = (1.0 - t) * out_adj[s:s+ramp_len] + t * g[:ramp_len]
279
+ out_adj[s+ramp_len:e] = g[ramp_len:e-s]
280
  else:
281
  out_adj[s:e] = g
282