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

edited 9:37 PM EDT November 4, 2017
by Vector Harbor at 9:51 PM EDT on November 4, 2017
So that means this atrac9 decoder will get some updates ? Or will it be added to foobar ? I'm curious about that.

edited 9:52 PM EDT November 4, 2017
by AnonRunzes at 10:08 PM EDT on November 4, 2017
@furrybob - Do you have any plans on ATRAC3/ATRAC3plus decoding/encoding at the moment?
by furrybob at 11:20 PM EDT on November 4, 2017
@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?
by AnonRunzes at 12:01 AM EDT on November 5, 2017
@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).

edited 12:03 AM EDT November 5, 2017
by furrybob at 12:20 AM EDT on November 5, 2017
So there are containers other than RIFF that contain ATRAC3 audio? And neither ffmpeg or VGMStream support them?
by AnonRunzes at 10:20 AM EST on November 5, 2017
@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.

edited 10:21 AM EST November 5, 2017
by furrybob at 5:17 PM EST on November 11, 2017
I've uploaded a build of VGAudio with ATRAC9 decoding support here.
by marcusss at 9:00 AM EST on November 12, 2017
Thanks or the tool. I tested it on some at9 files and decodes to a playable .dsp file.
by furrybob at 11:31 AM EST on November 12, 2017
@marcusss
Oh, yeah. Right now, DSP is the default output type if one isn't specified. You can output another type by specifying an output file.
by Sanadsk at 1:39 PM EST on November 28, 2017
Anyone has any luck with extracting .at9 files from .FSB files with their proper headers?
Here is a sample file if anyone is interested:

FSB File Sample
by furrybob at 4:34 PM EST on November 30, 2017
@Sanadsk
There are 8 bytes of unknown data in each ATRAC9 FSB_SAMPLE_HEADER.

The first 4 bytes is the size of each ATRAC9 superframe. The last 4 bytes is the "Config data" for the ATRAC9 stream.

After that, the sampleData for each stream is just a raw ATRAC9 bitstream.


@Everyone
I've posted a little more ATRAC9 documentation

edited 4:38 PM EST November 30, 2017
by furrybob at 11:16 PM EST on December 9, 2017
ATRAC9 decoder source is up on GitHub
by Sanadsk at 2:58 AM EST on December 10, 2017
@furrybob
How can we use it to extract from the FSB files?
by bxaimc at 11:34 AM EST on December 10, 2017
It’s a decoding tool. Not an extractor.
by furrybob at 9:11 PM EST on December 10, 2017
@Sanadsk
There's no FSB reader in VGAudio.

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.
by marcusss at 11:28 PM EST on December 10, 2017
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 😂
by furrybob at 10:12 PM EST on December 11, 2017
Version 2.2.0 of VGAudio has been released with ATRAC9 decoding support.

I'll port the decoder to C shortly.
by bnnm at 2:30 PM EST on December 14, 2017
@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).
by furrybob at 3:07 PM EST on December 16, 2017
@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.
by furrybob at 10:40 PM EST on December 21, 2017
@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.
by bnnm at 6:49 AM EST on December 28, 2017
@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?
by Knurek at 6:47 PM EST on December 28, 2017
@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...
by bnnm at 7:16 PM EST on December 28, 2017
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.
by furrybob at 2:05 PM EST on December 29, 2017
@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?
by bnnm at 2:39 PM EST on December 29, 2017
@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).
by furrybob at 3:54 PM EST on December 30, 2017
Right, there are a few options I see:

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 Atrac9Decoder
{
    Atrac9Config Config;

    Atrac9Decoder();
    void Initialize(byte[] configData);
    void Decode(byte[] atrac9Data, short[][] pcmOut);
}

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;
}
by bnnm at 6:13 PM EST on December 30, 2017
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.
by furrybob at 2:15 AM EST on January 3, 2018
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.
by bnnm at 11:20 AM EST on January 3, 2018
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.
by Knurek at 12:10 PM EST on January 3, 2018
Will this slot in into current VGMStream, or do we need a new build?
Sonic Gems Collection DSP files by furrybob at 12:28 PM EST on January 3, 2018
@bnnm
Good point. I'll probably just add a prefix of Atrac9 or something. And you're right. Vita can't do band extension decoding in hardware.

I've got a couple of hours today, so I'll probably get band extension ported and then do more complete testing/bugfixing.

Edit: Decoder port is feature-complete and accurate based on some additional testing I've done.

Take note of the rearranged parameters in Atrac9Decode if you're moving to this newer version.

edited 5:06 PM EST January 3, 2018
by bnnm at 7:23 PM EST on January 3, 2018
@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)

edited 7:30 PM EST January 3, 2018
by furrybob at 9:09 PM EST on January 3, 2018
@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.
by Knurek at 12:43 AM EST on January 4, 2018
@bnnm: Here you go
(Not a native windows executable, requires Bash on Windows)
by bnnm at 12:50 PM EST on January 4, 2018
@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).
by furrybob at 5:43 PM EST on January 4, 2018
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?
by kode54 at 11:41 PM EST on January 4, 2018
You're welcome to include the full library in VGMStream, I guess. I don't know why I bothered to include the DLL version of it, but I can change that.
by furrybob at 1:58 AM EST on January 5, 2018
@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.
by kode54 at 2:51 AM EST on January 5, 2018
I had already just assumed that people using the libraries would be pulling in the extra dependencies elsewhere. Probably a mistake to assume that.
by furrybob at 11:53 PM EST on January 7, 2018
The library's now about the size it should be in the latest release.

Generating some tables at runtime brings the dll size to ~55 KB down from ~205 KB.
by kode54 at 8:21 PM EST on January 8, 2018
Now it just needs v141_xp instead of v141 for the platform toolkit, and everything can be complete.
by marcusss at 12:59 AM EST on January 11, 2018
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

Mark



edited 11:52 AM EST January 11, 2018
by kode54 at 6:05 PM EST on January 11, 2018
The bass or frequency response is regardless of the format, it may be more likely that they mastered them differently.
by marcusss at 6:32 PM EST on January 11, 2018
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.
by kode54 at 8:06 PM EST on January 11, 2018
Just FYI, it's Crypt of the NecroDancer, not Necromancer. Nice soundtrack, too.
by marcusss at 10:23 PM EST on January 11, 2018
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.



edited 10:40 PM EST January 11, 2018
by Knurek at 2:53 PM EST on January 12, 2018
Not seeing any new files in Vita Crypt downloaded directly from PSN.
by marcusss at 10:24 AM EST on January 14, 2018
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 ;-)


Go to Page 0

Search this thread

Show all threads

Reply to this thread:

User Name Tags:

bold: [b]bold[/b]
italics: [i]italics[/i]
emphasis: [em]emphasis[/em]
underline: [u]underline[/u]
small: [small]small[/small]
Link: [url=http://www.google.com]Link[/url]

[img=https://www.hcs64.com/images/mm1.png]
Password
Subject
Message

HCS Forum Index
Halley's Comet Software
forum source