Page 1 of 2

Metal Gear Solid - MTA2 audio format

Posted: Wed Apr 22, 2015 12:44 pm
by daemon1
One user asked me if I can look at the sounds from Metal Gear Solid 4. So I checked bgm_mgo_title01.bgm and it looks like 4-channel audio encoded as ADPCM of some kind. 64-sample blocks. If we take first (uncompressed) samples from each block, this is the picture:

Image

and it sounds like some music (probably looped at the end). Let's try some research on this.

Re: MTA2

Posted: Wed Apr 22, 2015 12:50 pm
by OrangeC
Here is an EBOOT.BIN file from the PS3 Demo version incase you need it assuming you are good at looking into game exe's for decoding algorithims.

I will find a MTAF sample file as soon as i find a working MGS 2 or 3 link.

Link Removed
EDIT: Also NOTE that the decoding algorithm for MTAF is inside the vgmstream.dll but I cannot find source code or a decompiled version of it from hcs.

Re: MTA2

Posted: Wed Apr 22, 2015 1:01 pm
by daemon1
OrangeC wrote:EDIT: Also NOTE that the decoding algorithm for MTAF is inside the vgmstream.dll but I cannot find source code or a decompiled version of it from hcs.
Yes I found his source, but now we need to know how different is MTA2 from MTAF. It may be very different.

Re: MTA2

Posted: Wed Apr 22, 2015 1:08 pm
by OrangeC
Link Removed.

Here is an MTAF file.

Re: MTA2

Posted: Wed Apr 22, 2015 1:54 pm
by daemon1
OrangeC wrote:Here is an MTAF file.
ok, it is really different. 128 samples instead of 64 in MTA2, and probably another algorithm. I will keep you informed. bgm_mgo_lobby01.bgm has 12-channel streams. Weird. Maybe that are 3 parts of one 4-channel music track.

Re: MTA2

Posted: Wed Apr 22, 2015 2:05 pm
by OrangeC
Okay thank you. I knew the format was somehow different.

Re: MTA2

Posted: Wed Apr 22, 2015 6:35 pm
by GHzGangster
Love you guys. :]

bgm_title_mgo has 3 phases/version for sure, each is usually more/less dramatic.

It seems like each phase is denoted by the first byte of each block, then the next 3 bytes are the frame number.
00 00 00 01 ... 0x12c more bytes...
01 00 00 01 ... 0x12c more bytes...
02 00 00 01 ... 0x12c more bytes...
It's like this. For each frame, each version of that frame comes right after.

That EBOOT.BIN is probably useless though. I haven't looked at it, but I'm fairly certain you uploaded the "bootloader". The file you're looking for is MGS4.SELF. I did some debugging, but it seems the sound decoding is done on one of the SPUs (faster than the regular CPU), and it isn't as easy to debug there. Therefore, it's probably some SPU code inside of the ELF, but I really have no experience with SPU stuff right now.

And about the OP, you mentioned taking the first "uncompressed" sample from each block. Did you just take some normal ADPCM algorithm and decode the first sample with that?

Also, just something to note... I was able to take the sample data from one MTA2 and swap it in with another MTA2, and the sound seemed to be playing just fine, other than the loop obviously not working. I don't think there is a lot in the MTA2 that really determines how the actual sample decoding itself is done.

And if you're interested, me and tbg have a Skype chat going on. PM me if you feel like talking about anything. We also emailed the owner of multimedia.cx, he said he would take a look at it, a while ago.

Re: MTA2

Posted: Wed Apr 22, 2015 7:13 pm
by OrangeC
Interesting stuff. So how did you manage to get the MTA2 samples playing when you did the swap thing?

Re: MTA2

Posted: Wed Apr 22, 2015 7:26 pm
by SecaProject
I have some info about this files, but i don't know how to do a conversor, if you want i can share to you.
daemon1, you have a PM.

Re: MTA2

Posted: Wed Apr 22, 2015 7:29 pm
by daemon1
GHzGangster wrote:I did some debugging...
We actually don't need debugging. We just need ADPCM tables for this codec.

I didn't decode the first sample. It is saved in the ADPCM block unchanged. This is what I wanted to check and it was successful.

Re: MTA2

Posted: Wed Apr 22, 2015 7:34 pm
by daemon1
OrangeC wrote:Interesting stuff. So how did you manage to get the MTA2 samples playing when you did the swap thing?
Easily. They are all just a stream of 64 sample-blocks. You can replace them all you want.

Re: MTA2

Posted: Wed Apr 22, 2015 9:04 pm
by daemon1
This is a comparison between the decoded first samples of each frame and same sound recorded from youtube. We can now try and guess where the sample shifts go to decode the whole frames.

Image

Re: MTA2

Posted: Thu Apr 23, 2015 4:55 pm
by daemon1
Each adpcm block has some 5-bit value. We are trying to find out what can it be. An index for some table, or just a scale?

Image

It seem to correspond the original waveform posted on the top

Image

Re: MTA2

Posted: Sat Apr 25, 2015 11:32 am
by daemon1
We've calculated an approximate values in the table. Here's the first output. The red points are where the wave gets wrong, because the values are not accurate.

Image

Re: MTA2

Posted: Tue Apr 28, 2015 9:44 pm
by daemon1
Today is a good day for MGS fans. MTA2 codec algorithm was finally figured out with all tables and values. We can now decode any audio from the game.