Aladdin in Nasira's Revenge (PC) - .ASF by Nicknine at 8:56 PM EDT on June 2, 2018
The game stores music in ASF files which appear to have unknown encoding although they do have a header. I assume the audio is 22050 Hz mono like in PS1 version. There's also a codec module called asfcodec.adl in the executable directory if it's any help.
Found this old thread. kode54 commented that it seems like modified Microsoft ADPCM. Must be a custom codec made by Argonaut Games. Some guy posted a decoder but without the source code.
I tried before but assembly is not my thing. I saw a bunch of functions doing (seemingly) ADPCM nibble decoding, but I wasn't familiar with the algorithm (some stuff looked vaguely inpired by PS-ADPCM?).
If somebody properly describes it I could implement.
Hmmm, somehow can't find the option. I'm using "IDA Pro Free" (7.0?). I'll see if I can procure something better, or could you post the pseudo-code? (decoding functions are the 4 long-ish subroutines just before the entry point/DLL main, I think).
Thanks, still can't get it right. I think I'm misunderstanding something about signed/unsignedness and carry stuff (add vs adc). Oh well, if I level up I'll try again.
@kode54 - thanks, I think it's correct. My test files give byte-identical results though, I was expecting rounding diffs and stuff. I guess the math is basically equivalent. Not sure why I was getting it wrong (thought I tried what you wrote). Also you added "carry" but didn't get used?
Games in joswh using this codec: Croc 2, The Emperor's New Groove, Aladdin in Nasira's Revenge (Croc 1 isn't) Other Argonaut PC games that could use it: Bionicle: The Game, I-Ninja, Catwoman: The Game.
***
Gave another try and I think I understand it properly now and what we have is indeed byte-accurate: https://pastebin.com/eC1qwNTj (I'll do a minor tweak later)
The only thing I wonder is about the carry flag (add then adc) but I don't think it's needed with C int32? (since max values are limited)
I'm still getting slight crackling in the sound which is not heard in the original PS1 music files. Do these ASF files sound like that in-game as well?
EDIT: I ran the game and all the music plays with clicking, must be a bug on modern systems... How do you determine decoding is byte accurate?
I've never played the games but I can tell you the codec is worse than the PS1 one, so I wouldn't be surprised. Dunno why didn't just reuse the same, it's basically very similar but simplified in dumb ways.
It's byte accurate in that frames decode like asfcodec does (IOW the pastebin I posted). It's possible they apply a filter after decoding, but I don't think I saw anything like that in asfcodec.adl. You sure it should sound cleaner?
***
BTW, one detail not sure people get is that after decoding, games may upsample and/or filter the output. For example PS1 XA is saved in 37khz but is upsampled+filtered to 44khz (which may not even properly emulated elsewhere), or in PC games the sound card may do internal resampling who knows how.
vgmstream doesn't/can't simulate those behaviours and just outputs the raw sample rate, so it's less accurate than the real thing.
Yeah, I remember that games might re-sample the sound, this might be the case here. Like I said, I can't check if it sounds like this in-game or not ATM cause the music seems to be screwed up on modern systems. I'll check it on my Win98 box when I get the chance. I wish I could remember how it sounded from experience but the last time I played the PC version was way back in 2006. %)
By the way, it's even more baffling that they used a custom codec for music considering that all the sound effects and speech are still in PS-ADCPM in PC version.
Well, I ran the game on an authentic Win98 machine and the music sounds about the same as when decoded with vgmstream. I guess this ASF codec really is worse than PS-ADPCM.
More likely their encoder sucks. Also notice how the frequencies that are crackling are high frequencies, but the audio is 22050Hz. Maybe they clipped in downsampling?
Now that I'm getting the hang of IDA here is another crappy codec I added: Konami XMD (Xbox)
This also seems inspired by XA/PS-ADPCM, only one filter but resets ADPCM output every few samples (potentially better sound?). Guess somebody was bored, since Xbox had a bunch of standard codecs.
I didn't have IDA Pro at hand to decompile the .xbe so it's based on xmddecode.dll from some russian Silent Hill tools.