mirror of
https://github.com/jwetzell/JakAudioTools.git
synced 2026-07-26 10:08:39 +00:00
Continue work on SBK parser
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
This is the start of an SBK file specifically BEACH.SBK from JAK1
|
||||
|
||||
|
||||
------------??????????????????------------------
|
||||
626561636800000000000000000000000000000028000000
|
||||
|
||||
------------NAME---------------- --????--
|
||||
776F726D2D69646C6500000000000000 32000F10
|
||||
776F726D2D7269736531000000000000 32000F10
|
||||
776F726D2D73696E6B00000000000000 32000F10
|
||||
7368656C6C2D75700000000000000000 05800710
|
||||
7368656C6C2D646F776E000000000000 05800710
|
||||
736E6170000000000000000000000000 05800710
|
||||
637261622D736C696465000000000000 05800710
|
||||
6C75726B6572637261622D6469657300 05800710
|
||||
70656C6963616E2D666C617000000000 64801B10
|
||||
70656C6963616E2D67756C7000000000 64801B10
|
||||
70757070792D6261726B000000000000 19C00810
|
||||
6C75726B6572646F672D69646C650000 19C00810
|
||||
6C75726B6572646F672D646965730000 19C00810
|
||||
73656167756C6C2D74616B656F666600 3C001910
|
||||
67656172732D72756D626C6500000000 0F000F10
|
||||
726F70652D7374726574636800000000 05800710
|
||||
6D6F6E6B657900000000000000000000 05800710
|
||||
62697264000000000000000000000000 05800710
|
||||
66757365000000000000000000000000 0A800C10
|
||||
7361636B2D6C616E6400000000000000 1E001910
|
||||
6C75726B6572646F672D626974650000 05800710
|
||||
7361636B2D696E636F6D696E67000000 1E001910
|
||||
63616E6E6F6E2D73686F740000000000 96006410
|
||||
646972742D6372756D626C6500000000 19800710
|
||||
67726F74746F2D706F6C652D68697400 19800710
|
||||
6567672D637261636B00000000000000 96003210
|
||||
76656E742D726F636B2D627265616B00 50001910
|
||||
6567672D686974000000000000000000 05800710
|
||||
63616E6E6F6E2D636861726765000000 05800710
|
||||
62656163682D616D6232000000000000 32001410
|
||||
746F7765722D77696E64730000000000 05800710
|
||||
746F7765722D77696E64320000000000 32001410
|
||||
746F7765722D77696E64330000000000 05800710
|
||||
77617465722D6C617000000000000000 32001410
|
||||
776F726D2D6269746500000000000000 1E000A10
|
||||
776F726D2D7461756E74000000000000 05800710
|
||||
74656C6573636F706500000000000000 05800710
|
||||
66616C6C696E672D6567670000000000 05800710
|
||||
64726970000000000000000000000000 05800710
|
||||
776F726D2D6469657300000000000000 05800710
|
||||
+123
-22
@@ -1,6 +1,7 @@
|
||||
#UNFINISHED
|
||||
import os
|
||||
import argparse
|
||||
|
||||
import struct
|
||||
def is_valid_file(parser, arg):
|
||||
if not os.path.exists(arg):
|
||||
parser.error("The file %s does not exist!" % arg)
|
||||
@@ -23,26 +24,126 @@ sounds_start = 24
|
||||
sounds_length = 20
|
||||
|
||||
with open(args.filepath, "rb") as f:
|
||||
soundbank_name = f.read(20).decode('utf-8').strip()
|
||||
f.seek(24)
|
||||
soundsFound = 0
|
||||
while 1:
|
||||
empty = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||
sounds_chunk = f.read(sounds_length)
|
||||
if sounds_chunk == empty:
|
||||
break
|
||||
else:
|
||||
sound_name = sounds_chunk[:-4].decode('utf-8').strip()
|
||||
sound_data = sounds_chunk[-4:]
|
||||
soundsFound += 1
|
||||
print(f'Found {sound_name} with some data {sound_data[0:2].hex()} {sound_data[2:].hex()}')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sbkInfo = struct.unpack("20sI",f.read(24))
|
||||
print(sbkInfo)
|
||||
soundDatas = []
|
||||
for i in range(sbkInfo[1]):
|
||||
soundData = struct.unpack("16sHH",f.read(20))
|
||||
print(soundData)
|
||||
f.seek(2048)
|
||||
|
||||
'''
|
||||
seq
|
||||
I version
|
||||
I subversion
|
||||
I minorversion
|
||||
I something?
|
||||
I soundbankStart
|
||||
I soundBankSize
|
||||
'''
|
||||
|
||||
seqStart = f.tell()
|
||||
seq = struct.unpack("6I",f.read(24))
|
||||
print(seq)
|
||||
|
||||
soundbankStart = seq[4] + seqStart
|
||||
print(f"SoundBank Offset: {soundbankStart}")
|
||||
|
||||
'''
|
||||
sb1k
|
||||
|
||||
4s signature 'SB1k'
|
||||
I
|
||||
I
|
||||
4s
|
||||
I
|
||||
H
|
||||
H
|
||||
H
|
||||
H
|
||||
I instrumentOffset from beingging of this struct
|
||||
I regionOffset from beginning of this struct
|
||||
I
|
||||
I
|
||||
I
|
||||
I
|
||||
I
|
||||
12s
|
||||
H
|
||||
H
|
||||
H
|
||||
H
|
||||
I
|
||||
'''
|
||||
|
||||
|
||||
soundBankHeaderStart = f.tell()
|
||||
sb1k = struct.unpack("4sII4sIHHHHIIIIIII12sHHHHI",f.read(80))
|
||||
|
||||
instrumentStart = sb1k[8] + soundBankHeaderStart
|
||||
print(instrumentStart)
|
||||
f.seek(instrumentStart)
|
||||
regionStart = sb1k[10] + soundBankHeaderStart
|
||||
print(sb1k)
|
||||
|
||||
instruments = []
|
||||
while(f.tell() < regionStart):
|
||||
'''
|
||||
struct Instrument {
|
||||
uint8_t nRegion; // usually 1
|
||||
uint8_t volume; // ? maybe... like 7f is 1.0?
|
||||
uint16_t something; // always 0
|
||||
uint32_t oRegion; // relative to start of SBv2 block I think, points to the first region for instrument
|
||||
} __attribute__((packed));
|
||||
'''
|
||||
instrument = struct.unpack("BBBBHI",f.read(12))
|
||||
instruments.append(instrument)
|
||||
|
||||
print("INSTRUMENTS")
|
||||
offsets = []
|
||||
for instrument in instruments:
|
||||
if instrument[-1] not in offsets:
|
||||
offsets.append(instrument[-1])
|
||||
print(instrument)
|
||||
print(len(offsets))
|
||||
|
||||
f.seek(regionStart)
|
||||
|
||||
regions = []
|
||||
while(f.tell()<soundbankStart):
|
||||
#format defintely not right but
|
||||
region = struct.unpack("10I", f.read(40))
|
||||
regions.append(region)
|
||||
print("REGIONS")
|
||||
sampleOffsets = []
|
||||
for region in regions:
|
||||
print(region)
|
||||
sampleOffset = soundbankStart + region[-4]
|
||||
if sampleOffset not in sampleOffsets:
|
||||
sampleOffsets.append(sampleOffset)
|
||||
#print(f"Region Sample Audio offset: {soundbankStart + region[10]}")
|
||||
# this should align the index of the sample offset with it's sample ID
|
||||
sampleOffsets.sort()
|
||||
|
||||
count = 0
|
||||
for offset in sampleOffsets:
|
||||
f.seek(offset)
|
||||
soundData = f.read(1)
|
||||
while(f.tell() not in sampleOffsets):
|
||||
character = f.read(1)
|
||||
if not character:
|
||||
break
|
||||
soundData += character
|
||||
|
||||
#VAGp header data length and sample rate are packed in bytes 11-15 and 16-20 respectively
|
||||
header = b'\x56\x41\x47\x70\x00\x00\x00\x20\x00\x00\x00\x00'
|
||||
header += struct.pack(">II", len(soundData), 22050)
|
||||
header += b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x61\x73\x73\x69\x73\x74\x61\x6E\x74\x2D\x76\x69\x6C\x6C\x61\x67\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||
|
||||
with open(f'./OUT/VAGp/{count}.VAGp','wb') as out:
|
||||
out.write(header)
|
||||
out.write(soundData)
|
||||
out.close()
|
||||
count += 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user