Skip to content

fix(libSceNgs2): reset the geometry parameters to the console's values - #17673

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:k/ngs2-geom-reset-console
Nov 12, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:k/ngs2-geom-reset-console

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What

sceNgs2GeomResetListenerParam and sceNgs2GeomResetSourceParam wrote defaults that differ from a PS5 in two listener fields and ten source fields, and zeroed the reserved words that the console leaves untouched. They now write what a PS5 wrote: listener front (0, 0, -1) and sound speed 340.29; source direction (0, 0, 0), cone 1.0/30.0/0.2/60.0, rolloff model 5 with a maximum distance of 100.0, LFE level 0, radius 1.0, 7 speakers and matrix format 8. Position, velocity and up axis of the listener, the doppler factor, the full-band, maximum and minimum levels and the rolloff factor and reference distance already matched. The transform tests keep their own front axis and sound speed. A title process was not measured; PPSA15552 (Dead Cells) is the title the debt entry names as calling sceNgs2GeomResetSourceParam. sceNgs2GeomApply derives its channel count from matrix_format, so a source reset by a title now yields an 8-channel matrix instead of a 2-channel one; this was not run with the title.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-09 at 04:24 UTC and 04:54 UTC (two runs, identical); the console's own clock read about 1 h 41 min more (see the first comment). A title process may differ.

field written by the reset PS5, payload process, firmware 11.60 main before here now
listener orient_front (0, 0, -1) (0, 0, 1) (0, 0, -1)
listener sound_speed 340.29 343.0 340.29
source direction (0, 0, 0) (0, 0, 1) (0, 0, 0)
source cone 1.0 / 30.0 / 0.2 / 60.0 1.0 / 360.0 / 1.0 / 360.0 1.0 / 30.0 / 0.2 / 60.0
source rolloff model, max distance 5, 100.0 0, 1000000.0 5, 100.0
source lfe_level, radius 0.0, 1.0 1.0, 0.0 0.0, 1.0
source num_speakers, matrix_format 7, 8 2, 2 7, 8
reserved words (listener bytes 52 to 59, source bytes 100 to 107) untouched zeroed untouched

The tests ngs2_geom now expect these values. On Ubuntu 24.04 under WSL2 with GCC 13.3.0 and an AddressSanitizer build, on main 0ef5a14e6a the test commit alone aborts, and with the fix commit on the same main it passes; all 48 ngs2* tests pass with this change when leak detection is off; with it on, 27 of the 48 fail on LeakSanitizer reports (ngs2_geom passes), which I did not compare with main. tools/check_conventions.py --base upstream/main passes.

Overlap: the 8 other open pull requests that change Geom.cpp, Ngs2Geom.cpp or docs/dev/debt/libSceNgs2.native.md were checked on 2026-11-09 between 08:25 UTC and 08:32 UTC against main 75c65bf005 (the base of this change is the older 0ef5a14e6a; it still merges without a conflict). Three already conflict with main without this change (#5548, #12107 and #14212), and none conflicts only with this change. The other five merge cleanly with and without it.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (audio change)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

xXPBSXx and others added 3 commits November 9, 2026 06:53
…stenerParam and ResetSourceParam

On a PS5 (firmware 11.60, payload process) the listener reset writes front
(0, 0, -1) and a sound speed of 340.29 and the source reset writes a zero
direction, cone 1.0/30.0/0.2/60.0, rolloff model 5 with max distance 100.0,
lfe level 0, radius 1.0, 7 speakers and matrix format 8. Both leave the
reserved words untouched. The transform tests keep their own front axis and
sound speed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
sceNgs2GeomResetListenerParam and sceNgs2GeomResetSourceParam wrote
defaults that differ from a PS5 in two listener and ten source fields, and
zeroed the reserved words the console leaves untouched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Probe sources (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256) and their raw output. The clock in each PROBE line is the console's own clock, which was about 1 h 41 min ahead of the host clock (runs at 04:24 UTC and 04:54 UTC on 2026-11-09). The sources are unchanged (build ids 1688aacb138f and d56661fd9fcc); the words in the raw output are the 32-bit words of the written bytes.

sceNgs2GeomResetListenerParam probe.c (run at 04:24 UTC)
/* Probe E: sceNgs2GeomResetListenerParam, sceNgs2GeomResetSourceParam and sceNgs2GeomCalcListener, payload process,
   firmware 11.60 (debt libSceNgs2.native.md:89 and :90: the defaults the reset calls write, the structure sizes and
   the transform that CalcListener builds were taken from emulators and are not measured on a PS5). The three calls
   only fill caller-owned buffers: no system, rack or voice is created and nothing is rendered. The output buffers
   are 512 bytes filled with a marker; the number of changed bytes and the changed region are printed as hex words
   (floats), so no handle, user or device data can appear. CalcListener gets the reset listener parameter as its
   input with flags 0 and 1. No NULL pointer is passed. There is no initialization call for these functions. Nothing
   is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h>   /* only for kernel_get_fw_version() */

#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
   itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
}

