⚡ 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 commitf9ab8bd5b4480aaa1d1dab7585ebcdba57660960Parent: 0f9a3712 changed files +22 -16
crates/engine/src/normalize.rsmodified+13 -8
| @@ -534,9 +534,13 @@ fn settle( | ||
| 534 | 534 | mix: bool, |
| 535 | 535 | fps: f64, |
| 536 | 536 | end: u32, |
| 537 | -) -> Result<(Loudness, bool), String> { | |
| 537 | +) -> Result<(Loudness, bool, bool), String> { | |
| 538 | 538 | let plans: Vec<Plan> = lanes.iter().map(|&l| plan_of(s, l)).collect(); |
| 539 | 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 | 544 | set_plans(s, &plans, gain); |
| 541 | 545 | let probe_of = |s: &PlaybackSession| -> Result<Loudness, String> { |
| 542 | 546 | match (mix, lanes.first()) { |
| @@ -571,7 +575,7 @@ fn settle( | ||
| 571 | 575 | set_plans(s, &plans, gain); |
| 572 | 576 | after = probe_of(s)?; |
| 573 | 577 | } |
| 574 | - Ok((after, cut)) | |
| 578 | + Ok((after, cut, true)) | |
| 575 | 579 | } |
| 576 | 580 | |
| 577 | 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 | 626 | match scope { |
| 623 | 627 | Scope::Mix => { |
| 624 | 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)?; | |
| 626 | - let afters = lanes | |
| 627 | - .iter() | |
| 628 | - .map(|&l| measure_probe(s, &Probe::Lane(l), fps, end)) | |
| 629 | - .collect::<Result<Vec<_>, _>>()?; | |
| 629 | + let (after, cut, moved) = settle(s, &lanes, before, lufs, tp, true, fps, end)?; | |
| 630 | + let afters = if !moved { | |
| 631 | + befores.clone() | |
| 632 | + } else { | |
| 633 | + lanes.iter().map(|&l| measure_probe(s, &Probe::Lane(l), fps, end)).collect::<Result<Vec<_>, _>>()? | |
| 634 | + }; | |
| 630 | 635 | let reached = (lufs - after.integrated_lufs).abs() <= TOLERANCE_LU + 1e-6; |
| 631 | 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 | 643 | afters.push(befores[i]); |
| 639 | 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 | 647 | reached &= (lufs - after.integrated_lufs).abs() <= TOLERANCE_LU + 1e-6; |
| 643 | 648 | held |= cut; |
| 644 | 649 | afters.push(after); |
crates/mcp/src/tools/hear.rsmodified+9 -8
| @@ -2810,12 +2810,12 @@ fn settle( | ||
| 2810 | 2810 | limited: bool, |
| 2811 | 2811 | mut ceiling: f64, |
| 2812 | 2812 | mut gain: f64, |
| 2813 | + unmoved: Option<Loudness>, | |
| 2813 | 2814 | ) -> Result<Settled, String> { |
| 2814 | - let mut clamped = set_plans(s, plans, gain); | |
| 2815 | - // The result is measured, not predicted: a limiter, a lane gain limit or the | |
| 2816 | - // true peak moves the sound by less than the gain asks. Corrections follow | |
| 2817 | - // while the level misses or the peaks pass the ceiling. | |
| 2818 | - let mut after = measure_target(s, &json!({}), raw)?.loud; | |
| 2815 | + let (mut clamped, mut after) = match unmoved.filter(|_| gain.abs() < 0.01) { | |
| 2816 | + Some(l) => (Vec::new(), l), | |
| 2817 | + None => (set_plans(s, plans, gain), measure_target(s, &json!({}), raw)?.loud), | |
| 2818 | + }; | |
| 2819 | 2819 | let max_passes = pass_cap(limited); |
| 2820 | 2820 | let tol = peak_tolerance(limited); |
| 2821 | 2821 | let mut passes = 0; |
| @@ -3018,6 +3018,7 @@ fn normalize_trial( | ||
| 3018 | 3018 | hold: f64, |
| 3019 | 3019 | limited: bool, |
| 3020 | 3020 | delta: f64, |
| 3021 | + played: Loudness, | |
| 3021 | 3022 | ) -> Result<Settled, String> { |
| 3022 | 3023 | let mut gain = delta; |
| 3023 | 3024 | // 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 | 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 | 3040 | /// 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 | 3126 | let settled: Result<Vec<(Settled, f64, Option<Spill>)>, String> = each |
| 3126 | 3127 | .iter() |
| 3127 | 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 | 3130 | let applied = total_moved(s, &e.plan); |
| 3130 | 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 | 3381 | // does not fall with gain the way the prediction assumes (the clip is what the peak is made of), |
| 3381 | 3382 | // so a linear walk down chases it, while the limiter, ahead of the clip, holds it linearly. |
| 3382 | 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 | 3385 | let changed = s.history_pushes() > start; |
| 3385 | 3386 | let lim = s.limiter(); |
| 3386 | 3387 | // The lane gain each lane really holds after the change: the clamp can hold a lane back. |