audio: keep NGS2 sampler voices within max_waveform_blocks #1450
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!1450
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1450/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-12 11:43 UTC · original
Cosmo:fix/ngs2-max-waveform-blocks→main· +549 −143 · 2 files · 1 commits · merged 2026-10-12 12:22 UTCQuake's background music was distorted and sounded like an alarm on repeat, compared to the game on PS5.
Quake streams the music through a ring of 4 buffers and reuses the oldest one for each new block.
Our sampler voices kept every block they got and ignored
max_waveform_blocks, so as far as I can tell, the voice was still playing a block that Quake was already overwriting.This change drops the oldest block once a voice holds more than
max_waveform_blocks. With it, the music sounds right.I don't know what the PS5 actually does when a voice gets more blocks than the limit. Dropping the oldest is my guess from how Quake uses its buffers. So the change could affect other games, for better or worse.
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-12 11:46 UTC · original
📝 Walkthrough
Walkthrough
Ngs2VoiceControl now removes the oldest queued PCM waveform blocks when the nonzero rack limit is exceeded. This applies to standard and custom sampler racks when no decoder is active. ATRAC9 queues and queues with a zero limit are not trimmed. Tests verify the queue size and rendered samples for both sampler types.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
10ee6Trimming may leave callback-driven audio suppliers waiting to reuse a buffer. Clarify the discarded-block callback behavior before merging, or explicitly accept that risk.
Pre-merge checks |
4 |
1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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-12 11:47 UTC · original
On
src/libs/ngs2.cppline 2415 (outdated):🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Notify the caller when trimming removes a block.
If a voice has a completion callback and a new PCM block exceeds
max_waveform_blocks,pop_front()removes the oldest block without callingNgs2FinishBlock. The caller never receives that block’s completion notification. A caller that waits for the notification before reusing a buffer can stop supplying audio. Preserve the completion callback contract when discarding a block.@coderabbitai[bot] on GitHub · 2026-10-12 11:47 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
af90f0dc-402e-4728-adc2-3eae8bdf71b5📥 Commits
Reviewing files that changed from the base of the PR and between
5ce9a52936and 10ee66076fb3204065a2454325ac781bfd10777b.📒 Files selected for processing (2)
src/libs/ngs2.cpptests/Ngs2SamplerTests.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-12 12:22 UTC · original
@Cosmo Much better now :) Thanks