Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio manager #34

Open
TeoTwawki opened this issue Aug 18, 2018 · 4 comments
Open

audio manager #34

TeoTwawki opened this issue Aug 18, 2018 · 4 comments

Comments

@TeoTwawki
Copy link
Contributor

TeoTwawki commented Aug 18, 2018

Yes I know we can't decode the newer audio files. but if we could get rid of that BS about managed directx, that'd be great. MDX was discontinued forever ago and the audio manager part of polutils is still good for identifying sound effects in addition to older music tracks.

@alphaONE2
Copy link
Member

alphaONE2 commented Aug 18, 2018

I would certainly welcome such a change, but I don't have any time to reimplement it myself. I don't think anyone else on our dev team has time either.

It's actually not hard to extract audio from the new files either. There's some very simple XOR encryption, but other than that it's just compressed with ATRAC3. The FFMPEG library includes an ATRAC3 decoder, so once the XOR encryption is removed you could just pipe it through FFMPEG to get standard LPCM samples for playback or extraction.

The XOR encryption is pretty easy to break because as far as I can tell every single ATRAC3 encoded file in the game starts with a single block of silence. A silent block is made up of the bytes A0 02 4E 9F followed by 188 00 bytes (192 bytes total) for each channel of audio (so 192 bytes for a mono track, 384 for a stereo track, etc.) In other words the decryption key is just the first 192 * channel_count bytes of audio data with the first 4 bytes of each channel in the block (bytes 0-3, 192-195, etc.) XOR'd with A0 02 4E 9F.

@TeoTwawki
Copy link
Contributor Author

TeoTwawki commented Aug 18, 2018

If this issue can serve as a future wish list item that'd be good then. Maybe we'll get lucky and some random person browsing github will see it and tackle it someday. IIRC Pebbles wanted to move to [SharpDX ]'s nuGet package (https://github.com/sharpdx/SharpDX) for audio processing. Not sure I like that idea myself.

It's actually not hard to extract audio from the new files either.

Huh. wasn't aware anybody was able to decrypt the atrac3 ones thought we needed keys for that and the format was so obscure I didn't think anybody would ever care enough to have support in ..well anything.

@alphaONE2
Copy link
Member

I actually figured out how to decrypt them back around ToAU, took me a few days to figure it out.

However, once I did, it wasn't much use because converting the raw ATRAC3 data stream to LPCM at the time was a pain in the ass and required jumping through several hoops using proprietary Sony DirectShow filters and other Sony software that was almost impossible to find.

Since then FFMPEG has gained an ATRAC3 decoder so it should be much easier to get working now.

@alphaONE2
Copy link
Member

alphaONE2 commented Aug 18, 2018

For anyone who decides to take this on, there is one more thing to keep in mind about the ATRAC3 compressed files. ATRAC3 only supports a 44.1 kHz sample rate, but SE decided to use a 48 kHz sample rate for some files anyway. To do that they ignored the issue, pretended the raw samples were recorded at 44.1 kHz, and then just sped everything up to 48 kHz during playback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants