Files
Sylpheed/crates/sylpheed-formats/examples/voice_len_vs_subs.rs
Fabian Hamm ed54f95d54 style: rustfmt sweep -- 774 hunks across 154 files -> 0
`cargo fmt --all -- --check` has failed on every run in this repository's
history, identically on `main` and on every branch. This is #12.

Mechanical: `cargo fmt --all`, nothing else. 154 files, all `.rs`, no other
extension touched. `cargo check --workspace` exits 0 afterwards, so nothing
changed semantically.

ON THE ORDERING, WHICH WAS THE REAL QUESTION.

HANDOFF-2026-09-06 section 7 warns this is the expensive fix: a whole-tree
reformat before #7 and #8 return "would put a conflict in every file of 861
commits and make the reviews those items exist to enable unreadable".

That is measurably too pessimistic, and it had been reasoned rather than
tested. Measured here by three-way merging a rustfmt'd `main` against both
unmerged branches, file by file:

  file/branch pairs tested   32
  merges CLEAN               28
  merges CONFLICTING          4   (8 conflict hunks total)

    sylpheed-cli/src/main.rs      1 hunk
    sylpheed-export/src/check.rs  1
    sylpheed-export/src/screen.rs 4
    sylpheed-export/src/video.rs  2

All four are against `auto/frame-blend-draw-path` only;
`auto/port-p6-audio` does not conflict anywhere. The earlier framing --
154 dirty files, 133 that cannot collide, 21 that can, the collision set
carrying 147 of 774 hunks (19%) -- reproduces exactly. What it did not say
is that most of the 21 still merge cleanly, because rustfmt's edits and the
branches' edits rarely land on the same lines.

So the cost of sweeping now is 4 files and 8 hunks for one branch, against
a check that is otherwise red forever. Deliberately NOT folded into the
WASM PR: 154 reformatted files would make that one unreviewable.

Closes #12
2026-09-08 20:07:01 +02:00

81 lines
3.1 KiB
Rust

//! Is audio actually missing from the resupply banks? Ask the subtitles.
//!
//! The `.slb` decode of `VOICE_D_453` yields 0.14 s, which "looks too short" —
//! but that judgement was an impression. The subtitle track for each movie
//! carries cue times, so it says independently how long the spoken line runs.
//! If the last cue lands near the decoded length, nothing is missing; if it lands
//! far past it, audio really is being lost.
use sylpheed_formats::{movie_subtitle, slb, PakArchive};
/// XMA1 at 48 kHz stereo, 16-bit → bytes per second of PCM.
const PCM_BYTES_PER_SEC: f32 = 48000.0 * 2.0 * 2.0;
/// Decode one sub-wave with FFmpeg and return its length in seconds. Measured,
/// not estimated from a compression ratio — the ratio guess was the first version
/// of this and it is not good enough to hang a conclusion on.
fn decoded_secs(riff: &[u8]) -> f32 {
use std::io::Write;
use std::process::{Command, Stdio};
let Ok(mut c) = Command::new("ffmpeg")
.args(["-v", "error", "-i", "pipe:0", "-f", "s16le", "pipe:1"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()
else {
return f32::NAN;
};
let buf = riff.to_vec();
let mut stdin = c.stdin.take().unwrap();
std::thread::spawn(move || {
let _ = stdin.write_all(&buf);
});
let out = c.wait_with_output().expect("ffmpeg");
out.stdout.len() as f32 / PCM_BYTES_PER_SEC
}
fn main() {
let disc = std::env::var("SYLPHEED_DISC").expect("set SYLPHEED_DISC");
let snd = PakArchive::open(format!("{disc}/dat/sound.pak")).expect("sound.pak");
let lang = PakArchive::open(format!("{disc}/dat/movie/eng.pak")).expect("eng.pak");
// movie → the bank the record table binds it to.
let bound = [
("hokyu_LS_s02A", 450),
("hokyu_LS_s09A", 451),
("hokyu_DS_s13A", 452),
("hokyu_LS_s02H", 453),
("hokyu_DS_s07H", 454),
];
println!(
"{:<18} {:>6} {:>10} {:>12} {:>12}",
"movie", "bank", "last cue s", "decoded s", "verdict"
);
for (movie, n) in bound {
let cues = movie_subtitle::track_voice_cues(&lang, movie);
let last = cues.iter().map(|(_, t)| *t).fold(0.0f32, f32::max);
let path = format!("eng\\etc\\VOICE_D_{n}.slb");
let Some(entry) = snd.find_by_name(&path) else {
continue;
};
let bytes = snd.read(entry).expect("read");
// Sum the sub-waves' payloads as the decoder currently sees them.
let riffs = slb::to_xma_riffs(&bytes);
let secs: f32 = riffs.iter().map(|r| decoded_secs(r)).sum();
// One-directional: a subtitle that appears at t seconds cannot sit inside
// a clip shorter than t. A cue at 0.0 tells us nothing either way.
let verdict = if last == 0.0 {
"no cue signal"
} else if last > secs {
"AUDIO MISSING"
} else {
"consistent"
};
println!(
"{movie:<18} {:>6} {last:>10.2} {secs:>12.2} {verdict:>12} cues={}",
format!("D_{n}"),
cues.len()
);
}
}