audio: implement the AJM Opus decoder #858
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!858
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/858/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?
@joaodiaslobo on GitHub · 2026-09-26 23:06 UTC · original
joaodiaslobo:feat/ajm-opus→main· +218 −141 · 2 files · 2 commits · merged 2026-09-27 11:53 UTCThe AJM Opus decoder was a placeholder: it produced silence instead of decoding. Titles whose audio goes through it have no sound.
Gris (PPSA09804, #823) is affected: a Unity title whose audio decodes Opus through AJM, so all menu and gameplay audio is silent. Its cutscenes have sound because AvPlayer decodes through FFmpeg and never reaches AJM.
src/libs/ajm/opus_decoder.himplements the decoder over the vendored FFmpeg, followingaac_decoder.hand reusingAjmConvertFfmpegFrame.Gris now has correct audio in menus and throughout gameplay. Tested on Windows with clang-cl:
https://github.com/user-attachments/assets/9cac0dad-4741-451f-98fc-f1948f156099
@coderabbitai[bot] on GitHub · 2026-09-26 23:15 UTC · original · edited 2026-09-27 00:28 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
1309eec6-a6a6-4c79-a9d8-cfeb6897bafb📥 Commits
Reviewing files that changed from the base of the PR and between a14dc7787100388e5f651f541101f9b45ea4111d and
3eedb40721.📒 Files selected for processing (1)
src/libs/ajm/opus_decoder.hIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough
The AJM Opus decoder now uses FFmpeg instead of emitting silent frames. It validates initialization parameters, decodes length-prefixed Opus packets, handles gapless limits, and buffers decoded samples that do not fit in the output.
Priority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
3eedbNo outstanding defect is established for the Opus decoder change; it is ready to merge after normal checks.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
3eedbThe new decoder handles compressed audio that previously produced silence. Its packet processing can leave reported input consumption out of sync with decoder state after a partial failure, making recovery from malformed streams uncertain. The observed effect is confined to the existing audio-decoding path; broader attacker reach is not established.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-26 23:16 UTC · original
On
src/libs/ajm/opus_decoder.hline 194 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5964
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41985
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41592
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29896
Drain pending PCM before rejecting empty input.
When a final Opus packet produces more PCM than
output_size,AjmOpusDecoder::Decodeconsumes the packet, retains the excess inm_pending, and returnsAJM_RESULT_NOT_ENOUGH_ROOM. A public AJM decode retry with no remaining packet reaches the zero-input guard and returnsAJM_RESULT_PARTIAL_INPUTbeforeDrainPending, so the final samples are never written. Move the empty-input check after the pending drain.Suggested fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-09-26 23:16 UTC · original · edited 2026-09-27 00:31 UTC
On
src/libs/ajm/opus_decoder.hline 304 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41776
🤖 get_repo_knowledge executed:
get_repo_knowledge KytyPS5/KytyPS5 /tmp/coderabbit-repo-knowledge/kytyps5-kytyps5-b6cddd0b/architectureLength of output: 14418
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42115
🌐 Web query:
FFmpeg native libavcodec Opus decoder AVCodecContext sample_rate output 48000 source💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41686
🌐 Web query:
SceAjmDecOpusInitializeParameters sampleRate output PCM sampling rate AJM💡 Result:
Resample Opus output to
m_sample_rate.FFmpeg’s native Opus decoder forces decoded frames to 48000 Hz.
AjmConvertFfmpegFramepreserves that rate and configuresSwrContextwith the same input and output rate.AppendFramethen replaces the initialized format rate with 48000 Hz.For a supported lower-rate initialization, the decoder can therefore expose 48000-Hz PCM and report too many decoded samples. Add a target-rate parameter to
AjmConvertFfmpegFrame, resample tom_sample_rate, and keep the format rate fromInitialize.✅ Confirmed as addressed by @joaodiaslobo
@coderabbitai[bot] on GitHub · 2026-09-26 23:16 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
d337b106-a0d2-448f-b2da-9245937f8ac6📥 Commits
Reviewing files that changed from the base of the PR and between
bec67b7863and bd926c2ad7994a2c7610f80bec2b26e1c18871a2.📒 Files selected for processing (2)
src/libs/ajm.cppsrc/libs/ajm/opus_decoder.hIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-09-26 23:47 UTC · original · reviewed
♻️ Duplicate comments (1)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
29c376f1-b614-4793-b8e8-3c14f0c25b90📥 Commits
Reviewing files that changed from the base of the PR and between bd926c2ad7994a2c7610f80bec2b26e1c18871a2 and a14dc7787100388e5f651f541101f9b45ea4111d.
📒 Files selected for processing (1)
src/libs/ajm/opus_decoder.hIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@joaodiaslobo on GitHub · 2026-09-27 00:16 UTC · original
On
src/libs/ajm/opus_decoder.hline 304 (outdated):AjmConvertFfmpegFrameis shared with the AAC, MP3 and ATRAC9 decoders where taking the frame rate is correct, so adding a target rate parameter there reaches further than this PR. Every Opus stream I have seen initializes at 48000 Hz, but I can reject other rates inInitializewith a log line if preferred.@coderabbitai[bot] on GitHub · 2026-09-27 00:16 UTC · original
On
src/libs/ajm/opus_decoder.hline 304 (outdated):@joaodiaslobo, thanks for the clarification. I agree that changingAjmConvertFfmpegFramewould affect decoders outside this PR.For this PR, please reject non-48000 Hz rates in
AjmOpusDecoder::Initializeand log the unsupported rate. That keeps the accepted initialization rates consistent with the PCM rate produced by the current FFmpeg Opus path. Lower-rate output can be added later if needed.✏️ Learnings added
You are interacting with an AI system.
@joaodiaslobo on GitHub · 2026-09-27 00:23 UTC · original
On
src/libs/ajm/opus_decoder.hline 304 (outdated):Added the rate rejection in
Initialize.