/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
   thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
   as a second safeguard. */
static void* probe_watchdog(void* arg) {
  static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
  unsigned left = PROBE_MAX_S;
  (void)arg;
  while (left) left = sleep(left);
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
  return 0;
}

static void probe_watchdog_start(void) {
  pthread_t t;
  if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  probe_watchdog_start();
  struct tm tmv;
  gmtime_r(&now, &tmv);
  strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
  printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
         getpid(), utc);
  fflush(stdout);
}

static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
  printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
  fflush(stdout);
  cases++;
}

static void probe_end(void) {
  printf("END\t%d\n", cases);
  fflush(stdout);
}








typedef int (*fn_reset)(void*);
typedef int (*fn_calc)(const void*, void*, unsigned);

#define BUF 512

static void dump(const char* id, const char* call, long r, int e, const unsigned char* buf) {
  char extra[1200];
  int changed = 0, last = -1;
  for (int b = 0; b < BUF; ++b)
    if (buf[b] != 0x5a) { changed++; last = b; }
  int words = last < 0 ? 0 : (last / 4) + 1;
  int n = snprintf(extra, sizeof extra, "0x%08x changed_bytes=%d last_changed_offset=%d words=", (unsigned)r, changed, last);
  for (int w = 0; w < words && n < (int)sizeof extra - 12; ++w) {
    unsigned v;
    memcpy(&v, buf + w * 4, 4);
    n += snprintf(extra + n, sizeof extra - n, "%08x%s", v, w + 1 < words ? " " : "");
  }
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();

  errno = 0;
  void* lib = dlopen("libSceNgs2.sprx", RTLD_LAZY);
  probe_case("0", "load libSceNgs2.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
  if (!lib) { probe_end(); return 0; }
  fn_reset resetListener = (fn_reset)dlsym(lib, "sceNgs2GeomResetListenerParam");
  fn_reset resetSource = (fn_reset)dlsym(lib, "sceNgs2GeomResetSourceParam");
  fn_calc calc = (fn_calc)dlsym(lib, "sceNgs2GeomCalcListener");
  char extra[64];
  snprintf(extra, sizeof extra, "reset_listener=%d reset_source=%d calc=%d", resetListener != 0, resetSource != 0, calc != 0);
  probe_case("0b", "dlsym of the Geom functions", (resetListener && resetSource && calc) ? 0 : -1, 0, extra);
  if (!resetListener || !resetSource || !calc) { probe_end(); return 0; }

  static unsigned char listener[BUF];
  static unsigned char source[BUF];
  static unsigned char work[BUF];

  memset(listener, 0x5a, sizeof listener);
  errno = 0;
  long r = resetListener(listener);
  dump("1", "sceNgs2GeomResetListenerParam(&param)", r, errno, listener);

  memset(source, 0x5a, sizeof source);
  errno = 0;
  r = resetSource(source);
  dump("2", "sceNgs2GeomResetSourceParam(&param)", r, errno, source);

  /* CalcListener input: the reset listener parameter without the marker bytes behind it. */
  static unsigned char input[BUF];
  memset(input, 0, sizeof input);
  memcpy(input, listener, 64);

  memset(work, 0x5a, sizeof work);
  errno = 0;
  r = calc(input, work, 0);
  dump("3", "sceNgs2GeomCalcListener(reset param, &work, flags 0)", r, errno, work);

  memset(work, 0x5a, sizeof work);
  errno = 0;
  r = calc(input, work, 1);
  dump("4", "sceNgs2GeomCalcListener(reset param, &work, flags 1)", r, errno, work);

  probe_end();
  return 0;
}
raw output (run at 04:24 UTC)
PROBE	sceNgs2GeomResetListenerParam	fw=0x11600005	build=1688aacb138f	pid=102	utc=2026-11-09T06:05:57Z
CASE	0	load libSceNgs2.sprx	0	3	loaded
CASE	0b	dlsym of the Geom functions	0	0	reset_listener=1 reset_source=1 calc=1
CASE	1	sceNgs2GeomResetListenerParam(&param)	0	0	0x00000000 changed_bytes=52 last_changed_offset=51 words=00000000 00000000 00000000 00000000 00000000 bf800000 00000000 3f800000 00000000 00000000 00000000 00000000 43aa251f
CASE	2	sceNgs2GeomResetSourceParam(&param)	0	0	0x00000000 changed_bytes=100 last_changed_offset=99 words=00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 3f800000 41f00000 3e4ccccd 42700000 00000005 42c80000 3f800000 3f800000 3f800000 3f800000 00000000 3f800000 00000000 3f800000 00000007 00000008
CASE	3	sceNgs2GeomCalcListener(reset param, &work, flags 0)	0	0	0x00000000 changed_bytes=84 last_changed_offset=83 words=3f7f91b1 00000000 80000000 00000000 80000000 3f7f910f 80000000 00000000 00000000 00000000 3f7f910f 00000000 80000000 80000000 80000000 3f800000 00000000 00000000 00000000 43aa251f 00000000
CASE	4	sceNgs2GeomCalcListener(reset param, &work, flags 1)	0	0	0x00000000 changed_bytes=84 last_changed_offset=83 words=bf7f91b1 00000000 80000000 00000000 00000000 3f7f910f 80000000 00000000 00000000 80000000 bf7f910f 00000000 80000000 80000000 80000000 3f800000 00000000 00000000 80000000 43aa251f 00000001
END	6
sceNgs2GeomResetListenerParam probe.c (run at 04:54 UTC)
/* Probe E: sceNgs2GeomResetListenerParam, sceNgs2GeomResetSourceParam and sceNgs2GeomCalcListener, payload process,
   firmware 11.60 (debt libSceNgs2.native.md:89 and :90: the defaults the reset calls write, the structure sizes and
   the transform that CalcListener builds were taken from emulators and are not measured on a PS5). The three calls
   only fill caller-owned buffers: no system, rack or voice is created and nothing is rendered. The output buffers
   are 512 bytes filled with a marker; the number of changed bytes and the changed region are printed as hex words
   (floats), so no handle, user or device data can appear. CalcListener gets the reset listener parameter as its
   input with flags 0 and 1. No NULL pointer is passed. There is no initialization call for these functions. Nothing
   is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h>   /* only for kernel_get_fw_version() */

#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
   itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
}

