Repository navigation
fix(libSceAjm.native): keep an ATRAC9 gapless segment ended after its total - #18522
Conversation
… total On a PS5 (firmware 13.590.001, real libSceAjm.native in a payload process, a title's stereo 48 kHz ATRAC9 stream of 384-byte superframes) the gapless total only limits the output. The run that reaches it consumes all of its input and writes exactly `total` samples, whatever frame or superframe the total falls in (totals 300, 512, 1100 and 1500). Later runs consume their input and write nothing, and the total of decoded samples stays at the total, until SetGaplessDecode with the reset flag starts a new segment. RunAt9 stopped at the total and left the rest of its input unconsumed, then started a new segment on the next run. It now keeps decoding to consume the input and leaves the segment ended until a reset. The gapless segments test is rewritten to these results. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 7436b8db6d:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_ajm_testsbuilt cleanly. - CTest (
guest_ajm,guest_ajm_aac_multichannel,guest_ajm_vibration,guest_ajm_driver_queries,guest_ajm_wvorbis,guest_ajm_teardown):1/6 Test #2831: guest_ajm_vibration .............. Passed 0.04 sec 2/6 Test #2832: guest_ajm_driver_queries ......... Passed 0.02 sec 3/6 Test #2833: guest_ajm_wvorbis ................ Passed 0.02 sec 4/6 Test #2834: guest_ajm_teardown ............... Passed 0.03 sec 5/6 Test #2830: guest_ajm_aac_multichannel ....... Passed 0.20 sec 6/6 Test #2829: guest_ajm ........................ Passed 0.18 sec 100% tests passed, 0 tests failed out of 6 - Negative control: with
core/libs/prx/libSceAjm.native/src/Ajm.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/6 Test #2830: guest_ajm_aac_multichannel ....... Passed 0.17 sec 2/6 Test #2831: guest_ajm_vibration .............. Passed 0.04 sec 3/6 Test #2834: guest_ajm_teardown ............... Passed 0.03 sec 4/6 Test #2833: guest_ajm_wvorbis ................ Passed 0.03 sec 5/6 Test #2832: guest_ajm_driver_queries ......... Passed 0.02 sec 6/6 Test #2829: guest_ajm ........................Subprocess aborted***Exception: 0.67 sec 83% tests passed, 1 tests failed out of 6 - Code reading:
- core/libs/prx/libSceAjm.native/src/Ajm.cpp:RunAt9: Verified that roomForFrame evaluates to true when segmentEnded() is true, allowing full consumption of input superframes without falsely returning AJM_RESULT_NOT_ENOUGH_ROOM when no output buffer space remains.
- core/libs/prx/libSceAjm.native/src/Ajm.cpp:EmitFrame: Verified that when segmentEnded() holds (instance.segmentSamples >= instance.gapless.totalSamples), remaining is calculated as 0, preventing any sample emission to PcmOutputs or extraneous buffering in ResamplerPush.
- core/libs/prx/libSceAjm.native/src/Ajm.cpp:RunAt9: Verified the removal of the post-loop segmentSamples zeroing, preserving the ended segment state across subsequent jobs until explicitly cleared by SetGaplessDecode with the reset flag, ClearContext, or re-initialization.
- core/libs/tests/GuestAjm.cpp:TestAt9GaplessSegments: Verified unit test coverage across gapless boundaries within, across, and matching superframe boundaries (totals 300, 512, 1100, 1500), verifying zero output produced, full input consumption, and segment restart verification with proper resource teardown via sceAjmInstanceDestroy.
- core/libs/tests/GuestAjm.cpp:TestAt9GaplessResetRestartsTotal: Verified that updating the job invocation to pass the full stream accurately reflects that the preceding run consumed its entire input buffer, properly validating totalDecodedSamples accumulation.
- docs/dev/debt/libSceAjm.native.md: Verified AGENTS.md compliance for technical debt updates, noting console test measurements on firmware 13.590.001 and explicitly listing unmeasured cases (mono, nonzero skips, and totals modified without reset).
- Note: the AI-assisted checkbox can stay.
Looks Good To Me
|
@kali113 the Ratchet & Clank: Rift Apart title-screen check you asked for on #11700, on Linux/NVIDIA. With this PR the title screen appears and the game plays on into the opening; on the same
This is one run per build, each from a cold shader cache, and the driving was by hand (Cross on the title and in the menus), so the timings are rough. The freeze on Builds and runs
Tested and written by Claude (AI assistant) on a contributor's machine. |
|
@Tamalero thank you, that's the check I was hoping for. On the same AI-assisted: yes (Claude Code) |
|
@kali113 an AMD data point for the same build, on a Radeon PRO V620 (RADV):
Build and run
Tested and written by Claude (AI assistant) on a contributor's machine. |
Validation: q42 — PR #18522 (libSceAjm.native ATRAC9 gapless segment)Automated sequential-queue validation (item 42 of 50). Verdict: PASS (Linux/AMD scoped). Environment
Build (PR tree)
Focused test pattern
Test runs (both trees, identical env,
|
|
Thanks @blawesom for the Linux/AMD run (11/11 on both trees). The stale branch base doesn't affect the change: a merge with current AI-assisted: yes (Claude Code) |


What
A run of an ATRAC9 instance with a gapless total stopped decoding when the output reached the total, left the rest of its input unconsumed, and the next run started a new segment. On a PS5 it does neither. This makes the library match the console, as measured below.
Measured on a PS5 (firmware 13.590.001, the real
libSceAjm.nativecalled from a payload process) with 16 consecutive superframes of a title's own ATRAC9 file (stereo, 48 kHz, configFE 74 0B F0, 384-byte superframes of four frames; the bytes are not attached). The full table, with the probe source, is in this comment on #11700:totalsamples: totals 300, 512, 1100 and 1500, the last ending inside a run of two superframes (inputConsumed384 or 768,frames4 or 8,outputWritten1200, 2048, 304 for the 76 samples left of 1100, and 6000 bytes).totalDecodedSamplesstays at the total.SetGaplessDecodewith the same total and reset 0 changes nothing.SetGaplessDecodewith the reset flag starts a new segment: the next run wrote 2048 bytes again for total 512.RunAt9no longer breaks out of its loop at the total (output was already capped per frame) and no longer zeroes the segment counter after a run that ended it. Resets still do (the reset flag,ClearContext, initialization).TestAt9GaplessSegmentspinned the opposite for a mono synthetic stream (the next run decodes a new segment). It now checks the measured behaviour for totals 512, 300, 1500 and 1100, plus the reset.TestAt9GaplessResetRestartsTotalfeeds a whole superframe on its last run, since the previous run now consumes the whole input.Not measured, and said so in the debt entry: a new total without the reset flag after the end (the segment resumes up to it here), a nonzero skip, mono, other codecs. The tests use the repository's mono synthetic stream, not the measured stereo one.
Risk. The debt entry this replaces says FMOD in PPSA29141 needed the frames after the total decoded as a new segment (#2052). The console does not do that, so I expect the change to be right for that title too, but I did not run PPSA29141 myself. Ratchet & Clank: Rift Apart (PPSA01474, which hangs on the old behaviour per #11700) was run by @Tamalero on Linux/NVIDIA, one run per build (comment): on the same
mainit freezes before "Press X"; with this PR the title screen appears and the opening plays. A second run by @Tamalero on a Radeon PRO V620 (RADV),main4e2acc2120+ this PR, reaches the title screen, goes through the menus and the opening and hands the player control, with the #13538 limit set; there is no run ofmainon that GPU, so it does not show what the PR changes there. PPSA29141 is still unverified.Tested
Linux x86-64 (Ubuntu container, GCC 15.2): all six
guest_ajm*tests pass. WithAjm.cppreverted tomain,guest_ajmaborts, so the rewritten test pins the behaviour. Not run on Windows or macOS. Console measurements as above, one console, one stream.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)