From 910f4c3f8f6bf02c25068416e2ec99e64e1273a0 Mon Sep 17 00:00:00 2001 From: SoulMelody Date: Sat, 11 Jan 2025 21:54:08 +0800 Subject: [PATCH] vxf: add VxPitchData model --- libresvip/plugins/ppsf/legacy_model.py | 4 +-- libresvip/plugins/tssln/value_tree.py | 2 +- libresvip/plugins/vxf/model.py | 39 ++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/libresvip/plugins/ppsf/legacy_model.py b/libresvip/plugins/ppsf/legacy_model.py index acd98cc06..ef39fdf51 100644 --- a/libresvip/plugins/ppsf/legacy_model.py +++ b/libresvip/plugins/ppsf/legacy_model.py @@ -30,7 +30,7 @@ def ppsf_int_encoder(value: int, ctx: Context) -> int: low = value & 0x7F high = (value >> 7) << 8 - width = math.floor(math.log(high, 256)) + width = math.floor(high.bit_length() / 8) base = 0x80 << (width * 8) high += base return high + low @@ -39,7 +39,7 @@ def ppsf_int_encoder(value: int, ctx: Context) -> int: def ppsf_int_decoder(value: int, ctx: Context) -> int: high = value >> 8 low = value & 0xFF - width = math.floor(math.log(high, 256)) + width = math.floor(high.bit_length() / 8) base = 0x80 << (width * 8) high -= base return (high << 7) + low diff --git a/libresvip/plugins/tssln/value_tree.py b/libresvip/plugins/tssln/value_tree.py index edd233d56..6988ac609 100644 --- a/libresvip/plugins/tssln/value_tree.py +++ b/libresvip/plugins/tssln/value_tree.py @@ -62,7 +62,7 @@ def _build(self, obj: int, stream: BinaryIO, context: Context, path: CSPath) -> if obj < 0: msg = "Negative numbers not supported" raise ValueError(msg) - width = math.ceil(math.log(obj + 1, 256)) + width = max(math.ceil(obj.bit_length() / 8), 1) try: content = obj.to_bytes(width, "little", signed=False) stream.write(struct.pack("