/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
   thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
   as a second safeguard. */
static void* probe_watchdog(void* arg) {
  static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
  unsigned left = PROBE_MAX_S;
  (void)arg;
  while (left) left = sleep(left);
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
  return 0;
}

static void probe_watchdog_start(void) {
  pthread_t t;
  if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  probe_watchdog_start();
  struct tm tmv;
  gmtime_r(&now, &tmv);
  strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
  printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
         getpid(), utc);
  fflush(stdout);
}

static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
  printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
  fflush(stdout);
  cases++;
}

static void probe_end(void) {
  printf("END\t%d\n", cases);
  fflush(stdout);
}








typedef int (*fn_reset)(void*);
typedef int (*fn_calc)(const void*, void*, unsigned);

#define BUF 512

static void dump(const char* id, const char* call, long r, int e, const unsigned char* buf) {
  char extra[1200];
  int changed = 0, last = -1;
  for (int b = 0; b < BUF; ++b)
    if (buf[b] != 0x5a) { changed++; last = b; }
  int words = last < 0 ? 0 : (last / 4) + 1;
  int n = snprintf(extra, sizeof extra, "0x%08x changed_bytes=%d last_changed_offset=%d words=", (unsigned)r, changed, last);
  for (int w = 0; w < words && n < (int)sizeof extra - 12; ++w) {
    unsigned v;
    memcpy(&v, buf + w * 4, 4);
    n += snprintf(extra + n, sizeof extra - n, "%08x%s", v, w + 1 < words ? " " : "");
  }
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();

  errno = 0;
  void* lib = dlopen("libSceNgs2.sprx", RTLD_LAZY);
  probe_case("0", "load libSceNgs2.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
  if (!lib) { probe_end(); return 0; }
  fn_reset resetListener = (fn_reset)dlsym(lib, "sceNgs2GeomResetListenerParam");
  fn_reset resetSource = (fn_reset)dlsym(lib, "sceNgs2GeomResetSourceParam");
  fn_calc calc = (fn_calc)dlsym(lib, "sceNgs2GeomCalcListener");
  char extra[64];
  snprintf(extra, sizeof extra, "reset_listener=%d reset_source=%d calc=%d", resetListener != 0, resetSource != 0, calc != 0);
  probe_case("0b", "dlsym of the Geom functions", (resetListener && resetSource && calc) ? 0 : -1, 0, extra);
  if (!resetListener || !resetSource || !calc) { probe_end(); return 0; }

  static unsigned char listener[BUF];
  static unsigned char source[BUF];
  static unsigned char work[BUF];

  memset(listener, 0x5a, sizeof listener);
  errno = 0;
  long r = resetListener(listener);
  dump("1", "sceNgs2GeomResetListenerParam(&param)", r, errno, listener);

  memset(source, 0x5a, sizeof source);
  errno = 0;
  r = resetSource(source);
  dump("2", "sceNgs2GeomResetSourceParam(&param)", r, errno, source);

  /* CalcListener input: only the 52 bytes the reset call wrote (case 1); everything behind them is zero. The first run copied 64 bytes and so passed 12 marker bytes (0x5a) as part of the input. */
  static unsigned char input[BUF];
  memset(input, 0, sizeof input);
  memcpy(input, listener, 52);

  memset(work, 0x5a, sizeof work);
  errno = 0;
  r = calc(input, work, 0);
  dump("3", "sceNgs2GeomCalcListener(reset param, &work, flags 0)", r, errno, work);

  memset(work, 0x5a, sizeof work);
  errno = 0;
  r = calc(input, work, 1);
  dump("4", "sceNgs2GeomCalcListener(reset param, &work, flags 1)", r, errno, work);

  probe_end();
  return 0;
}
raw output (run at 04:54 UTC)
PROBE	sceNgs2GeomResetListenerParam	fw=0x11600005	build=d56661fd9fcc	pid=104	utc=2026-11-09T06:35:56Z
CASE	0	load libSceNgs2.sprx	0	3	loaded
CASE	0b	dlsym of the Geom functions	0	0	reset_listener=1 reset_source=1 calc=1
CASE	1	sceNgs2GeomResetListenerParam(&param)	0	0	0x00000000 changed_bytes=52 last_changed_offset=51 words=00000000 00000000 00000000 00000000 00000000 bf800000 00000000 3f800000 00000000 00000000 00000000 00000000 43aa251f
CASE	2	sceNgs2GeomResetSourceParam(&param)	0	0	0x00000000 changed_bytes=100 last_changed_offset=99 words=00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 3f800000 41f00000 3e4ccccd 42700000 00000005 42c80000 3f800000 3f800000 3f800000 3f800000 00000000 3f800000 00000000 3f800000 00000007 00000008
CASE	3	sceNgs2GeomCalcListener(reset param, &work, flags 0)	0	0	0x00000000 changed_bytes=84 last_changed_offset=83 words=3f7f91b1 00000000 80000000 00000000 80000000 3f7f910f 80000000 00000000 00000000 00000000 3f7f910f 00000000 80000000 80000000 80000000 3f800000 00000000 00000000 00000000 43aa251f 00000000
CASE	4	sceNgs2GeomCalcListener(reset param, &work, flags 1)	0	0	0x00000000 changed_bytes=84 last_changed_offset=83 words=bf7f91b1 00000000 80000000 00000000 00000000 3f7f910f 80000000 00000000 00000000 80000000 bf7f910f 00000000 80000000 80000000 80000000 3f800000 00000000 00000000 80000000 43aa251f 00000001
END	6

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@JJenkx

JJenkx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 338ccc9451, merged onto main 0dd2fffe35 (9a292dd1ae, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • ngs2_control_reentry_guards, ngs2_detached_pending, ngs2_lifecycle, ngs2_lifecycle_guards, ngs2_ownership, ngs2_rackinfo pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5548 docs/dev/debt/libSceNgs2.native.md
PR 14212 docs/dev/debt/libSceNgs2.native.md

@oneandonlydean
oneandonlydean merged commit c85dcfd into boykopovar:main Nov 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants