forge
Explore
Log in

Don't you dare go Hollow

⚡ A normalize that needs no gain change skips the render that would measure it again, in the GUI and over MCP

Browse files at this commit

f9ab8bd5b4480aaa1d1dab7585ebcdba57660960Ahmet Kaan GümüşParent: 0f9a371
crates/engine/src/normalize.rsmodified+13 -8
@@ -534,9 +534,13 @@ fn settle(
534 mix: bool,534 mix: bool,
535 fps: f64,535 fps: f64,
536 end: u32,536 end: u32,
537-) -> Result<(Loudness, bool), String> {537+) -> Result<(Loudness, bool, bool), String> {
538 let plans: Vec<Plan> = lanes.iter().map(|&l| plan_of(s, l)).collect();538 let plans: Vec<Plan> = lanes.iter().map(|&l| plan_of(s, l)).collect();
539 let mut gain = loudness::gain_to_target(first, lufs, tp);539 let mut gain = loudness::gain_to_target(first, lufs, tp);
540+ if gain.abs() < 0.01 {
541+ let over = if first.true_peak_dbtp.is_finite() { first.true_peak_dbtp - tp } else { 0.0 };
542+ return Ok((*first, over >= -PEAK_TOLERANCE_DB && (lufs - first.integrated_lufs).abs() > TOLERANCE_LU, false));
543+ }
540 set_plans(s, &plans, gain);544 set_plans(s, &plans, gain);
541 let probe_of = |s: &PlaybackSession| -> Result<Loudness, String> {545 let probe_of = |s: &PlaybackSession| -> Result<Loudness, String> {
542 match (mix, lanes.first()) {546 match (mix, lanes.first()) {
@@ -571,7 +575,7 @@ fn settle(
571 set_plans(s, &plans, gain);575 set_plans(s, &plans, gain);
572 after = probe_of(s)?;576 after = probe_of(s)?;
573 }577 }
574- Ok((after, cut))578+ Ok((after, cut, true))
575 }579 }
576 580
577 /// Loudness-normalizes the timeline to `lufs` (integrated) with the true peak held under `tp`581 /// Loudness-normalizes the timeline to `lufs` (integrated) with the true peak held under `tp`
@@ -622,11 +626,12 @@ pub fn normalize(s: &mut PlaybackSession, scope: &Scope, lufs: f64, tp: f64) ->
622 match scope {626 match scope {
623 Scope::Mix => {627 Scope::Mix => {
624 let before = mix_before.as_ref().expect("a mix is measured");628 let before = mix_before.as_ref().expect("a mix is measured");
625- let (after, cut) = settle(s, &lanes, before, lufs, tp, true, fps, end)?;629+ let (after, cut, moved) = settle(s, &lanes, before, lufs, tp, true, fps, end)?;
626- let afters = lanes630+ let afters = if !moved {
627- .iter()631+ befores.clone()
628- .map(|&l| measure_probe(s, &Probe::Lane(l), fps, end))632+ } else {
629- .collect::<Result<Vec<_>, _>>()?;633+ lanes.iter().map(|&l| measure_probe(s, &Probe::Lane(l), fps, end)).collect::<Result<Vec<_>, _>>()?
634+ };
630 let reached = (lufs - after.integrated_lufs).abs() <= TOLERANCE_LU + 1e-6;635 let reached = (lufs - after.integrated_lufs).abs() <= TOLERANCE_LU + 1e-6;
631 Ok((afters, Some(after), reached, cut))636 Ok((afters, Some(after), reached, cut))
632 }637 }
@@ -638,7 +643,7 @@ pub fn normalize(s: &mut PlaybackSession, scope: &Scope, lufs: f64, tp: f64) ->
638 afters.push(befores[i]);643 afters.push(befores[i]);
639 continue;644 continue;
640 }645 }
641- let (after, cut) = settle(s, &[l], &befores[i], lufs, tp, false, fps, end)?;646+ let (after, cut, _) = settle(s, &[l], &befores[i], lufs, tp, false, fps, end)?;
642 reached &= (lufs - after.integrated_lufs).abs() <= TOLERANCE_LU + 1e-6;647 reached &= (lufs - after.integrated_lufs).abs() <= TOLERANCE_LU + 1e-6;
643 held |= cut;648 held |= cut;
644 afters.push(after);649 afters.push(after);
crates/mcp/src/tools/hear.rsmodified+9 -8
@@ -2810,12 +2810,12 @@ fn settle(
2810 limited: bool,2810 limited: bool,
2811 mut ceiling: f64,2811 mut ceiling: f64,
2812 mut gain: f64,2812 mut gain: f64,
2813+ unmoved: Option<Loudness>,
2813 ) -> Result<Settled, String> {2814 ) -> Result<Settled, String> {
2814- let mut clamped = set_plans(s, plans, gain);2815+ let (mut clamped, mut after) = match unmoved.filter(|_| gain.abs() < 0.01) {
2815- // The result is measured, not predicted: a limiter, a lane gain limit or the2816+ Some(l) => (Vec::new(), l),
2816- // true peak moves the sound by less than the gain asks. Corrections follow2817+ None => (set_plans(s, plans, gain), measure_target(s, &json!({}), raw)?.loud),
2817- // while the level misses or the peaks pass the ceiling.2818+ };
2818- let mut after = measure_target(s, &json!({}), raw)?.loud;
2819 let max_passes = pass_cap(limited);2819 let max_passes = pass_cap(limited);
2820 let tol = peak_tolerance(limited);2820 let tol = peak_tolerance(limited);
2821 let mut passes = 0;2821 let mut passes = 0;
@@ -3018,6 +3018,7 @@ fn normalize_trial(
3018 hold: f64,3018 hold: f64,
3019 limited: bool,3019 limited: bool,
3020 delta: f64,3020 delta: f64,
3021+ played: Loudness,
3021 ) -> Result<Settled, String> {3022 ) -> Result<Settled, String> {
3022 let mut gain = delta;3023 let mut gain = delta;
3023 // The limiter's detector is the meter's own true-peak method, so its ceiling is the target: the3024 // The limiter's detector is the meter's own true-peak method, so its ceiling is the target: the
@@ -3033,7 +3034,7 @@ fn normalize_trial(
3033 gain = lufs - r.loud.integrated_lufs;3034 gain = lufs - r.loud.integrated_lufs;
3034 }3035 }
3035 }3036 }
3036- settle(s, raw, plans, lufs, hold, limited, hold, gain)3037+ settle(s, raw, plans, lufs, hold, limited, hold, gain, (!limited).then_some(played))
3037 }3038 }
3038 3039
3039 /// The past tense a reply uses for a change that was made, or the conditional for a dry run, which3040 /// The past tense a reply uses for a change that was made, or the conditional for a dry run, which
@@ -3125,7 +3126,7 @@ fn run_normalize_each(srv: &mut Server, args: &Value) -> Reply {
3125 let settled: Result<Vec<(Settled, f64, Option<Spill>)>, String> = each3126 let settled: Result<Vec<(Settled, f64, Option<Spill>)>, String> = each
3126 .iter()3127 .iter()
3127 .map(|e| -> Result<(Settled, f64, Option<Spill>), String> {3128 .map(|e| -> Result<(Settled, f64, Option<Spill>), String> {
3128- let st = settle(s, &e.name, std::slice::from_ref(&e.plan), lufs, tp, false, tp, e.delta)?;3129+ let st = settle(s, &e.name, std::slice::from_ref(&e.plan), lufs, tp, false, tp, e.delta, Some(e.played))?;
3129 let applied = total_moved(s, &e.plan);3130 let applied = total_moved(s, &e.plan);
3130 Ok((st, applied, spill_of(s, &e.plan)))3131 Ok((st, applied, spill_of(s, &e.plan)))
3131 })3132 })
@@ -3380,7 +3381,7 @@ fn run_normalize(srv: &mut Server, args: &Value) -> Reply {
3380 // does not fall with gain the way the prediction assumes (the clip is what the peak is made of),3381 // does not fall with gain the way the prediction assumes (the clip is what the peak is made of),
3381 // so a linear walk down chases it, while the limiter, ahead of the clip, holds it linearly.3382 // so a linear walk down chases it, while the limiter, ahead of the clip, holds it linearly.
3382 let limited = limiter_in_the_way(limiter_asked, tp_binds, played.true_peak_dbtp, hold);3383 let limited = limiter_in_the_way(limiter_asked, tp_binds, played.true_peak_dbtp, hold);
3383- let trial = normalize_trial(s, raw, &plans, lufs, hold, limited, delta);3384+ let trial = normalize_trial(s, raw, &plans, lufs, hold, limited, delta, played);
3384 let changed = s.history_pushes() > start;3385 let changed = s.history_pushes() > start;
3385 let lim = s.limiter();3386 let lim = s.limiter();
3386 // The lane gain each lane really holds after the change: the clamp can hold a lane back.3387 // The lane gain each lane really holds after the change: the clamp can hold a lane back.