diff --git a/crates/ec-truehd/src/decode.rs b/crates/ec-truehd/src/decode.rs
index bebb14c3..1b023bad 100644
--- a/crates/ec-truehd/src/decode.rs
+++ b/crates/ec-truehd/src/decode.rs
@@ -111,16 +111,64 @@ const PARAM_PRESENCE: u8 = 1 << 0;
/// external encoder's output (`tests/oracle.rs`).
pub const HUFFMAN_TABLES: [[(u16, u8); 18]; 3] = [
[
- (0x01, 9), (0x01, 8), (0x01, 7), (0x01, 6), (0x01, 5), (0x01, 4), (0x01, 3), (0x04, 3), (0x05, 3),
- (0x06, 3), (0x07, 3), (0x03, 3), (0x05, 4), (0x09, 5), (0x11, 6), (0x21, 7), (0x41, 8), (0x81, 9),
+ (0x01, 9),
+ (0x01, 8),
+ (0x01, 7),
+ (0x01, 6),
+ (0x01, 5),
+ (0x01, 4),
+ (0x01, 3),
+ (0x04, 3),
+ (0x05, 3),
+ (0x06, 3),
+ (0x07, 3),
+ (0x03, 3),
+ (0x05, 4),
+ (0x09, 5),
+ (0x11, 6),
+ (0x21, 7),
+ (0x41, 8),
+ (0x81, 9),
],
[
- (0x01, 9), (0x01, 8), (0x01, 7), (0x01, 6), (0x01, 5), (0x01, 4), (0x01, 3), (0x02, 2), (0x03, 2),
- (0x03, 3), (0x05, 4), (0x09, 5), (0x11, 6), (0x21, 7), (0x41, 8), (0x81, 9), (0, 0), (0, 0),
+ (0x01, 9),
+ (0x01, 8),
+ (0x01, 7),
+ (0x01, 6),
+ (0x01, 5),
+ (0x01, 4),
+ (0x01, 3),
+ (0x02, 2),
+ (0x03, 2),
+ (0x03, 3),
+ (0x05, 4),
+ (0x09, 5),
+ (0x11, 6),
+ (0x21, 7),
+ (0x41, 8),
+ (0x81, 9),
+ (0, 0),
+ (0, 0),
],
[
- (0x01, 9), (0x01, 8), (0x01, 7), (0x01, 6), (0x01, 5), (0x01, 4), (0x01, 3), (0x01, 1), (0x03, 3),
- (0x05, 4), (0x09, 5), (0x11, 6), (0x21, 7), (0x41, 8), (0x81, 9), (0, 0), (0, 0), (0, 0),
+ (0x01, 9),
+ (0x01, 8),
+ (0x01, 7),
+ (0x01, 6),
+ (0x01, 5),
+ (0x01, 4),
+ (0x01, 3),
+ (0x01, 1),
+ (0x03, 3),
+ (0x05, 4),
+ (0x09, 5),
+ (0x11, 6),
+ (0x21, 7),
+ (0x41, 8),
+ (0x81, 9),
+ (0, 0),
+ (0, 0),
+ (0, 0),
],
];
@@ -165,7 +213,11 @@ fn crc8(poly: u8, init: u8, bytes: &[u8]) -> u8 {
for &b in bytes {
crc ^= b;
for _ in 0..8 {
- crc = if crc & 0x80 != 0 { (crc << 1) ^ poly } else { crc << 1 };
+ crc = if crc & 0x80 != 0 {
+ (crc << 1) ^ poly
+ } else {
+ crc << 1
+ };
}
}
crc
@@ -174,7 +226,7 @@ fn crc8(poly: u8, init: u8, bytes: &[u8]) -> u8 {
/// The restart header's own CRC-8 (poly 0x1D), over the header from its
/// first byte (`buf[0]`, whose two leading bits — the params/restart flags —
/// are masked off) through its last full byte and the trailing partial bits.
-fn restart_checksum(buf: &[u8], bit_size: u64) -> u8 {
+pub(crate) fn restart_checksum(buf: &[u8], bit_size: u64) -> u8 {
let bit_size = bit_size as usize + 2;
let num_bytes = bit_size / 8;
let mut crc = crc8(0x1D, 0, &[buf[0] & 0x3F]);
@@ -271,7 +323,12 @@ impl Substream {
fn recompute_sign_offset(&mut self, ch: usize) {
let cp = &mut self.channels[ch];
let lsb_bits = i32::from(cp.huff_lsbs) - self.quant_step_size[ch] as i32;
- let sign_shift = lsb_bits + if cp.codebook > 0 { 2 - i32::from(cp.codebook) } else { -1 };
+ let sign_shift = lsb_bits
+ + if cp.codebook > 0 {
+ 2 - i32::from(cp.codebook)
+ } else {
+ -1
+ };
let mut off = cp.huff_offset;
if cp.codebook > 0 {
off -= 7 << lsb_bits;
@@ -350,7 +407,11 @@ impl Core {
/// Decodes one access unit whose header already parsed; `None` until the
/// first major sync and every substream's first restart header are seen.
- pub(crate) fn decode(&mut self, header: &AccessUnitHeader, data: &[u8]) -> Result