Commit Graph

51 Commits

Author SHA1 Message Date
MarcZX100 852c808373 test(libSceNgs2): fix custom filter regression expectations 2026-10-14 08:47:31 +13:00
Jnbla6 ef52b16920 feat(libSceNgs2.native): add custom voice filter support and related tests for 0x13 issue case 2026-10-14 08:39:32 +13:00
Jnbla6 855823e85e feat(libSceNgs2.native): implement custom sampler rack id 0x4001 (#4334) 2026-10-14 08:39:32 +13:00
lorkydey dadc23a8c1 fix(libSceNgs2): reject unverified listener transforms 2026-10-12 23:12:40 +02:00
lorkydey 4168cf3bbd feat(libSceNgs2): calculate the listener coordinate transform 2026-10-12 23:10:42 +02:00
Del'aRun cac398cb96 feat(libSceNgs2): implement the Geom reset functions
Implement sceNgs2GeomResetListenerParam and sceNgs2GeomResetSourceParam,
taken from #1021 and limited to the two reset functions. The Geom
structures get their real layouts. sceNgs2GeomCalcListener and
sceNgs2GeomApply stay unimplemented.

Co-Authored-By: Dextroid17 <217507631+Dextroid17@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:39:27 +04:00
Simon 233590462c fix(libSceNgs2): report EMPTY for a streaming sampler that played its queue
A playing sampler voice whose waveform still accepts blocks (CONTINUE)
reported only INUSE|PLAYING after it had played every queued block, so
a title that waits for EMPTY before it reuses the voice never did.
PPSA18391 (engine: Clickteam Fusion) reads state_flags & 0x22 != 2 from
sceNgs2VoiceGetState as the end of a sound; each of its sound effects
played once and never again.

The voice now also reports EMPTY (0x20) in that state and keeps
playing, so blocks added later still play. A waveform that was closed
without CONTINUE does not report it.
2026-10-12 00:26:12 +02:00
EdouardSence 295e48f059 feat(libSceNgs2): export sceNgs2ReportRegisterHandler and sceNgs2ReportUnregisterHandler
PPSA04540 (Rise of the Ronin) imports both and now loads past them;
calling either throws until NGS2 produces reports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 15:11:24 +02:00
gookie 132715e4e2 perf(libSceNgs2.native): parse waveform files without reading their samples
sceNgs2ParseWaveformFile read everything from the offset to the end of
the file into a zero-filled buffer and parsed that, although parsing
uses only the RIFF chunk headers and the fmt, fact and smpl payloads.
A waveform at an offset in a sound bank cost a read of the rest of the
bank on each call.

ReadChunks now takes the bytes through an accessor. Waveform data passes
its buffer; a waveform file seeks to and reads the headers and those
payloads alone, with the same checks against the length from the offset
to the end of the file. The format dispatch both use moves to
ParseWaveform.

ngs2_parse adds a bank of two waveforms in one file, the second with a
chunk after its samples, and parses each at its offset.

PPSA21402 (Balatro) parses its five 33 MB music tracks at start: one
call took 8.3 to 26.7 ms and allocated 33 MB, and now takes 0.01 to
0.04 ms with the same result.
2026-10-11 02:29:13 +02:00
Adrià Franch 2cd63a7ec2 test(libSceNgs2.native): pass a non-null data pointer for dataless blocks
AddWaveformBlocks rejects a null data pointer before reaching the silence
path, so TestSilenceBlock aborted and its dataless rejection passed for the
wrong reason.
2026-10-11 00:38:22 +02:00
Adrià Franch 271a8f291e fix(libSceNgs2.native): throw for a dataless silence-flag block on an ATRAC9 voice
GatherSuperframe finishes a block with no data at once, so such a block
would not play num_samples of silence (requested by @oneandonlydean).
2026-10-11 00:37:58 +02:00
PhialsBasement 2d9b6aebb7 feat(libSceNgs2.native): render silent waveform blocks with flag 0x10
A waveform block that declares samples with no data threw as not
fitting them. PPSA04867 adds such a block with flags 0x11 (data_size 0,
num_samples 16385) and terminates the process on the throw, followed by
a fully specified block under the same flags, which takes the ordinary
path. Accept flag 0x10, named SILENCE here: a dataless block under it
renders num_samples frames of silence and finishes like a complete
block, reporting its bytes through decoded_data_size. A dataless block
without the flag keeps throwing. No public reference names the flag;
the assumption is recorded in TechnicalDebt.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-11 00:37:42 +02:00
Dean 903863c974
Merge pull request #959 from JAB-dev/feat/ngs2-pan
feat(libSceNgs2.native): implement sceNgs2PanInit and sceNgs2PanGetVolumeMatrix
2026-10-10 18:53:48 +13:00
Dean 14469b74e8
Merge pull request #964 from JAB-dev/fix/ngs2-unset-matrix-passthrough
fix(libSceNgs2.native): mix ports without set levels through the default channel map
2026-10-10 18:36:02 +13:00
TibixDev 2d1031b7b9 test(ngs2): cover append boundaries and missing waveform metadata 2026-10-10 00:50:24 +02:00
TibixDev 4a04a78bfc fix(ngs2): decode ATRAC9 across streamed waveform blocks
Keep logical sample and skip counts across byte-only continuation buffers, assemble split superframes, and allow callbacks to refill, pause or reset the stream. Preserve decoded audio while waiting for input and reject truncated closed streams.

Validated with seven NGS2 tests, an ASan/UBSan streaming test build, and PPSA03747 repeatedly supplying continuation buffers during playback. Flag semantics follow the pinned KytyPS5 source documented in TechnicalDebt.md.

Written with AI assistance.
2026-10-10 00:50:23 +02:00
Dean 9ee4972db6
Merge pull request #2336 from JAB-dev/feat/ngs2-reverb-rack
feat(libSceNgs2.native): reverb rack following the PS4 libSceNgs2 reverb
2026-10-10 10:59:54 +13:00
JAB-dev 00e13ecfa7 feat(libSceNgs2.native): implement sceNgs2PanInit and sceNgs2PanGetVolumeMatrix
Pan follows the PS4 firmware 11.00 libSceNgs2.sprx: the speaker layout
from the init angles, then each param's angle and distance into a
volume matrix for the voice. Every param is checked before anything is
written, and angles too large to wrap throw. The pan functions are
exported from the existing Voice.cpp export block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 23:26:24 +02:00
JAB-dev 9af48b5b02 test(libSceNgs2.native): destroy the system after the unsupported default map render
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 23:25:40 +02:00
JAB-dev ed9a70175e fix(libSceNgs2.native): mix ports without set levels through the default channel map
A port without a matrix sent source channel n to destination channel n, so a
mono voice reached only the left channel of a stereo mix. The PS4 firmware
11.00 libSceNgs2.sprx mixes such ports, and ports whose matrix levels were
never set, through a fixed channel map instead: mono reaches both stereo
channels at -3 dB and the centre of 5.1 and 7.1, stereo folds to mono at
-3 dB per side, and wider sources fold down with 0.5 and -3 dB gains. The map
was measured for every source width into 1, 2, 6 and 8 channels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 23:25:31 +02:00
JAB-dev 56d8e5c4df fix(libSceNgs2.native): mix through a selected matrix whose levels were never set
PPSA22520 routes its title music through port matrix 0 without setting the
matrix levels, so the music rendered silent. A matrix without levels now
mixes like a port without a matrix, source channel n to destination channel
n. The console's initial levels are unknown; the assumption is recorded in
TechnicalDebt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 23:25:31 +02:00
JAB-dev 255ed1de7c test(libSceNgs2.native): keep the matrix level clamp clear of the other NGS2 changes
Use INFINITY and NAN from <cmath> instead of a new <limits> include, and
list the TechnicalDebt entry beside the other NGS2 voice entries, so the
change merges cleanly with the pan, channel map and reverb changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 17:55:06 +02:00
JAB-dev 473ca04b2f fix(libSceNgs2.native): throw on reverb rack sizes and sample rates the reverb does not handle
A reverb_size other than the default was accepted and ignored, and below
about 7.5 kHz an allpass length went negative and wrapped to a 16 GB buffer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 17:38:18 +02:00
JAB-dev 1986905adb Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into feat/ngs2-reverb-rack 2026-10-08 19:38:46 +02:00
JAB-dev d6821edc67 fix(libSceNgs2.native): clamp matrix levels to -4..4 as the PS4 libSceNgs2 does
The PS4 firmware 11.00 libSceNgs2.sprx stores matrix levels clamped to
-4..4, keeps NaN, and rejects a level count of 0. Levels were stored
unclamped, so a level of 8 played twice as loud as on the console, and a
count of 0 cleared the matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 19:36:19 +02:00
TibixDev 0d4db860a6 feat(ngs2): implement legacy submixer UserFx callbacks
Invoke the title callback on planar mixed samples and silence. Preserve per-voice callback data, reset registration on setup, and release the render guard on callback failure. Include behavioral tests and source references. Written with AI assistance.
2026-10-08 13:18:41 +02:00
TibixDev 9a78bda01b feat(ngs2): parse forward ATRAC9 waveform loops
Split looped waveforms into decoder-aligned intro, loop and tail blocks, preserving the encoder delay and finite or infinite repeat counts. Parse trailing sampler chunks and reject malformed loop ranges.

Validation: all seven NGS2 CTest cases passed; standalone ATRAC9 tests passed with ASan, UBSan and leak detection. AI-assisted implementation.
2026-10-08 10:00:47 +03:00
Gjon Gojcevic 88e77da57b feat(libSceNgs2.native): stream 16-bit PCM waveforms through appended waveform blocks
A 16-bit PCM block whose num_samples exceed its data starts a stream, and waveform blocks with flag 0x2 append more data to it. The voice outputs silence while it has played all appended data and CONTINUE is set, and ends at num_samples or when CONTINUE is cleared.
2026-10-08 07:35:59 +02:00
Dean 91b6a46222
Merge pull request #1197 from gookie-dev/fix/ngs2-state-outlives-exit
fix(libSceNgs2.native): keep the system list and its mutex alive through static teardown
2026-10-08 09:23:17 +13:00
Dean 76543c2e89
Merge pull request #1020 from gjonn/feat/ngs2-parse-waveform-file
feat(libSceNgs2.native): implement sceNgs2ParseWaveformFile and parse 16-bit PCM waveforms
2026-10-08 09:21:16 +13:00
Gjon Gojcevic 02166268ea test(libSceNgs2.native): run the waveform parse tests in their own executable
On Linux ngs2_atrac9 aborted without any output once TestParseFile was part of
its main(). The exception that TestCorruptSuperframeAtPageEnd throws in the
Ngs2 module and catches in main() has to resume through a cleanup landing pad
inside main(). That resume goes through the unwinder statically linked into the
test executable, which then fails with _URC_FATAL_PHASE2_ERROR and aborts
silently. Whether main() gets such a pad depends on what the compiler inlines
into it, so adding any function with non-trivial cleanups to that main() is
enough to trigger it.

Move the PCM and file parse tests into a new ngs2_parse executable and restore
Ngs2Atrac9.cpp to its upstream content, so the test that catches exceptions is
unchanged. The new executable has no catch and never relies on that path.
2026-10-07 09:49:31 -04:00
gookie a2bb991171 fix(libSceNgs2.native): keep the system list and its mutex alive through static teardown
sceNgs2SystemRender and the other entry points look up their handles in a
function-local std::vector guarded by a function-local std::recursive_mutex.
Both were destroyed with the other statics when the process exits, while a
title's audio thread can still be rendering: std::exit runs the destructors
on the exiting thread and other threads keep running until the process
ends. The freed vector then no longer holds the system, so rendering
returns SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE, and a lookup that walks the
racks reads freed memory and crashes.

Both are now allocated once and never destroyed, as other driver state that
must outlive static teardown already is.

PPSA21402 (Balatro) printed "Error: sceNgs2SystemRender() 804A0230" and
segfaulted in Ngs2FindVoice (from sceNgs2VoiceGetState) when it was closed.

ngs2_render now renders from an atexit handler registered before the first
NGS2 call, which runs after the library's statics are destroyed; without
this change it fails on that render.
2026-10-07 14:00:37 +02:00
JAB-dev e493328eb7 Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into feat/ngs2-reverb-rack 2026-10-07 07:01:30 +02:00
Gjon Gojcevic 5bae4df0b6 feat(libSceNgs2.native): mix a stereo mastering voice into a 6 or 8 channel render buffer
The mixing stage threw when a mastering voice and its render buffer had different channel counts. A 2-channel voice is now mixed into the first two channels of a 6- or 8-channel buffer; other mismatches still throw.
2026-10-06 22:23:40 -04:00
Gjon Gojcevic 1bdc37bb86 test(libSceNgs2.native): write the ParseWaveformFile test file where the guest path resolves
On Linux every absolute guest path is resolved under the working directory, so the temporary file in the host temp directory was not found. The test now asks ResolvePath_nid_no_patch for the host path of a guest path and writes the file there.
2026-10-06 22:14:23 -04:00
Gjon Gojcevic 74a7a1d9f1 fix(libSceNgs2.native): take (path, offset, info) in sceNgs2ParseWaveformFile and reject PCM data that does not fit
The call site of PPSA21402 sets only three argument registers, so the function has no size parameter. A data chunk that runs past the buffer or ends inside a frame returns INVALID_WAVEFORM_DATA instead of being shortened. The test no longer writes padding from a string literal.
2026-10-06 22:14:23 -04:00
Gjon Gojcevic 64230cf95a feat(libSceNgs2.native): implement sceNgs2ParseWaveformFile and parse 16-bit PCM waveforms 2026-10-06 22:14:23 -04:00
JAB-dev e15f1644e3 fix(libSceNgs2.native): reverb as the PS4 libSceNgs2 does
The reverb was a Freeverb-style approximation. It now follows the PS4
firmware 11.00 libSceNgs2.sprx, read and checked against its output: the
input mixed to mono with the library's fixed gains, a 14400-sample buffer
with four reflection taps from the reflection pattern tables and a late
feed, sixteen damped comb filters with a pre-emphasis stage, a signed
selection of combs and four allpasses per output channel, a two-pole room
HF filter, and the library's parameter clamps, crossfades and setup
defaults. The test values are the PS4 library's own output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 01:26:11 +02:00
JAB e289b56e6f
feat(libSceNgs2.native): implement sceNgs2RackGetInfo, sceNgs2VoiceGetPortInfo and sceNgs2VoiceQueryInfo (#958)
RackGetInfo reports the rack's handles, buffer, id, uid, option limits,
render count and active voices. VoiceGetPortInfo reports a port's matrix,
volume and destination. VoiceQueryInfo answers info id 0x4001 with the
voice channel count and throws for other ids. Assumptions are recorded in
TechnicalDebt.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 11:10:30 +13:00
Dean 5fc8755f4c
Merge pull request #961 from JAB-dev/feat/ngs2-mastering-gain
feat(libSceNgs2.native): mastering voice gain parameter
2026-10-07 10:22:26 +13:00
JAB-dev 34bdc37b76 feat(libSceNgs2.native): reverb rack with I3DL2 parameters
Rack 0x2001 is created with its option layout and KytyPS5's defaults, takes
the setup (0x20010000) and I3DL2 (0x20010001) voice params and reports the
common voice state. The voice mixes its inputs and runs a Freeverb-style
approximation driven by the I3DL2 parameters: room and room HF, early
reflections and their delay, late reverb and its pre-delay, decay time and
HF ratio, and diffusion. Out-of-range params throw, param changes keep the
tail, a stop or kill clears it, and the tail ends once it decays below
1e-20. The console's algorithm is unknown; the approximation is recorded in
TechnicalDebt. The test context buffer pool grows to 64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 22:21:28 +02:00
JAB-dev 81a332c148 feat(libSceNgs2.native): mastering voice gain parameter
Mastering voice param 0x30000004 sets a full-band and an LFE level. They
scale the mastering voice when it is mixed into the render buffer, the LFE
level on channel 3 of 6- and 8-channel voices. Non-finite levels are
invalid arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 22:21:28 +02:00
Adrià Franch 5784515e13 fix(libs): use the referenced NGS2 handle and session signaling argument error codes
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 14:39:02 +02:00
Dean 2f7c9e5914
Merge pull request #812 from adriadam10/feat/ngs2-system-state
feat(ngs2): system sample rate, user data and lock
2026-10-06 22:33:34 +13:00
Adrià Franch 6dbdd927ee feat(ngs2): system sample rate, user data and lock
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 08:02:42 +02:00
Adrià Franch 5a031f3ef6 fix(ngs2): start UserFx2 process flags at 1 on the first call 2026-10-06 07:40:12 +02:00
Adrià Franch 52869f0112 feat(ngs2): custom submixer rack with UserFx2 modules
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 07:40:12 +02:00
Adrià Franch 819c045327 feat(libSceNgs2.native): sampler voice low-pass filter
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-06 07:16:25 +02:00
Alberto Ruiz 9879deca69 fix(audio): bound ATRAC9 decoding to the superframe
LibAtrac9 read its bitstream without a length, so a corrupt ATRAC9 frame
made the decoder read past the end of the guest's buffer. Update the
submodule to 946e05a ("Prevent bitstream overruns"), whose decode
functions take the buffer size, and pass the bytes left in the
superframe from NGS2, AJM and Audiodec. The callers already reject a
frame that consumes more than the superframe holds.

ngs2_atrac9 places a synthetic corrupt superframe right before an
inaccessible page and expects the render to report the decode failure;
with the previous LibAtrac9 it crashes with a segmentation fault.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R5WJS4ZdQynAJesCZKH5hb
2026-10-03 14:25:49 +02:00
Adrià Franch 69bd750c46 feat(libSceNgs2.native): decode ATRAC9 sampler voices, parse and size ATRAC9 waveforms
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-02 09:24:46 +02:00