aboutsummaryrefslogtreecommitdiff
path: root/examples/sound/spustream/interleave.py
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-12-18 16:05:43 +0100
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-12-18 16:05:43 +0100
commitb58a37bdac753ceace35761ef474c198a3f18e12 (patch)
treef7747c222e47479b2b39ad04b39b82d991ae0f0a /examples/sound/spustream/interleave.py
parentd84bc4939607442e41888521939ef10908c87ce3 (diff)
downloadpsn00bsdk-b58a37bdac753ceace35761ef474c198a3f18e12.tar.gz
Clean up MDEC and sound examples
Diffstat (limited to 'examples/sound/spustream/interleave.py')
-rw-r--r--examples/sound/spustream/interleave.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/examples/sound/spustream/interleave.py b/examples/sound/spustream/interleave.py
index 4e68974..4f4f20f 100644
--- a/examples/sound/spustream/interleave.py
+++ b/examples/sound/spustream/interleave.py
@@ -8,7 +8,7 @@ from struct import Struct
from itertools import zip_longest
from argparse import ArgumentParser, FileType
-VAG_HEADER = Struct("> 4s I 4s 2I 12x 16s")
+VAG_HEADER = Struct("> 4s 4I 10x H 16s")
VAG_MAGIC = b"VAGp"
VAGI_MAGIC = b"VAGi"
VAG_VERSION = 0x20
@@ -17,6 +17,9 @@ CHUNK_ALIGN = 0x800
## Helpers
+def swap_endian(value, size):
+ return int.from_bytes(value.to_bytes(size, "big"), "little")
+
def align(data, size):
chunks = (len(data) + size - 1) // size
@@ -40,7 +43,7 @@ class VAGReader:
magic, _, _,
self.size,
self.sample_rate,
- self.name
+ _, _
) = VAG_HEADER.unpack(header)
if magic == VAGI_MAGIC:
@@ -116,9 +119,6 @@ def main():
size = input_files[0].size
sample_rate = input_files[0].sample_rate
- if (not args.raw) and (len(input_files) != 2):
- warn(RuntimeWarning("interleaved .VAG only supports stereo (2 input files)"))
-
for vag in input_files[1:]:
if vag.size != size:
warn(RuntimeWarning(f"{vag.file.name} has a different file size"))
@@ -135,9 +135,10 @@ def main():
header = VAG_HEADER.pack(
VAGI_MAGIC,
VAG_VERSION,
- args.buffer_size.to_bytes(4, "little"),
+ swap_endian(args.buffer_size, 4),
size,
sample_rate,
+ swap_endian(len(input_files), 2),
os.path.basename(_file.name).encode()[0:16]
)