-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcmtop86.py
52 lines (41 loc) · 1.78 KB
/
pcmtop86.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import struct
import sys
def create_p86(input_files, output_file, p86drv_version=0x11):
pcm_data_list = []
all_size = 0x10 # Initialize all_size with 0x10
# Read all input files and calculate the total size
for input_file in input_files:
with open(input_file, "rb") as pcm_file:
pcm_data = pcm_file.read()
pcm_data_list.append(pcm_data)
all_size += len(pcm_data) # Add each file's size to all_size
all_size += 0x6 # I believe this is for the size of the header ?
# Prepare the header
header = bytearray()
header.extend(b"PCM86 DATA\x0A\x00") # 12 bytes
header.append(p86drv_version) # Version number 1 byte
header.extend(all_size.to_bytes(3, 'little')) # ALL_Size 3 bytes
# Set START and SIZE for each input file
start = 0x610
for pcm_data in pcm_data_list:
header.extend(start.to_bytes(3, 'little')) # START (3 bytes)
header.extend(len(pcm_data).to_bytes(3, 'little')) # SIZE (3 bytes)
start += len(pcm_data)
# Fill the rest of the START/SIZE values with zeros
header.extend(b'\x00\x00\x00' * (255 * 2 - len(pcm_data_list) * 2)) # START/SIZE (3 bytes each) 6 bytes * (255 - number of input files)
# Calculate padding size
padding_size = 0x610 - len(header)
# Add padding (empty bytes) to header
header.extend(b'\x00' * padding_size)
with open(output_file, "wb") as p86_file:
p86_file.write(header)
for pcm_data in pcm_data_list:
p86_file.write(pcm_data)
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: python3 pcmtop86.py <input_file1> <input_file2> ... <output_file>")
sys.exit(1)
input_files = sys.argv[1:-1]
output_file = sys.argv[-1]
create_p86(input_files, output_file)