forge
Explore
Log in

Don't you dare go Hollow

U11: ec-mp3 drop exit-reason census and EC_MP3_LOOP_TRACE env aid (debug only, no output change)

Browse files at this commit

e4fbe999018b279cf8cedf43ee329cb95f96e3b7Ahmet Kaan GümüşParent: 41510f0
crates/ec-mp3/src/encode.rsmodified+1 -17
@@ -1201,8 +1201,7 @@ fn quantise_granule(
12011201 // Short blocks carry twelve bands, long ones twenty-one.
12021202 let bands = if block_type == 2 { 12 } else { SFB_LONG };
12031203 let threshold = band_thresholds(threshold, block_type, sample_rate);
1204- let mut exit = ("cap", 19usize);
1205- for round in 0..20 {
1204+ for _ in 0..20 {
12061205 let (granule, noise) = code_with(xr, block_type, target_bits, &scalefac, sample_rate);
12071206 let ratios: Vec<f64> = (0..bands)
12081207 .map(|b| f64::from(noise[b]) / f64::from(threshold[b]).max(1e-30))
@@ -1218,7 +1217,6 @@ fn quantise_granule(
12181217 best = Some((granule, score, bands));
12191218 }
12201219 if score <= 0.0 {
1221- exit = ("mask", round);
12221220 break; // every band is already exactly at the mask; nothing left to buy
12231221 }
12241222 // Where to stop amplifying, as a fraction of the frame's budget. Swept
@@ -1241,7 +1239,6 @@ fn quantise_granule(
12411239 // the MSE optimum, so perceptual redistribution can only trade away
12421240 // what this gate scores. Don't re-run it: change the metric first.
12431241 if spent * 100 > target_bits * 85 {
1244- exit = ("budget", round);
12451242 break; // the budget is spent; amplifying now only coarsens
12461243 }
12471244 // Bands over their mask get the bits first, worst three per round so
@@ -1258,29 +1255,16 @@ fn quantise_granule(
12581255 .take(3)
12591256 .collect();
12601257 if chosen.is_empty() {
1261- exit = ("saturated", round);
12621258 break;
12631259 }
12641260 for band in chosen {
12651261 scalefac[band] += 1;
12661262 }
12671263 }
1268- census(exit);
12691264 let (granule, score, bands) = best.expect("at least one round runs");
12701265 (granule, score / bands as f64)
12711266 }
12721267
1273-/// Exit-reason census for the distortion loop: with `EC_MP3_LOOP_TRACE` set,
1274-/// one `mp3loop <reason> <round>` line per granule on stderr, so a sweep can be
1275-/// counted with `sort | uniq -c`. The loop's shape is the encoder's open
1276-/// question; without this the only evidence it ever iterates is indirect.
1277-fn census(exit: (&str, usize)) {
1278- static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
1279- if *ON.get_or_init(|| std::env::var_os("EC_MP3_LOOP_TRACE").is_some()) {
1280- eprintln!("mp3loop {} {}", exit.0, exit.1);
1281- }
1282-}
1283-
12841268 /// Puts a spectrum into bitstream order in `out`.
12851269 ///
12861270 /// A short granule is coded band by band, window by window, line by line,