U11: ec-mp3 drop exit-reason census and EC_MP3_LOOP_TRACE env aid (debug only, no output change)
Browse files at this commite4fbe999018b279cf8cedf43ee329cb95f96e3b7Parent: 41510f01 changed file +1 -17
- crates/ec-mp3/src/encode.rs +1 -17
crates/ec-mp3/src/encode.rsmodified+1 -17
| @@ -1201,8 +1201,7 @@ fn quantise_granule( | |||
| 1201 | // Short blocks carry twelve bands, long ones twenty-one. | 1201 | // Short blocks carry twelve bands, long ones twenty-one. |
| 1202 | let bands = if block_type == 2 { 12 } else { SFB_LONG }; | 1202 | let bands = if block_type == 2 { 12 } else { SFB_LONG }; |
| 1203 | let threshold = band_thresholds(threshold, block_type, sample_rate); | 1203 | let threshold = band_thresholds(threshold, block_type, sample_rate); |
| 1204 | - let mut exit = ("cap", 19usize); | 1204 | + for _ in 0..20 { |
| 1205 | - for round in 0..20 { | ||
| 1206 | let (granule, noise) = code_with(xr, block_type, target_bits, &scalefac, sample_rate); | 1205 | let (granule, noise) = code_with(xr, block_type, target_bits, &scalefac, sample_rate); |
| 1207 | let ratios: Vec<f64> = (0..bands) | 1206 | let ratios: Vec<f64> = (0..bands) |
| 1208 | .map(|b| f64::from(noise[b]) / f64::from(threshold[b]).max(1e-30)) | 1207 | .map(|b| f64::from(noise[b]) / f64::from(threshold[b]).max(1e-30)) |
| @@ -1218,7 +1217,6 @@ fn quantise_granule( | |||
| 1218 | best = Some((granule, score, bands)); | 1217 | best = Some((granule, score, bands)); |
| 1219 | } | 1218 | } |
| 1220 | if score <= 0.0 { | 1219 | if score <= 0.0 { |
| 1221 | - exit = ("mask", round); | ||
| 1222 | break; // every band is already exactly at the mask; nothing left to buy | 1220 | break; // every band is already exactly at the mask; nothing left to buy |
| 1223 | } | 1221 | } |
| 1224 | // Where to stop amplifying, as a fraction of the frame's budget. Swept | 1222 | // Where to stop amplifying, as a fraction of the frame's budget. Swept |
| @@ -1241,7 +1239,6 @@ fn quantise_granule( | |||
| 1241 | // the MSE optimum, so perceptual redistribution can only trade away | 1239 | // the MSE optimum, so perceptual redistribution can only trade away |
| 1242 | // what this gate scores. Don't re-run it: change the metric first. | 1240 | // what this gate scores. Don't re-run it: change the metric first. |
| 1243 | if spent * 100 > target_bits * 85 { | 1241 | if spent * 100 > target_bits * 85 { |
| 1244 | - exit = ("budget", round); | ||
| 1245 | break; // the budget is spent; amplifying now only coarsens | 1242 | break; // the budget is spent; amplifying now only coarsens |
| 1246 | } | 1243 | } |
| 1247 | // Bands over their mask get the bits first, worst three per round so | 1244 | // Bands over their mask get the bits first, worst three per round so |
| @@ -1258,29 +1255,16 @@ fn quantise_granule( | |||
| 1258 | .take(3) | 1255 | .take(3) |
| 1259 | .collect(); | 1256 | .collect(); |
| 1260 | if chosen.is_empty() { | 1257 | if chosen.is_empty() { |
| 1261 | - exit = ("saturated", round); | ||
| 1262 | break; | 1258 | break; |
| 1263 | } | 1259 | } |
| 1264 | for band in chosen { | 1260 | for band in chosen { |
| 1265 | scalefac[band] += 1; | 1261 | scalefac[band] += 1; |
| 1266 | } | 1262 | } |
| 1267 | } | 1263 | } |
| 1268 | - census(exit); | ||
| 1269 | let (granule, score, bands) = best.expect("at least one round runs"); | 1264 | let (granule, score, bands) = best.expect("at least one round runs"); |
| 1270 | (granule, score / bands as f64) | 1265 | (granule, score / bands as f64) |
| 1271 | } | 1266 | } |
| 1272 | 1267 | ||
| 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 | - | ||
| 1284 | /// Puts a spectrum into bitstream order in `out`. | 1268 | /// Puts a spectrum into bitstream order in `out`. |
| 1285 | /// | 1269 | /// |
| 1286 | /// A short granule is coded band by band, window by window, line by line, | 1270 | /// A short granule is coded band by band, window by window, line by line, |