SBlk head characterised: four constants and one word that is not a count

sound_bank's head was parsed but never characterised. Across all 27 levels the
SBlk region opens identically for its first twelve bytes:

    +0x00 "SBlk"   +0x04 1   +0x08 4   +0x0c "DAW\0"   +0x10 0

and +0x14 is the only word that varies. It varies with its low sixteen bits zero
on all 27, leaving 0x0092..0x0103 -- 146 to 259.

That is the shape of a record count, and it tracks the body length at close to
100 bytes per unit. It is not one:

    body / field_14     91.2 .. 110.8 across 27 levels
    any stride 0..80 with body = stride*word + constant exactly:  no

So the test asserts the negative too. If a stride ever makes the relation exact
on all 27, sound_bank_sblk_head_is_constant_apart_from_one_word fails and asks
for the record size to be revisited. A near-miss at 100 bytes/record is exactly
what hardens into a name the next time somebody glances at it; the constants are
also checked individually so a real deviation names which one moved.

The DAW region begins with sixteen zero bytes then block-structured data with
16-byte periodicity and slowly varying nibbles -- consistent with block
compressed audio, not decoded. Recorded as such.

Two mistakes, both mine, both the same shape as earlier ones:

1. The constructor bound `format_tag` with a `let` BEFORE the two words that
   precede it in the file, consuming bytes 4..8 and shifting every field after
   it. The struct literal listed the names in the right order; the statements did
   not. A scratch script reading the same bytes gave the opposite answer, which
   is what exposed it. Fixed, with a comment, because "read the lets in file
   order" gets undone otherwise.

2. Inserting the new test ahead of an existing one stranded that test's #[test]
   on my doc comment -- silently unregistering
   tie_vertex_element_is_16_bytes_with_fixed_texcoords. This is the SAME mistake
   as two commits ago and I made it again. It again surfaced only as clippy's
   "never used" rather than as a missing test. Restored and verified by listing
   the registered tests rather than trusting the count.

240 tests, clippy clean, both tie vertex tests confirmed present.
This commit is contained in:
2026-10-13 07:29:07 +02:00
parent bc5ebe559f
commit 28ab7e094b
4 changed files with 195 additions and 1 deletions
+68
View File
@@ -68,6 +68,74 @@ impl SoundBankHeader {
}
}
/// The 24-byte head that opens the `SBlk` region.
///
/// Measured across all 27 levels: the first twelve bytes are **identical
/// everywhere** -- `"SBlk"`, then `1`, then `4`, then `"DAW\0"` -- and the word
/// at `+0x10` is zero on every level. The word at `+0x14` is the only part that
/// varies, and it varies per level with its **low sixteen bits zero in all 27**,
/// leaving values `0x0092..=0x0103` (146..=259).
///
/// That word tracks the length of the `SBlk` body at close to 100 bytes per
/// unit, but it is **not** a record count with a fixed stride: the ratio runs
/// 91.2 to 110.8 across the 27 levels, and no stride in 0..80 makes
/// `body = stride * word + constant` hold exactly on all of them. So it is
/// correlated with the body length and is not identified. Recorded rather than
/// named, because "a count that nearly works" is exactly the claim that later
/// gets asserted by someone who did not run this test.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SBlkHeader {
/// Always `"SBlk"`.
pub magic: [u8; 4],
/// Always `1`.
pub field_4: u32,
/// Always `4`.
pub field_8: u32,
/// Always `"DAW\0"`.
pub format_tag: [u8; 4],
/// Always `0`.
pub field_10: u32,
/// Varies per level; low sixteen bits always zero, `0x0092..=0x0103`.
pub field_14: u32,
}
impl SBlkHeader {
/// Parse the 24-byte head.
pub fn parse(bytes: &[u8]) -> Result<SBlkHeader> {
// Read in byte order. The struct literal names `format_tag` after two
// words, but a `let` bound for it would consume bytes 4..8 and shift
// every field after it -- which it did, once.
let mut b = Buf::new(bytes);
let magic: [u8; 4] = b.read_bytes(4, "SBlk magic")?.try_into().expect("4 bytes");
let field_4 = b.u32("SBlk field_4")?;
let field_8 = b.u32("SBlk field_8")?;
let format_tag: [u8; 4] = b
.read_bytes(4, "SBlk format tag")?
.try_into()
.expect("4 bytes");
Ok(SBlkHeader {
magic,
field_4,
field_8,
format_tag,
field_10: b.u32("SBlk field_10")?,
field_14: b.u32("SBlk field_14")?,
})
}
/// True when every constant this header carries holds.
///
/// Each is universal on all 27 levels. They are tested individually so a
/// real deviation says which one moved.
pub fn constants_hold(&self) -> bool {
&self.magic == b"SBlk"
&& self.field_4 == 1
&& self.field_8 == 4
&& &self.format_tag == b"DAW\0"
&& self.field_10 == 0
}
}
/// Split a sound extent into its two regions.
///
/// Bounds are checked before slicing; a level whose head points outside its own