fix(ngs2): retain PCM input when reporting decoded bytes #5548
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5548"
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 JJenkx on 2026-10-13T23:32:03Z.
What
Retain PCM input before reporting its bytes as decoded, so a caller reusing those reported bytes cannot alter samples still waiting in the resampler. This remains an experimental draft: the console's decode granularity, repeat visibility and waveform-pointer timing are not measured.
An ordinary playable block or a clipped stream piece is copied on first use and counted in
decoded_data_sizethen. Submission does not copy or count future input. Resampling andnum_decoded_samplesdrain the retained data independently. Repeat callbacks release the old copy before the next iteration decodes again. Callback metadata andwaveform_datakeep caller addresses and playback position. Integer-phase playback avoids unused lookahead, and high-pitch advancement accounts for skipped decoded input.Two reusable per-voice buffers each retain at most 64 KiB after consumption. Larger allocations, including a final drained piece of a starved stream, are released. Active whole-block copies remain proportional to the submitted playable range; large repeated blocks may allocate again on each loop. These limits and unverified console behavior are documented in library debt. No whole-waveform copy at submission is used.
Main now includes Ondra97's #6029 callback waveform-replacement correction. A callback replacing the waveform stops the old render path.
Tested
New current-main lifetime evidence, 2026-11-13: main
e8b95881c391already converts PCM into resampler scratch/history before reporting the bytes consumed. Its sampler path includes #11315. The focused regression proposed in #19349 passes with unchanged main production code in both NGS2 variants: six formats, mono/stereo, 44.1/48/96 kHz and pitch 0.75/1/2, 108 combinations per library.Every case overwrites only the reported prefix after each render, patches an unreported tail within the same submitted block after the first render, compares exact samples with the expected-tail reference, and confirms the late write affects output. Separate private controls for whole-block first-read snapshots and early byte reporting both fail at the sample comparison in both libraries; restoring main returns both complete PCM suites to green. Playback stays active throughout because empty-voice state clears counters.
This establishes the tested current-main ownership property, not console decode granularity, repeat visibility, waveform-pointer timing or current Quake audio. The experimental whole-block retention/accounting changes in this draft are not thereby qualified; its public head remains unchanged. A fresh title/audio result is still needed before claiming the historical static is resolved or assigning a remaining cause.
Exact pins, verbose tests, fault-control patches, regression and manifest, SHA-256
89476a4f9853fb89c2fdc17060e279cb2f014b9a26f46c5c17c2eed284193c96; downloaded archive and all 15 manifest members verified.Current-main integration still blocked, 2026-10-27 UTC: reviewed main
74acfad65b3f0fd4eab653f3a3989d298fba1157; the public head3b3710efcf760296bb594a748e8ec1c64fd1dbd3was not rewritten and this remains an open technical draft. The #10127 format/accounting integration requirement is substantive. Main's U8/I16/I24/I32/F32/F64 conversion, consumed-byte assertions, partial-input restrictions and additional NGS2 test registrations were preserved in the local analysis.Changing only the report counter while retaining a whole-block snapshot would hide legal later writes to an unreported tail in the same block. The earlier late-fill case uses a different future block and does not establish this case. A cache containing only already reported samples has no demonstrated future use in main's monotonic consumed-cursor and repeat-reset flow. A replacement decode/read-ahead policy needs reference evidence of granularity, repeat visibility and waveform-pointer lifetime; neither weakening main's assertions nor an I16-only workaround qualifies as an integration.
The attached same-block unreported-tail and 44.1 kHz cases are test designs from source review, not executed runtime tests. No new native, console, Windows or audio validation is claimed. The local integration remains stopped at its reproducible CMake conflicts; no unqualified source change was pushed.
Exact pins, unchanged upstream PCM-test hash, staged/stopped patches, counterexample design and bounded handoff. SHA-256:
aa2d6b9083a61cbd4227ff67ff88425dd29b86b608ddbe5b9fb1cd5d12a1aa2a; downloaded copy verified. Earlier passing tests below retain their exact historical scope.2026-10-25: head
ebfaae7a040a009579e4392300cfb5343234ed79, six linear topic commits on mainb90d009d9f73354cbea239a74a8f7e2dcd138772. Linux GCC 16.2.1 Release. Built both NGS2 libraries and all 18 focused test executables, including main's new voice-event tests. All 20 registered CTest groups passed three repetitions (60 passes, zero skips). Restoring the candidate after the main control reproduced all 60 passes and identical hashes for both libraries and all 18 test executables.The new
--reported-regionsmode runs the existing ring-buffer cases separately: mono and stereo at 48 kHz and 44.1 kHz, recycling only the bytes reported decoded, without assuming a whole-block decoded-byte count. Their function bodies are unchanged. Both main and the candidate pass these isolated cases. They do not independently demonstrate a buffer-lifetime failure on main.The control uses this branch's tests/CMake with exactly main's
Render.cpp,Voice.cppandNgs2Internal.hpp. Fourteen groups pass three repetitions; six fail: render, PCM-input and PCM-memory in each library variant. Full PCM-input fails at the decoded accounting assertion before the overwrite check. These failures show differences from the tests' accounting/memory policy; they must not be presented as independent proof of a copying bug or console equivalence.The rebase retains main's input-channel/custom-mastering changes and voice-event tests. Existing PCM helper bodies are unchanged from former public head
ddf93fbe14b4f036131e5c870a43874414414597; the complete render source also contains newer upstream changes. Source/whitespace checks pass. Conventions: zero errors, two existing debt-length warnings. Local merge-tree is clean against the exact tested main.Validation archive: verbose logs, controls, source comparisons and patches. SHA-256:
ecee379ddbd1c1758547169ae101f9b16340e0f820d25248275436761ad7e722; downloaded copy verified.No new native title/audio, Windows, GPU or performance result is claimed. The draft blockers remain console decode granularity, repeat visibility and waveform-pointer timing; CPU test success does not resolve them.
Historical title evidence, retaining its original scope: @DavidAmsellem's randomized blind Quake PPSA01880 comparison used main
0fbfd91e5against main plus this PR at89d293cc6, the same machine/runtime and stationary scene. The tester identified the PR run as clean and main as static before revealing the order. This supports that one-scene audio result, not console semantic equivalence or a freshly repeated result. The preceding report used different scenes and is correspondingly weaker for quantitative attribution. Earlier local diagnostic audio captures also used different rendered scenes. Prior revision-specific details are preserved in the comments and archive's original description.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.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:37:31Z.
Review: COMMENTED
The analysis is good: Quake refills a buffer for each positive delta of
decoded_data_size, so on the console those bytes must already be independent of the guest buffer by the time the counter reports them. That points at where the copy should happen. Copying the whole block atAddWaveformBlockstime is earlier than the protocol implies:decoded_data_sizeare no longer read from its buffer;A version that matches both observations: render from the guest buffer as
maindoes, and copy a block's bytes into the voice's retained buffer at the moment they are counted intodecoded_data_size(the same point at which the title is allowed to reuse them). Then the counter and the data lifetime are tied together by construction. Your "changing counter timing only reduced it" experiment suggests the counter currently runs ahead of the rendered position somewhere, and this would also surface that.Smaller: the
pcmvectors are allocated per block on the submission path, which is often an audio thread with tight deadlines. Reserving per voice, or pooling the vectors, avoids allocator calls there.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-14T03:17:31Z.
Agreed that the refill observation only establishes ownership for bytes counted as decoded; it does not establish that the console copies unread bytes at submission. I have returned this PR to draft and corrected the description to make that limitation explicit. I will not claim this snapshot implementation is ready to merge. The next revision needs late-fill/reuse coverage with retention tied to decoded-byte accounting, reusable storage, and a fresh Quake audio comparison.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-15T22:20:23Z.
Follow-up to the submission-time-copy review: current draft head
b21f78b0copies neither PCM nor decoded-byte accounting at submission.DecodePcmretains a playable block or clipped stream piece when first decoded and adds exactly those retained bytes todecoded_data_size; late-fill-before-decode and reuse-after-accounting are covered in both NGS2 variants. Two reusable per-voice buffers retain at most 64 KiB each after consumption; larger consumed buffers are released. The existing description records the 14 passing tests and the stereo-accounting negative control.This resolves the eager-submission-copy approach, but it does not establish that whole-block first-use decoding matches console granularity, repeat visibility or waveform-pointer timing. The PR stays draft. The Quake producer/SDL captures also show different scenes, so their discontinuity statistics do not prove a controlled audible improvement or resolve the earlier static-audio reports.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-16T02:56:54Z.
Closing this draft to free a slot under the 20-open-PR limit for an independently tested compiler change. This PCM draft still lacks console granularity/repeat evidence and a controlled audible improvement; it is not ready to merge.
The branch
fix/ngs2-owned-pcm-inputis preserved atb21f78b004f82469b8bad0dca31e26e8bb57eb5b. No code is discarded. It can be revisited when that evidence and a PR slot are available.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T16:26:25Z.
Listening verdict and a measurement for Quake (PPSA01880 v01.006.000), on AMD/Linux. This PR removes the constant background static. On unmodified
mainit is there the whole time. With this PR merged, the sound is clean to the ear, and the recorded stream backs that up.Setup:
main0fbfd91e5(it already has #6029 and #6476), and the samemainwith this PR's head merged (clean merge). Only the system libraries differ: the same relinkedapp.elfandapp0/. AMD Radeon RX 7900 XT (RADV NAVI31), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release, PipeWire.Method: the title opens two PipeWire playback streams. Fifteen seconds after start, both were recorded straight from the title's stream nodes for 60 s each (
pw-record --target <stream serial>, 48 kHz s16 stereo), not from the speakers or a mixed sink. The title was on its menu, attract demo or in play; the scenes were not matched between the two runs.main, stream Amain, stream BOn
main, stream B never reaches digital silence. The static is broadband: spectral flatness 0.59 between 100 Hz and 20 kHz, weighted to the low end. It has no peak at the 256-sample grain rate (187.5 Hz) or the 1024-sample port rate (46.9 Hz), and no autocorrelation at those lags. So it reads as garbage samples mixed in continuously, not as a grain-boundary fault. That fits stale PCM input being decoded, which is what this PR addresses. With the PR the floor goes to exact zero between sounds.One observation that I do not attribute to this PR: the PR's stream B reaches full scale on 0.03 % of its samples (1,781 samples, the longest run 126 samples, i.e. 2.6 ms), all between 33 s and 40 s. The demo scene differed between the two runs, the
mainrun never got that loud, and this looks like a loud in-game moment rather than a regression. I mention it in case the mixer's headroom matters.Not covered: only a few minutes per build, no long session, and Quake only.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T17:41:59Z.
Follow-up with a controlled, blind comparison on the same scene, since the recordings in my previous comment came from two different play sessions.
Setup as before: Quake (PPSA01880 v01.006.000), the same relinked
app.elfandapp0/, and only the system libraries differ.main0fbfd91e5against the samemainwith this PR's head89d293cc6merged. AMD Radeon RX 7900 XT (RADV NAVI31), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release, PipeWire.Protocol: a script picked the order at random and did not show it. Each run launched the title and recorded its PipeWire output streams for 90 s from launch, then closed it. In both runs the same actions were taken: New Game, Normal, then standing still at the start of the first map without moving or firing. I listened to each run and gave a verdict before the order was revealed.
mainOn the last 40 s of each recording, which is the standing-still part, measured per 1024-sample block (Hann window) on the stream that carries the game sound:
mainThe overall level is the same on both runs. On
mainthe band above 6 kHz is about 16 dB higher across the whole stretch, and the 100 Hz to 2 kHz band is also about 9 dB higher, which fits a broadband noise added on top of the same sound. That is the static I hear. Levels are in dB of the block FFT power, so only the differences between the two runs are meaningful.This covers one scene in one title on one AMD/Linux machine. I have no console reference, so it says nothing about granularity or repeat behaviour.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T17:46:49Z.
Thanks for the randomized blind same-scene follow-up. I added the attributed listening and last-40-second stream results to the description, with the exact source pins and one-scene scope. This is substantially stronger evidence for the static reduction than the earlier different-session recordings. The draft still records the unmeasured console decoder granularity, repeat visibility, and waveform-pointer timing; this comparison does not resolve those semantics.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T22:40:52Z.
Refreshed onto main
a6dcea9279as five linear commits; head isff47a6ae8a. The PCM production changes are unchanged, while main’s newer callback-reset, rack/render locking and nested-render checks are retained.Fresh Release builds of both library variants and all 17 NGS2 tests pass three repetitions, zero skips. Restoring only main’s production Render.cpp, Voice.cpp and Ngs2Internal.hpp makes both ownership tests fail the decoded-byte check in each of three runs. After restoring the candidate, all 17 tests pass three repetitions again; both library and all test hashes match the first candidate build. Merge-tree and whitespace checks pass; conventions have zero errors and two debt-length warnings.
Still draft for the unmeasured native decode granularity, repeat visibility and waveform-pointer timing. This refresh adds current-main regression evidence, not a new audio/title result.
AI-assisted: yes.
Pull request closed