From 2613a81f09583d6f34bd69a162d5d0ceb4a9700f Mon Sep 17 00:00:00 2001 From: Matthew Jackson <1085847+MattJackson@users.noreply.github.com> Date: Wed, 24 Jun 2026 09:39:02 -0700 Subject: [PATCH] Fix AC-3 channel count read from wrong nibble in VTS audio attr The VTS_AST_ATR byte 1 stores (channels - 1) in the low 3 bits, but we were reading the high nibble. A normal 2.0 AC-3 track has 0x1 in the low nibble and 0x0 in the high nibble, so we computed 0+1=1 and mislabeled every stereo track as mono in the muxed Channels element. Read the low 3 bits instead, and correct the two audio_attr tests that had encoded (channels - 1) in the high nibble to match the buggy reader. --- src/ifo.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ifo.rs b/src/ifo.rs index 0d55c89..0115f15 100644 --- a/src/ifo.rs +++ b/src/ifo.rs @@ -444,7 +444,7 @@ fn parse_audio_attr(data: &[u8], offset: usize) -> Result { _ => 48000, }; - let channels = ((b1 >> 4) & 0x0F) + 1; // stored as channels minus 1 + let channels = (b1 & 0x07) + 1; // (channels - 1) in low 3 bits of byte 1 // Language code: bytes 2-3 as ISO 639 let lang_bytes = sub_slice(data, offset + 2, 2)?; @@ -926,8 +926,8 @@ mod tests { // AC3 (coding=0), 48kHz (rate=0), 6 channels (stored as 5) // b0: bits 7-5=000(AC3), bits 4-3=00(48k) => 0x00 data[0] = 0x00; - // b1: bits 7-4=0101 (channels-1=5) => 0x50 - data[1] = 0x50; + // b1: bits 2-0=101 (channels-1=5) => 0x05 + data[1] = 0x05; // language "en" data[2] = b'e'; data[3] = b'n'; @@ -993,8 +993,8 @@ mod tests { // DTS (coding=6), 96kHz (rate=1), 2 channels (stored as 1) // b0: bits 7-5=110(DTS), bits 4-3=01(96k) => 0b110_01_000 = 0xC8 data[0] = 0xC8; - // b1: bits 7-4=0001 (channels-1=1) => 0x10 - data[1] = 0x10; + // b1: bits 2-0=001 (channels-1=1) => 0x01 + data[1] = 0x01; data[2] = b'f'; data[3] = b'r';