ATRAC9 Decoding by furrybob at 9:36 PM EDT on November 4, 2017
I've been doing stuff with HCA encoding for the past month, and now that VGAudio's HCA encoder is complete, I'm working on finishing an ATRAC9 decoder. I figured I'd keep the HCA thread a bit cleaner and start an ATRAC9 one.
The decoder is complete and been pretty thoroughly tested. The source will be released after I've done some final cleanup on it. When the source code is first published, the ATRAC9 decoder will be part of VGAudio
A build of the VGAudio UWP app with ATRAC9 decoding support can be found here. You may need to install the included dependencies if they haven't been already.
For now, I've posted a small amount of documentation for the ATRAC9 format. It can be found in the atrac9-docs branch of VGAudio. Once ATRAC9 support is merged, the documentation will be found in the master branch
@Vector Harbor That looks like someone took a batch script, at9tool 1.6, and ffmpeg and crammed them all into one executable. I'm not sure what updates it would need other than updating the ~5-year-old at9tool.
The point with this new decoder is that it's open source, and could be distributed with and/or integrated into other software.
@AnonRunzes I don't. Besides, isn't ATRAC3(plus) documented? Is there anything incomplete in regards to decoding?
@furrybob - Well, I just want a decent encoder that doesn't come from the SDK, but also has support for other formats that use the codec beyond just the RIFF format(RXWS/SGXD for example).
@furrybob - Exactly, but only on the ffmpeg part. It might be the case with ATRAC9 as well, since there are also audio formats that use this codec such as SGXD. I have no samples of those formats at the moment to give you an general idea of how they look like, unfortunately.
Although you could read the FSB file yourself and then call the ATRAC9 decoder library to decode the audio. There already seems to be FSB reading code out there.
Fab is supported of course in vgmstream but some day the at9 support may be integrated with the source available now. It will be cool to play the music with vgmstream without transcoding it.
Hopefully that day is near as the time for miracles is before us. Lol 😂
@furrybob - great news, I can handle vgmstream's integration once it's live (unless you or kode54 want to do it of course).
Out of curiosity, the EncoderDelay field is repeated, but Sony's tools only seem to use the second field. ATRAC3 is also like this, though older .at3 only had it once. Do you know what's the first field for? (when I try to 0-fill it nothing happens).
@bnnm I'm not sure what the 2 fields are for. Sony's AT9 parser ignores the first value.
Someone recently messaged me that the first and second fields were:
"Input And Overlap Delay Samples - Total value of input delay (0) and overlap delay Encoder Delay Samples - Total value of input delay (0), overlap delay, and encode delay (0)"
I don't know how to verify if that's right or now.
@bnnm It's the holiday season, so I'm unsure about my schedule and when I'll start/finish the port, but if you want to get a head start, you could add ATRAC9 decoding by using Sony's decoder. Then when I do the port, all you'll have to do is swap the decoders since I'm using the same interface.
Here's an old library version along with an example of how to use it.
@furrybob - Ok, did my part (wink wink). One thing I worry though is that keeping lib/function names 1:1 may "atrac"t (har har) Sony's wrath. I mean, it replaces a private tool that Sony would want to control with an iron fist and only licensees should have knowledge of. Maybe some renaming would be safer?
@bnnm: Should I start prepping JoshW archive for it? As with the PSP sets, I'd need to remove the .POS files and regenerate playlists, then reupload most of sets...
Well, maybe furrybob will be busy and won't be able to port it for a while or such. But since he publicly posted his C# decoder (much appreciated) it's a matter of time until done. I can tell you loops and decoding should be equivalent to Sony's stuff, so it's up to you. Personally, those .pos/playlists don't bother me though.
I can upload Freedom Wars/Gravity Rush/Soul Sacrifice Delta original .SXD meanwhile if you want.
@bnnm Maybe it would be a better decision to rename some stuff. I've already put together an open-source, binary-compatible replacement for Nintendo's dsptool.dll, but Nintendo cares less about that kind of stuff than Sony does.
Great, reading ATRAC9 from various container formats appears to be in place. Maybe I missed it, or maybe it's still private, but do you have the calls to the ATRAC9 library done yet?
@furrybob - here is the actual decoder if you want to check it (renamed obvious calls), works fine for all files I tested.
Didn't upload yet as I felt a bit anxious about using Sony's lib calls, but if that's what you'll really use I could go ahead. Just feeling the less reasons for them to make a "cease & desist" thing the better, but maybe they won't care as this stuff is super-niche anyway.
Might do minor restructuring to support "EATrax" (EA's ATRAC9 in .sps) and some simplifications too (ex. sceAt9GetCodecInfo can be easily replicated, GetHandle/DecInit/DecDecode/ReleaseHandle are the only calls really needed if you want to skip the rest).
1. Use the same API as Sony's library Pros: Can be used as a drop-in dll replacement for the official library. Source and binary compatibility with programs using the official library, statically or dynamically linked. Cons: Sony's legal department has an itchy trigger finger.
2. Use the same API, but rename the calls and structures. Pros: Might help avoid legal issues. Cons: No source or binary compatibility with official library, but source compatibility would only require changing some names.
3. Ignore the official library's API and implement whatever seems reasonable. Pros: Freedom to change the API. Cons: Would require changes to a program using Sony's library. Using the open-source library with closed-source programs would require a shim or something.
As a side note, major architecture differences aside, I've found porting (or at least an initial port) the library's individual functions from C# to C is mostly a matter of copying and pasting. Sure you have to tweak some stuff to work with pointers, but there's hardly any rewriting going on.
The decoder included with VGAudio (link) took the 3rd route, and the API looks something like what's listed below. The calls are simpler and less abstract than Sony's decoder, and the information structure provides more detail (noise?) about the stream.
class Atrac9Config { Atrac9Config(byte[] configData);
byte[] ConfigData; int SampleRateIndex; int ChannelConfigIndex; int FrameBytes; int SuperframeIndex;
ChannelConfig ChannelConfig; int ChannelCount; int SampleRate; bool HighSampleRate; int FramesPerSuperframe; int FrameSamplesPower; int FrameSamples; int SuperframeBytes; int SuperframeSamples; }
2 is a good compromise, but I'm not sure if people really need compatibility (if you are a licensee you have the original lib, if you aren't you'll use whatever), the lib is apparently meant to be a testing or dev tool anyway.
3 would simplify the API I guess, good as vgmstream only needs to do superframes and minimal config_data info.
Well, either way works as I can change it anytime, whatever is easier or cleaner for you.
Initial port posted. (Very initial. I'm basically just posting the first working code.)
I renamed the function names just before pushing. The function names and signatures are subject to change, but if they do, the changes should be minor.
Seems to work fine with all my tests files. I don't have any actual >2ch though. IIRC Vita can't do band extension, and all my PS4 samples didn't, not sure if later games do.
Lib calls may have collisions/shadowing without some prefix though, I think Windows used GetHandle somewhere.
@furrybob - great, I'll test some more later and upload/notify kode54 if that's the 'probably final version' (I think he wanted to add the C code directly for his other players though). If you can generate a new .DLL to test it would save me some time to setup Makefiles. Also found one actual 6ch file (Last of Us), seems to work with VGAudio but not with the first DLL release, I'll report.
@Knurek - next or next-next build I think, plus other(s) for lame variations (ex. EATrac, FSB/XVAG 6ch). While you are still here, could you post that Vita decryption tool? (probably helpful to have around)
@bnnm Here's a new dll. It's not the final version. I'll do some of refactoring and cleanup, and remove the pre-generated tables.
The dll posted yesterday only played streams with 1, 2, or 4 channels because 6 and 8 channel streams have an LFE channel, and I hadn't added LFE block decoding yet.
@furrybob - worked great. I guess the API is now stable so I think I'll up my code, and the lib can be integrated to vgmstream then. Well, unless you'd prefer to wait, but we can sync the lib as you upgrade it (the code is very readable btw, props).
Add it whenever you feel it's ready. The API and the entire port should be stable now.
The only functional change left (I think) is to generate lookup tables at runtime in order to save about 100-150? KB of space in the binary. Other than that, changes would include making the code style uniform and maybe reducing the number of files in the source.
Would the library be placed in something like /ext_libs/libatrac9?
@kode54 Either way works for me, so whichever works best for you. Although I suppose that including the source means that ATRAC9 support would be included in cross-platform builds instead of just 32-bit Windows ones.
Hi guys. Is there any documentation on quality or performamce vs other formats or even previous versions such as at3 etc.. ?
Listening to Crypt of he Necromancer e.g., from my ears some songs sound different..well perhaps atrac9 versions offer more bass than the vorbis. It is very subjective so yeah would like to read up some more. Pretty hard to find much info online.
Velocity series sound great in atrac9 format Cheer
Yeah that is probably correct but was curious which people say is better like vorbis rip vs atrac9 rip of the same game. So far i feel atrac9 is better..but like you said they.were probably mastered separately at a different time to pc counterparts etc.
Yeah Dancer. Sorry. Yeah I ripped the PC version with DLC which had latest updates but will try to grab the updated vita version as well as current rip doesn't have the dlc.
Anyway thanks or your replies kode54 and your coding work.
Thanks Knurek. I had a copy of v233 but yeah no dlc was inside.. Hopefully the PS4 version has it otherwise the PC is the only version I guess..Just figured for completeness sake other versions will be good...for all games ;-)