audio: let the AJM Opus decoder write part of a packet #1914
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1914
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1914/head"
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?
@Cosmo on GitHub · 2026-10-26 07:45 UTC · original
Cosmo:fix/ajm-opus-small-output→main· +621 −18 · 5 files · 1 commits · merged 2026-10-28 20:31 UTCA game using FMOD had no in-game sound. It decodes Opus into 1024-byte outputs, but each packet decodes to 1920 bytes. The decoder only wrote whole packets, so every call returned NOT_ENOUGH_ROOM and nothing was decoded.
Now the decoder writes as much of a packet as fits and keeps the rest for the next call. With it, the game has sound.
ajm_opus_testscovers this.What I don't know is whether the PS5 reports NOT_ENOUGH_ROOM when it has to keep part of a packet for the next call. This change reports OK.
AI use
Research, implementation and tests were done with Claude Code at my direction.
I reviewed the code, and tested it as described above.
@coderabbitai[bot] on GitHub · 2026-10-26 07:50 UTC · original · edited 2026-10-28 20:24 UTC
Walkthrough
The PR adds an
AjmResamplerfor Opus decoding, connects its parameter controls and resampling information to AJM results, and adds a test executable with CTest registration. The tests cover chunked output, resampling ratios, retained PCM, format changes, and loop behavior.Suggested reviewers:
nmzikPriority:
Normal
Change: Feature
Merge Risk:
Low · up to
edc97Resampled audio can report a false drained state or carry old audio into a new stream. These bounded issues warrant fixes or explicit acceptance before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 25 functions across 4 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-26 07:50 UTC · original
On
src/libs/ajm/opus_decoder.hline 85 (outdated):🔎 Supported by static analysis
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 13904
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12861
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14000
Web query:
Sony PlayStation AJM sceAjmBatchJobDecodeSingle multiple frames contractResult:
Stop a single-frame call after draining pending PCM.
AjmBatchJobDecodeSinglepassesfalseformultiple_frames. WhenWritePcmemptiesm_pcm_buffer, the pending-PCM path continues into the input loop without checking that flag. A single-frame call can therefore write the remainder of one packet, consume the next packet, and write part of it.Return after draining pending PCM when
multiple_framesisfalse. Preserve the existing multi-frame behavior.Suggested fix
Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-26 07:50 UTC · original · reviewed
Actionable comments posted: 1
d3239bd1-d648-4be5-bca7-e003515a4478Reviewing files that changed from the base of the PR and between
f90a8b1589and e0508eebc9cf4e870907d157bbe6caa5a8f206c3.CMakeLists.txtsrc/libs/ajm/opus_decoder.htests/AjmOpusTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@Nmzik on GitHub · 2026-10-28 18:45 UTC · original
@Cosmo PPSA game code?
@Cosmo on GitHub · 2026-10-28 18:50 UTC · original
PPSA33626 works best to demonstrate.
In-game there was basically no sound
@ -0,0 +41,4 @@info.ratio = static_cast<float>(m_ratio);info.num_samples = m_end && m_position >= Samples()? -1: static_cast<int32_t>(std::ceil(Samples() - m_position));@coderabbitai[bot] on GitHub · 2026-10-28 20:24 UTC · original
Clamp
num_samplesto 0 unless the stream has ended.GetInfo()can report a negativenum_samplesbefore END is set.m_positioncan exceedSamples()after the last buffered sample is consumed.Compact()removes onlySamples()from the position, so the remainder stays andSamples() - m_positionbecomes negative.Example: a stream has 959 source samples (960 with
skip1) and the ratio is 2. The last write movesm_positionto 960, andCompact()leaves 1.GetInfo()then returnsceil(0 - 1) = -1. This is the same value as the end-of-stream marker.tests/AjmResampleTests.cpptreatsnum_samples < 0as "stream drained". A caller can therefore see a false end-of-stream.Proposed fix
Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-28 20:24 UTC · original · reviewed
Actionable comments posted: 1
10fadde3-95d4-44d4-88b1-6134ebcd9adaReviewing files that changed from the base of the PR and between e0508eebc9cf4e870907d157bbe6caa5a8f206c3 and
edc97ec0ea.CMakeLists.txtsrc/libs/ajm.cppsrc/libs/ajm/decoder.hsrc/libs/ajm/resampler.htests/AjmResampleTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.