Skip to content

New implementation of sceAtrac (the Atrac3+ module) #20098

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

Merged
merged 40 commits into from
Mar 18, 2025
Merged

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Mar 9, 2025

Re-implementation and documentation of sceAtrac

IT FIXES FLATOUT!

The new documentation page, trying to document sceAtrac in detail:
https://www.ppsspp.org/docs/development/ppsspp-internals/atrac/

You guys can start testing some problematic cases now. NOTE: To test it, go into developer setting (on a build from this branch) and enable Experimental Atrac.

Atrac3+ is Sony's proprietary format used for music playback (similar to MP3). sceAtrac is the Sony library used to parse the streams, handle buffering and decode them. It's very complex.

This is a new approach to sceAtrac emulation. Instead of trying to simulate the surface behavior, we now go deep and exactly replicate everything including using the Atrac context state directly, instead of having a lot of extra state variables.

To do this, I've written a new hardware test, and more are coming: hrydgard/pspautotests#235

Luckily, sceAtrac exposes a pointer to its inner state using the _sceAtracGetContextAddress function, so my hardware test can read all the variables from the state, and we can compare. I've uncovered which variable represents the buffer read pointer while streaming, which wasn't known before.

Unluckily, there's still a ton of complexity here, especially around looping etc which has always been a pain. But it seems to be managable.

This will stay behind the "Experimental Atrac3+" setting until it starts getting reliable across a lot of games. But the hope is that soon we'll be able to default to this for all games, and that it will fix a lot of the more mysterious Atrac bugs.

Remaining work:

  • Fix Burnout Legends problem (small buffer math bug)
  • Implement looping
    • simple looping
    • Full support with tail and stuff
  • Fix playback glitch in Wipeout Pulse
  • Fix seeking
  • sceSas integration (Sol Trigger)
  • a lot of other stuff..

To test

Moved all the checkboxes to #20125

@hrydgard hrydgard added the Atrac3+ Issue involves sceAtrac features. label Mar 9, 2025
@hrydgard hrydgard added this to the v1.20 milestone Mar 9, 2025
@hrydgard
Copy link
Owner Author

Guess what? This now fixes Flatout! (Well, behavior at the end of the songs / looping is still not implemented....)

@sum2012
Copy link
Collaborator

sum2012 commented Mar 10, 2025

This now also fixes
#19994 (bad voice)
#15233

@hrydgard
Copy link
Owner Author

Thanks for pre-testing! I'll add a comment here when it's actually ready to be fully tested. Known errors are "halfway" buffers and looping/resetting.

@hrydgard
Copy link
Owner Author

hrydgard commented Mar 11, 2025

GTA Vice City now plays music/speech, although testing some more games I find a lot of issues remaining, plus looping and seeking isn't implemented yet. But progress!

Quite a lot of games actually play music now without crashing, so that's nice.

It might make sense to start testing previously problematic games now...

@ppmeis
Copy link
Contributor

ppmeis commented Mar 12, 2025

GTA Vice City now plays music/speech, although testing some more games I find a lot of issues remaining, plus looping and seeking isn't implemented yet. But progress!

Quite a lot of games actually play music now without crashing, so that's nice.

It might make sense to start testing previously problematic games now...

Hello, 10 years since the first issue report about this bug! Glad to see the light at the end of the tunnel :).

Do you have a list of the problematic titles?

Thanks for your amazing work.

P.S.: Do you any build for testing?

@hrydgard
Copy link
Owner Author

hrydgard commented Mar 12, 2025

Fixed a bunch more issues, now Burnout Legends is solid, and Flatout still works ;) Well, I was right in my prediction that a total rewrite of sceAtrac would be what it takes to fix it..

I'll collect a list of games that have Atrac issues from around the issue tracker, I expect this to fix most of them once done (added list in the top post)

Looping while streaming still remains to be implemented, and it's pretty complex.

As for testing builds, you can grab builds from CI right here on github if you know where to look, or build your own from this branch. Or just wait for this to hit master, I'd estimate a few more days to a week before I'm fully done with it.

I have to hold off on actually merging this until I have savestate handling for this implemented correctly, and I want it pretty solid first.

@hrydgard
Copy link
Owner Author

hrydgard commented Mar 13, 2025

