//! Does `resolve_movie_voice_region` start LATE, and by exactly how much? //! //! The port agent's arithmetic: the running decoder's three `ADV` XMA contexts sum //! to **3 584 000** payload bytes, but the resolved voice region is **3 114 352** — //! 15 % too small to hold them. One of the two spans is not what the other thinks //! it is, and the disc side is this crate's. //! //! The gap is exact. `ctx0` declares **632** packets (1 294 336 B); the leading //! chunk the resolver yields has **394** (806 912 B). The difference is **238 //! packets = 487 424 B**, a whole number of packets — which is what a start offset //! looks like, not corruption. //! //! So: walk the region start backwards and report where `to_xma_riffs` first //! reproduces the decoder's own three sizes. The probe's byte_sizes are the //! control — this is not free to fit, it either lands on them or it does not. //! //! cargo run -p sylpheed-formats --example adv_region_extend use sylpheed_formats::media::{self, DirectorySource, DiscSource}; use sylpheed_formats::slb::{self, VoiceLang}; /// What the running decoder reported (docs/re/structures/voice-three-streams-are-concurrent.md). const WANT: [usize; 3] = [1_294_336, 1_118_208, 1_171_456]; fn main() { let disc = std::env::var("SYLPHEED_DISC").expect("SYLPHEED_DISC"); let src = DirectorySource::new(std::path::PathBuf::from(&disc)); let (start, end) = media::resolve_movie_voice_region(&src, "ADV", VoiceLang::English).expect("region"); println!("resolver says {start}..{end} ({} B)", end - start); println!( "decoder wants {:?} = {} B payload\n", WANT, WANT.iter().sum::() ); for back_packets in [0usize, 100, 200, 237, 238, 239, 300, 400] { let back = (back_packets * 2048) as u64; if back > start { continue; } let s = start - back; let Ok(bytes) = src.read_segment_range("dat/sound", s, (end - s) as usize) else { println!("-{back_packets:4} packets: unreadable"); continue; }; let riffs = slb::to_xma_riffs(&bytes); let sizes: Vec = riffs.iter().map(|r| r.len() - 60).collect(); let hit = sizes.len() == 3 && sizes.iter().zip(WANT.iter()).all(|(a, b)| a == b); println!( "-{back_packets:4} packets (start {s}): {} chunk(s) {:?}{}", riffs.len(), sizes, if hit { " <== MATCHES THE DECODER" } else { "" } ); } }