mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 06:34:04 +09:00
did it work?
This commit is contained in:
37
it2taud.py
37
it2taud.py
@@ -302,40 +302,33 @@ def _it214_decompress_block(payload: bytes, num_samples: int,
|
|||||||
v = read_bits(width)
|
v = read_bits(width)
|
||||||
|
|
||||||
if width <= 6:
|
if width <= 6:
|
||||||
# Short form: top bit == escape trigger
|
# Short form: top bit == escape trigger; read escape_bits for new width.
|
||||||
|
# Reference: cubic.org/itsex.c (Jeffrey Lim, IT author) — no skip-self.
|
||||||
if v == (1 << (width - 1)):
|
if v == (1 << (width - 1)):
|
||||||
new_w = read_bits(escape_bits) + 1
|
width = read_bits(escape_bits) + 1
|
||||||
if new_w >= width:
|
|
||||||
new_w += 1
|
|
||||||
width = new_w
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif width < init_width:
|
elif width < init_width:
|
||||||
# Mid form: escape codes are in the top half of the unsigned range.
|
# Mid form. border = (all-ones mask) >> (init_width - width).
|
||||||
# border = (2^(width-1)) - range_count (= (0x100 >> (9-width)) - 8 per reference).
|
# For 8-bit: 0xFF>>(9-w) → 63 (w=7), 127 (w=8).
|
||||||
# Escape if v > border; new width = v - border (adjusted for skip-over-self).
|
# Escape when v > border; new width = v - border directly, no skip-self.
|
||||||
border = (1 << (width - 1)) - range_count
|
# Reference: cubic.org/itsex.c, OpenMPT ITTools.cpp.
|
||||||
|
mask = (1 << (init_width - 1)) - 1 # 0xFF (8-bit) or 0xFFFF (16-bit)
|
||||||
|
border = mask >> (init_width - width)
|
||||||
if v > border:
|
if v > border:
|
||||||
new_w = v - border # 1..range_count
|
width = v - border
|
||||||
if new_w >= width:
|
|
||||||
new_w += 1
|
|
||||||
width = new_w
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Full form: top bit (bit init_width-1) is escape flag
|
# Full form: top bit (bit init_width-1) is escape flag.
|
||||||
|
# new width = lower bits + 1, no skip-self.
|
||||||
top_bit = 1 << (init_width - 1)
|
top_bit = 1 << (init_width - 1)
|
||||||
if v & top_bit:
|
if v & top_bit:
|
||||||
new_w = (v & (top_bit - 1)) + 1
|
width = (v & (top_bit - 1)) + 1
|
||||||
if new_w >= width:
|
|
||||||
new_w += 1
|
|
||||||
width = new_w
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Real sample: sign-extend delta and accumulate.
|
# Real sample delta. For full-form the top bit was the escape flag so the
|
||||||
# Full-form (width == init_width): top bit was the escape flag, so the
|
# signed delta is in the lower (init_width-1) bits — same as C's (int8)value.
|
||||||
# actual signed delta occupies the lower (init_width-1) bits — equivalent
|
|
||||||
# to C's (int8)val / (int16)val. All other widths use their full width.
|
|
||||||
delta = _sign_extend(v, min(width, init_width - 1))
|
delta = _sign_extend(v, min(width, init_width - 1))
|
||||||
if is_16bit:
|
if is_16bit:
|
||||||
d1 = _wrap16(d1 + delta)
|
d1 = _wrap16(d1 + delta)
|
||||||
|
|||||||
Reference in New Issue
Block a user