feat(ajm): resample interleaved s16 PCM through codec 23 #6841
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6841"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Sevthered on 2026-10-16T14:01:23Z.
What
Broken Sword - Shadow of the Templars: Reforged (PPSA21480) stops 11 to 15 s after start on current
main(#6671), 2 of 2 runs. These are theAPS5_TRACE_AJM=1lines asked for in #6671:What the title does with codec 23, measured with a local probe (not part of this PR):
.osaarchives hold Ogg Opus streams,music.vt7aholds Ogg Vorbis, and libopus 1.5.2 is linked intoeboot.bin.sceAjmBatchJobInitializewith the 12 bytes0, 2, 44100,sceAjmBatchJobSetResampleParameterswith 0.91875 (44100/48000), thensceAjmBatchJobDecodewith 940 input bytes and a 1024-byte output. 940 bytes are 235 interleaved stereos16frames and 1024 bytes are 256; 256 × 0.91875 = 235.2.So the title uses codec 23 as PCM input that only goes through the resampler, and this PR handles it that way:
s16; other formats throw.SIDEBAND_STREAM, and initialization throughsceAjmBatchJobControl.Why every frame is emitted rather than going through the streaming resampler of the other codecs: that resampler holds two frames back for the next run. With it the title received 254 frames per block and then submitted a second job for exactly the missing 8 bytes, after a new initialize and with the same 940 input bytes. With every frame emitted it submits one job per block, 187.5 per second (48000 / 256), and the output is as smooth across block joins as inside a block (median step 88 against 85, p99 882 against 858).
The MP3, ATRAC9, M4AAC and Opus paths are unchanged. The debt entry lists every value taken from this title and every assumption. #6672 records codec 23 as not implemented in the same debt file; with this PR that entry would no longer apply. The name
CODEC_PCMis mine, since no source names a codec 23 (shadPS4's PS4 header ends its codec list withMax = 23, as noted in #6671).Tested
Windows 11 (build 26300), WinLibs MinGW-w64 GCC 15.2.0 r7; Ubuntu 24.04 in WSL, GCC 13.3. Both on
main82ddae75bplus this commit.guest_ajmwith the newTestPcmResample: the title's batch sequence twice on the same instance, every output frame of a ramp and of a non-linear channel compared with an independent Catmull-Rom, nothing written past frame 256 of a 300-frame output, the passthrough at ratio 1 over two runs, and the throwing cases. Passes on Windows and Linux. It fails with the output one frame short, without the continuity check, and when the run fills the whole output (each mutation tried and reverted).guest_ajm_teardown(Linux): passes.tools/check_skips.py --job windowsexpects.--windows --registry: with this PR it no longer stops (runs of 122 s and 92 s with the final build, no error), the codec 23 jobs come one per block at 187.5 per second, and the sound plays correctly. WithAPS5_TRACE_AJM=1the sound stutters, because the per-job trace lines slow the title's audio thread; that is the trace, not the decoder.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 (none added).mdfiles or images added to the repository (attach them to this PR)Closes #6671
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T14:39:51Z.
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.
core/libs/tests/GuestAjm.cppcore/libs/tests/GuestAjm.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T21:00:40Z.
The codec-23 trace and repeated-block regression give this implementation a strong evidence trail. One integration item remains from the overlap report: #6040 inserts tests at the same
GuestAjm.cpplocation, and #6672 adds the debt entry this PR supersedes. Please coordinate merge order with those authors and recordDepends on: #Nif one must land first; after the first merges, retain both test changes and make the debt entry match the landed implementation. The changes appear independent in behavior, but the shared hunks need an explicit resolution.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T21:01:13Z.
Follow-up from checking the live base: this PR still records base
82ddae75, while upstreammainisbc3c0fc1. Its current checks are conventions and intake only; they do not validate the rebased implementation. Please rebase onto currentmain, preserve the #6040 test and #6672 debt changes when resolving those shared hunks, then rerun the focused AJM tests before merge.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T09:41:07Z.
Rebase handoff — rebased onto current
main(authorship unchanged). Conflicts resolved: your codec-23 PCM test blocks sit alongsidemain's newer Opus gapless-reset test inGuestAjm.cpp, and your debt entry replaces the older "codec 23 is not implemented" one it supersedes.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
417176200.Imported from boykopovar/AnyPS5. Originally posted by Sevthered on 2026-10-17T16:19:15Z.
Thanks @blawesom, I took your rebase. I applied
417176200onto today'smain82f0c9aec, which needed no further changes, and pushed it as3f5f84996. The diff is the same as yours.@MarcZX100 both shared hunks are resolved: the codec 23 tests sit after #6040's Opus gapless-reset test in
GuestAjm.cpp, and the debt entry from #6672 is replaced by the one describing the implementation. Since both have merged, there is nothing left to list underDepends on.Focused tests on
3f5f84996:guest_ajmpasses (guest_ajm_teardownis only registered on Linux).guest_ajmandguest_ajm_teardownpass.tools/check_conventions.py --base origin/mainpasses.The AJM code itself is unchanged from the head I ran Broken Sword with, so I didn't rerun the title or the full suite on this head.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T03:09:27Z.
One malformed-input edge case in
RunPcm:SetResampleParametersstores the ratio without validation, and if it is NaN then both< framescomparisons here are false. The loop emits zero frames, the post-loop capacity check also passes, and the function reports the whole input consumed with a successful result. Could this reject a non-finite ratio (and cover it inTestPcmResample) so malformed state cannot silently drop a whole block of audio? I have not changed the PR branch.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T11:41:07Z.
Checked the diff against the trace in #6671: codec 23 is handled as interleaved s16 PCM through the existing Catmull-Rom resampler, and every case the title does not show throws (other input formats, ratio change, gapless, empty/partial input, small output, extra run flags, init through
sceAjmBatchJobControl, second resampled run without init). Non-finite or non-positive ratios are already rejected insceAjmBatchJobSetResampleParameters, soRunPcmcannot see a NaN.TestPcmResamplepins the output against an independent Catmull-Rom and the debt entry replaces the old "not implemented" one; merged.