Skip to content

fix(ajm): restart the stream total at a gapless reset - #12322

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Tamalero:fix/ajm-gapless-reset-total
Oct 29, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Tamalero:fix/ajm-gapless-reset-total

Conversation

@Tamalero

@Tamalero Tamalero commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What

Ratchet & Clank: Rift Apart (PPSA01474) hangs on its title screen when it seeks a 4-channel ATRAC9 stream. The game sends sceAjmBatchJobSetGaplessDecode with the reset flag and a new total, then counts the new segment from the stream sideband's total decoded samples.

Cause: the SetGaplessDecode reset clears segmentSamples and skippedSamples but keeps totalDecodedSamples, so every later run reports the samples decoded before the seek as well. In the hang, the stream had decoded 10,944 samples before a seek to a 343,028-sample segment. When the voice hung, the segment had decoded 334,272 samples and the sideband reported 345,216. The game's voice reached its end 8,756 samples early (343,028 − 334,272), and the sideband claimed 2,188 samples past it (345,216 − 343,028). The two add up to 10,944. The voice then owes 140 samples it never gets, and the mixer loop holding the main thread's lock never exits. The trace and the core analysis are in #11700 (#11700 (comment)).

Fix: the reset branch of SetGaplessDecode also sets totalDecodedSamples to 0, for every codec. This matches ClearContext in the same file, which already zeroes it on a CONTROL_RESET, and shadPS4's AjmInstance::Reset() (m_total_samples = 0), which runs for every job with the reset flag. Not measured on a console; the debt entry says so.

Related, already fixed on main: the constant tone I reported in #11700 was not AJM. About 20 of the title's object ports get their PCM from the same two scratch buffers, set one port after another, and AudioOut2 read every pointer at Advance, so each port mixed the last port's grain. A local copy of each grain at sceAudioOut2PortSetAttributes removed it (no full-scale grain in 183 one-second summaries after the title, against 119 of 119 before). #8098 fixes the same thing on main.

This changes the expectation that #6040 added to TestOpusGaplessReset: each segment's total now restarts instead of accumulating. #6040 kept the cumulative count as a choice, without console data. @Ondra97, if you know of a title or a measurement that needs the count kept across a SetGaplessDecode reset, I'd like to hear it.

Tested

Linux 7.3 (CachyOS), GCC 16.2.1, Release, BUILD_TESTING=ON, on main 316615d.

Checklist

🤖 Generated with Claude Code

Tested and written by Claude (AI assistant) on a contributor's machine.

image

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reset branch clears totalDecodedSamples alongside the segment counters, and the updated AT9/Opus tests verify the total restarts after reset but continues across a non-reset gapless update. The author reports 65/65 focused AJM/audio tests, including a negative control and the traced Ratchet & Clank title path; this was not measured on a physical PS5. Hosted Windows, conventions, intake and reporting pass. No blocking issue found on head 08fdabc2d9fa.

@Ondra97

Ondra97 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for tracing this, @Tamalero. I don't have console measurements or a title that requires the total to survive a gapless reset. #6040 fixed Opus segment clipping; its cumulative sideband expectation was not hardware-validated. Your change preserves that fix, and the traced seek failure supports restarting the total. I have no objection to updating that expectation.

@github-actions

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3205 core/libs/tests/GuestAjm.cpp

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@Tamalero the change reads right to me. SetGaplessDecode with the reset flag now clears the reported stream total, the same as ClearContext and initialization already do. The value is only ever reported in the sideband and never used to limit output, so nothing else moves, and the new ATRAC9 test covers a reset mid-stream followed by a non-reset update. One small thing in the debt line: please keep the title ID and drop the game name ("Ratchet & Clank: Rift Apart (PPSA01474) counts..." -> "PPSA01474 counts..."). Debt entries here refer to titles by ID only.

@maskym

maskym commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 08fdabc2d9, merged into main 16e1b95117 (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. Build clean.

This PR's own tests: guest_ajm (0.08 s), guest_ajm_aac_multichannel, guest_ajm_vibration and guest_ajm_wvorbis, all passed.

The tree also carried the open PRs #12318, #12306, #12302, #12200, #12191, all merged cleanly, so the run is a joint one. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tamalero

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, done in f535334: the debt entry now says "PPSA01474 counts a sought segment…", without the game name. No code change.

Tested and written by Claude (AI assistant) on a contributor's machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants