Important information: this site is currently scheduled to go offline indefinitely by end of the year.

The Wonderful 101 [WWise, WEM]

Get help on any and all audio formats, or chip in and help others!
spider91
advanced
Posts: 78
Joined: Mon Feb 14, 2011 8:09 am
Has thanked: 18 times
Been thanked: 45 times

Re: The Wonderful 101 [WWise, WEM]

Post by spider91 »

Well, i've made a script. First of all you need to interleave files with ima_rejigger, then run this script to get playable .wav. Didn't work with music from your archieve, only with voices, don't know why (maybe because of 6 channels?).

Code: Select all

endian big
goto 0x16
get CHANNELS short
reverseshort CHANNELS
get FREQ long
reverselong FREQ
get BPS long
reverselong BPS
get UNK1 short
reverseshort UNK1
get UNK2 short
reverseshort UNK2
goto 0xC
do
	getDstring CHUNK_NAME 4
	get DATA_SIZE long
	savepos DATA_OFFSET
	getDstring DUMMY DATA_SIZE

while CHUNK_NAME != "data"
set FULLSIZE long 0x30
math FULLSIZE += DATA_SIZE
reverselong DATA_SIZE
set RIFF_SIZE long FULLSIZE
math RIFF_SIZE -= 0x8
reverselong RIFF_SIZE
log MEMORY_FILE 0 0
set MEMORY_FILE binary "\x52\x49\x46\x46\x00\x00\x00\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x14\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x41\x00\x64\x61\x74\x61\x00\x00\x00\x00"
putVarChr MEMORY_FILE 4 RIFF_SIZE long
putVarChr MEMORY_FILE 22 CHANNELS short
putVarChr MEMORY_FILE 24 FREQ long
putVarChr MEMORY_FILE 28 BPS long
putVarChr MEMORY_FILE 32 UNK1 short
putVarChr MEMORY_FILE 34 UNK2 short
putVarChr MEMORY_FILE 44 DATA_SIZE long
append
reverselong DATA_SIZE
log MEMORY_FILE DATA_OFFSET DATA_SIZE
get NAME basename
string NAME += ".wav"
log NAME 0 FULLSIZE MEMORY_FILE
Researchman
mega-veteran
mega-veteran
Posts: 315
Joined: Fri Jun 11, 2010 12:08 pm
Has thanked: 78 times
Been thanked: 23 times

Re: The Wonderful 101 [WWise, WEM]

Post by Researchman »

I think so - ffmpeg, xmplay with vgmstream, WMP, Audition CS6 reports about unknown codec or loads without sound(silence in 6ch files).

Funny, but Windows Explorer detects audio time even for 6ch files.

Probably need inform hcs about it.
Chaofanatic
ultra-n00b
Posts: 2
Joined: Fri Jul 10, 2015 6:51 pm
Has thanked: 1 time

Re: The Wonderful 101 [WWise, WEM]

Post by Chaofanatic »

I hate to bump such an old post but I've been trying this and I'm able to get wav files I can play but they all have grinding static sound over them while I can still hear the original sound underneath.
It sounds like this was figured out but I think I missed a step or I may be using a wrong version of ima_rejigger or something. Were you actually able to get completely working files out of this or is it still being figured out?
spider91
advanced
Posts: 78
Joined: Mon Feb 14, 2011 8:09 am
Has thanked: 18 times
Been thanked: 45 times

Re: The Wonderful 101 [WWise, WEM]

Post by spider91 »

mono and stereo files plays well if you use ima_rejigger first and my script after that. If you don't you will get that grinding sound
Chaofanatic
ultra-n00b
Posts: 2
Joined: Fri Jul 10, 2015 6:51 pm
Has thanked: 1 time

Re: The Wonderful 101 [WWise, WEM]

Post by Chaofanatic »

Oh! It worked! Thank you! I was using the wrong version of ima_rejigger and there were some problems with my batch file. Thanks a ton!
I'd also like to ask about the 6 channel files as well. Is there any way of dealing with those and getting something usable out of them? I checked around with some people and they may be used for event dialogue or something similar.

I've got some files here if you'd like to take a look.
https://www.dropbox.com/s/qmb48ahnuboqd ... s.rar?dl=0
hcs
mega-veteran
mega-veteran
Posts: 263
Joined: Sun Oct 18, 2009 9:41 pm
Location: Portland, OR
Has thanked: 3 times
Been thanked: 79 times
Contact:

Re: The Wonderful 101 [WWise, WEM]

Post by hcs »

spider91's wwise_ima_adpcm gave me the final clue, that Wwise uses one less sample per block than standard MS IMA:

MS IMA has the weird feature that every block, which is fairly small, has in its header the first sample in full 16-bit PCM form, which allows for very accurate seeking. The rest of the block is 4 byte chunks with 8 4-bit samples each, so the sample count of a block is always 8x+1.

In Wwise IMA, the final decoded sample is thrown away, and in fact that last nibble is always 0. Thus, sample count is 8x. I assume they did this because it lets them keep some buffer aligned to nice round numbers.

The upshot of which is that it is impossible to convert Wwise IMA ADPCM to standard Microsoft IMA ADPCM; there are these extra samples hanging out which throw the whole file off. There is actually a space in the extra format data for "samples per block", but I don't think many decoders care about that (sox rejects anything without that extra +1 sample-per-block, libavformat seemingly ignores it).

Anyway, I'm glad to finally be able to put this behind me and retire the old ima_rejiggers, which never worked properly.

Here's ima_rejigger5, which does the decoding to PCM and supports both RIFF and RIFX wems, so it should be usable with The Wonderful 101. It isn't super-necessary but I wanted to get some closure here.

edit;
I'm realizing belatedly that my whole digression into reinterleaving stuff with the rejiggering tools was a huge wrong turn, this IMA turns out to be more common to the stuff we see on consoles all the time than the weird +1 thing standardized in RIFF. Sorry for causing and prolonging the confusion. I hope things are correct now, they certainly sound good.

edit2:
One final thought: I may have been a little too harsh on myself, this is definitely an unusual format, somewhere between MS IMA and normal IMA. Normally when you see IMA/DVI with block headers with a sample in it, that sample is just history, used only for seeking; you have to take that history and compute a new sample from the first nibble of ADPCM data. It is a good idea that MS came up with to not waste that and actually use it as part of the stream, so it is less redundant, but in so doing they wound up with really oddly sized blocks. I think AK came along and realized the best of both worlds, as they've managed to do in such creative ways with Vorbis.
AnonBaiter
veteran
Posts: 82
Joined: Thu Oct 15, 2015 8:15 pm
Has thanked: 18 times
Been thanked: 8 times

Re: The Wonderful 101 [WWise, WEM]

Post by AnonBaiter »

Finally a solution is found!
hcs
mega-veteran
mega-veteran
Posts: 263
Joined: Sun Oct 18, 2009 9:41 pm
Location: Portland, OR
Has thanked: 3 times
Been thanked: 79 times
Contact:

Re: The Wonderful 101 [WWise, WEM]

Post by hcs »

Credit where it is due: wwise_ima_adpcm is by Zwagoth Klaar (zabb65), whose repository of Payday 2 modding tools is found here.

I'm not sure why spider91 was distributing the .exe without the readme, but it's my fault for not looking hard enough. Oops.
hcs
mega-veteran
mega-veteran
Posts: 263
Joined: Sun Oct 18, 2009 9:41 pm
Location: Portland, OR
Has thanked: 3 times
Been thanked: 79 times
Contact:

Re: The Wonderful 101 [WWise, WEM]

Post by hcs »

Was just looking over this again due to clipping in some very loud files from EVE Online, here's the heart of the decoder in the x64 debug lib from Wwise_v2015.1.6_Build5553_SDK.Linux

Code: Select all

<_ZN13CAkADPCMCodec12DecodeSampleEiii>:
  10:   83 e0 07                and    $0x7,%eax        ; sample
  13:   01 c0                   add    %eax,%eax        ; sample*2
  15:   83 c0 01                add    $0x1,%eax        ; sample*2+1
  18:   0f af 45 e4             imul   -0x1c(%rbp),%eax ; (sample*2+1)*scale
  1c:   8d 50 07                lea    0x7(%rax),%edx   ; result+7
  1f:   85 c0                   test   %eax,%eax        ; result negative?
  21:   0f 48 c2                cmovs  %edx,%eax        ; adjust if negative to fix rounding for below division
  24:   c1 f8 03                sar    $0x3,%eax        ; (sample*2+1)*scale/8
What's notable is that this is a different rounding model from what ima_rejigger5 and wwise_ima_adpcm use, which is the shift-and-add from the IMA specification. There are very small differences, though with the block headers resetting state every few samples it doesn't accumulate. It looks like the noise introduced by this is down in the -50 dB range.

In any case this didn't fix my clipping problem, which is probably unavoidable. Maybe I will release a new revision of ima_rejigger to reflect this but I don't know if I'll bother.

(As an aside I'm pretty sure the adjustment done before division is unnecessary (and unwanted anyway), but the compiler probably didn't look at the constant table to figure this out and had to play it safe with signed division.)
Post Reply