Is it possible to preserve raw PCM data for reimporting?

Doubts, help and support about QuickBMS and other game research tools
R4nger
Posts: 13
Joined: Mon Oct 29, 2018 6:19 pm

Is it possible to preserve raw PCM data for reimporting?

Post by R4nger »

Hello, everyone!
I am attempting to extract a WAV file from Prince of Persia: Warrior Wihin's .sb0 files.
I managed to extract it and import it into audacity as raw data. I also managed to find the right offset for the size of the file, which is 0x350 threebyte in little endianness. However when I place a different file for reimporting, the archive gets completely changed (making it essentially useless). (This happens with both reimport and reimport2.bat and/or a smaller or higher file size,) however reimporting the original unchanged file works flawlessly. The WAV file specifically is named Pr_ONOHURT_001.WAV in the .sb0 file, which I included below. (It is renamed to .zip because .sb0 was not allowed.)

I will accept any kind of help. :)
Thank you in advance.
R4nger
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by aluigi »

What's the script you are using?
R4nger
Posts: 13
Joined: Mon Oct 29, 2018 6:19 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by R4nger »

aluigi wrote:What's the script you are using?

A very simple custom script which is only a few lines, those being getting the offset of the file, the size and the name and logging that. Nothing fancy. It works, but its a bit bad of a script.

Code: Select all

goto x310
getdstring NAME 0x12
goto 0x33B
get OFFSET byte
goto 0x350
get SIZE threebyte
log NAME OFFSET SIZE
R4nger
Posts: 13
Joined: Mon Oct 29, 2018 6:19 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by R4nger »

Although the OFFSET of the script is just 00, so i probably wouldnt even need to use the get command for it, but its just how i do it.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by aluigi »

"goto x310" is not hexadecimal.
Do you mean "goto 0x310"?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by aluigi »

Anyway the offset is for sure wrong and the reason your reimported file corrupts everything is just that one, offset 0 with a size bigger than 0x310 (where the first file name resides).
R4nger
Posts: 13
Joined: Mon Oct 29, 2018 6:19 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by R4nger »

aluigi wrote:Anyway the offset is for sure wrong and the reason your reimported file corrupts everything is just that one, offset 0 with a size bigger than 0x310 (where the first file name resides).


Interesting. I will keep that in mind, Aluigi. Thanks a lot for your help here! :)

PS: The original is indeed 0x310, a simple copy mistake.
R4nger
Posts: 13
Joined: Mon Oct 29, 2018 6:19 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by R4nger »

It is me again!
I have managed to find some new info in the messy format of the .sb0 file, like the channel number, frequency and bits.

I was wondering if it would be possible to put this info into the WAV file itself, to make it playable right after extraction and if it would be possible to reimport again after that?

Code: Select all

goto 0x300
get FREQ long
get BITS long
goto 0x310
getdstring NAME 0x12
getdstring DUMMY 0x16
get CH long
goto 0x2F0             //Temporal "correct" offset until I find the correct offset
get OFFSET short
goto 0x2C4
get SIZE long
log NAME OFFSET SIZE

Super sorry for the messy code, still kind of a noob to this! :D

PS: I realize this fits more into the "Audio and Video Formats" thread now, so if you wanna move it that thread, go ahead.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by aluigi »

I have a function that I use often in my script when I have to dump raw PCM data into a wav file.
The latest version is currently used in this script:
http://aluigi.org/bms/score_hero_bnk.bms

It's the function starting at line 50: startfunction TOWAV

I guess that in your case it's enough to use the following instead of "log NAME OFFSET SIZE":

Code: Select all

math CODEC = 1
math FREQUENCY = FREQ
math CHANNELS = CH
callfunction TOWAV 1
R4nger
Posts: 13
Joined: Mon Oct 29, 2018 6:19 pm

Re: Is it possible to preserve raw PCM data for reimporting?

Post by R4nger »

Awesome! Thanks aluigi!