Added a link to the new sceAtrac documentation I've written.

Next up I'll be working on the trickiest case, looping+streaming.

@DominikGTA69
Copy link
Contributor

Is there any precompiled android build to download and test? Checked github actions but android build seems to be absent there.

@anr2me
Copy link
Collaborator

anr2me commented Mar 14, 2025

Is there any precompiled android build to download and test? Checked github actions but android build seems to be absent there.

you can use the manual generate android apk workflow and select the branch used by this PR (ie. atrac3-new-impl) to generate the apk.

@hrydgard
Copy link
Owner Author

Hm, getting further (more commits are coming soon), but I'm facing a slightly odd issue.

_sceAtracGetContextAddress is currently implemented with a gross hack that allocates an extra data block in main RAM on first call. It's barely used but now we use real context structs so we need to allocate them somewhere, and an extra block seems like a bad idea.

It seems the contexts are actually simply located in the data segment of sceAtrac. Where that will be will depend on whether the module is fake-loaded through sceUtilityLoadModule or if an sceAtrac.prx is loaded from disk (and then unused since we HLE it).

Some games use sceUtilityLoadModule, others supply their own. But in the latter case, at least in the first case I tried, the bss section is too small.. 0x5c0 instead of the required 0x600 bytes for six contexts. Though almost nothing uses that many..

Anyway I guess we'll need two cases here.

I could just allocate contexts in fake "kernel space" and avoid the problem entirely, but I don't like that since it'll have games doing accesses that "should" be illegal, if they call _sceAtracGetContextAddress.

Another thing I noticed is that digging a bit deeper into how Atrac3+ works, it itself uses sceAudiocodec, so maybe we can just run the native sceAtrac when it's supplied by games on disk and only HLE sceAudiocodec instead in those cases..

@anr2me
Copy link
Collaborator

anr2me commented Mar 15, 2025

Btw, in your documentation, on GTA Vice City, there is "Atrac2" being mentioned, was it a typo?

@hrydgard
Copy link
Owner Author

hrydgard commented Mar 15, 2025

That's just the (current) name of my new implemementation. I'll clarify it later (and probably rename the current one to AtracLegacy and the new one to Atrac, internally).

@Maarcis12
Copy link

Maarcis12 commented Mar 16, 2025

Hoping it's not late, but i can report that FIFA 07 doesn't crash with the current sceAtrac implementation in the branch build.

@sum2012
Copy link
Collaborator

sum2012 commented Mar 16, 2025

Fix #5564 with "experiment sceAtrac" in option
I forget mention #20098 (comment) also need enable with "experiment sceAtrac"

@hrydgard
Copy link
Owner Author

hrydgard commented Mar 17, 2025

Alright, implemented proper support for looping while streaming, including with trailer, and full savestate support with backwards compatibility. Things seem to work pretty well, and my new set of detailed tests all pass (they will be updated soon).

Please re-test things that weren't previously working (don't forget to enable the Experimental Atrac3+ setting in developer options)

Note that if you load old savestates, the old implementation will be used - you need to restart and load from a proper in-game save.

Oh yeah, Sol Trigger is probably not gonna work, I'll have to write a test for the sceSas + sceAtrac interaction.

@hrydgard hrydgard changed the title WIP: New implementation of sceAtrac (the Atrac3+ module) New implementation of sceAtrac (the Atrac3+ module) Mar 17, 2025
@Maarcis12
Copy link

re-tested FIFA 07, still good, no bad memory execution crash whatsoever.

@thomashastings
Copy link

Is there any precompiled android build to download and test? Checked github actions but android build seems to be absent there.

you can use the manual generate android apk workflow and select the branch used by this PR (ie. atrac3-new-impl) to generate the apk.

By using thr above method, I tested this with FlatOut on Android and it works both in the menu and in game with 60 fps patch enabled as well. Happy times! Thank you for the huge effort, @hrydgard!

@hrydgard hrydgard merged commit 9190a83 into master Mar 18, 2025
19 checks passed
@hrydgard hrydgard deleted the atrac3-new-impl branch March 18, 2025 09:52
@Unknowncat1991
Copy link

v1.19 milestone

@hrydgard hrydgard modified the milestones: v1.20, v1.19.0 Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Atrac3+ Issue involves sceAtrac features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants