Skip to content

fix(libSceAudioOut): return the console's codes from the legacy mastering calls - #16737

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:k/audioout-legacy-mastering-state
Nov 9, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:k/audioout-legacy-mastering-state

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

What

sceAudioOutMasteringTerm always returned 0, sceAudioOutMasteringInit(1) and sceAudioOutMasteringGetState with a states id other than 1 threw, and sceAudioOutMasteringGetState with id 1 answered before an Init. On a PS5 a Term without an Init returns 0x80260203, sceAudioOutMasteringInit(1) returns 0x80260201, sceAudioOutMasteringGetState returns 0x80260204 for a states id other than 1 and 0x80260203 for id 1 before an Init or after a Term. The legacy calls now keep an initialized flag: sceAudioOutMasteringInit(0) sets it, Term clears it, and the three calls return those codes. Other Init flags still throw because they were not measured. The 304 bytes the console writes for id 1 after an Init (8 of them non-zero) are not modelled; the debt entries say so.

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-07 at 06:55 UTC and 07:25 UTC; the console's own clock read about 1 h 41 min more (see the first comment). A title process may differ.

call PS5, payload process, firmware 11.60 main before here now
sceAudioOutMasteringTerm without Init, and a second Term 0x80260203 0 0x80260203
sceAudioOutMasteringInit(1) 0x80260201 throws 0x80260201
sceAudioOutMasteringInit(0), also repeated 0 0 0
sceAudioOutMasteringGetState, states id 0, 2 or 0xffffffff 0x80260204 throws 0x80260204
sceAudioOutMasteringGetState, states id 1 before Init or after Term 0x80260203 0 0x80260203

The test audio_out2_latency now checks these codes. On Ubuntu 24.04 under WSL2 with GCC 13.3.0 and an AddressSanitizer build, on main 006d11fca5 the test commit alone aborts, and with the fix commit on the same main it passes. All 64 audio_out* tests pass with this change. tools/check_conventions.py --base upstream/main passes.

Overlap: the 13 other open pull requests that change AudioOut2Mastering.cpp, AudioOut2Latency.cpp, AudioOut.cpp or docs/dev/debt/libSceAudioOut.md were checked on 2026-11-07 between 13:45 UTC and 13:50 UTC against main c32f751139 (the base of this change is the older 006d11fca5; it still merges without a conflict). Three already conflict with main without this change: #5021 and #14212 in the debt file, #12315 in other files. None conflicts only with this change; the other ten merge cleanly with and without it, among them #16597, #16614 and #16641, which edit other entries of the same files.

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 7, 2026 13:02
… mastering calls

On a PS5 (firmware 11.60, payload process) sceAudioOutMasteringTerm without
an Init returns 0x80260203, sceAudioOutMasteringInit(1) 0x80260201 and
sceAudioOutMasteringGetState 0x80260204 for a states id other than 1 and
0x80260203 for id 1 before an Init or after a Term.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ng calls

sceAudioOutMasteringTerm, sceAudioOutMasteringGetState and
sceAudioOutMasteringInit(1) now return the codes the console returns.

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

xXPBSXx commented Nov 7, 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 06:55 UTC and 07:25 UTC on 2026-11-07). The sources are unchanged (build ids d32e39796ef2 and 536525ee6a35).

sceAudioOutMasteringInit probe.c
/* Probe E: sceAudioOutMasteringInit, sceAudioOutMasteringTerm and sceAudioOutMasteringGetState, payload process,
   firmware 11.60 (debt libSceAudioOut.md: a repeated Init, a Term without Init and GetState before Init are unknown;
   non-zero Init flags). sceAudioOutInit runs first and the probe stops if it fails. Init is called with flags 0, and
   with flags 1 only after the mastering stage has been ended again. GetState gets a 336-byte marker buffer; only
   the return code and the number of changed bytes in the first 32 and the rest are printed. SetParam is not called.
   No NULL pointer is passed. No user ID is used. 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_init)(void);
typedef int (*fn_minit)(unsigned);
typedef int (*fn_mterm)(void);
typedef int (*fn_mstate)(void*);

static fn_mstate mState;

static void step(const char* id, const char* call, long r, int e) {
  char extra[32];
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
  probe_case(id, call, r, e, extra);
}

static void state_case(const char* id, const char* call) {
  unsigned char buf[336];
  char extra[96];
  memset(buf, 0x5a, sizeof buf);
  errno = 0;
  long r = mState(buf);
  int e = errno;
  int head = 0, rest = 0;
  for (size_t b = 0; b < sizeof buf; ++b)
    if (buf[b] != 0x5a) { if (b < 32) head++; else rest++; }
  snprintf(extra, sizeof extra, "0x%08x changed_first_32=%d changed_after=%d", (unsigned)r, head, rest);
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  char extra[32];
  probe_header();

  errno = 0;
  void* lib = dlopen("libSceAudioOut.sprx", RTLD_LAZY);
  probe_case("0", "load libSceAudioOut.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
  if (!lib) { probe_end(); return 0; }
  fn_init aoInit = (fn_init)dlsym(lib, "sceAudioOutInit");
  fn_minit mInit = (fn_minit)dlsym(lib, "sceAudioOutMasteringInit");
  fn_mterm mTerm = (fn_mterm)dlsym(lib, "sceAudioOutMasteringTerm");
  mState = (fn_mstate)dlsym(lib, "sceAudioOutMasteringGetState");
  if (!aoInit || !mInit || !mTerm || !mState) {
    probe_case("0b", "dlsym of the mastering functions", -1, 0, "missing");
    probe_end();
    return 0;
  }

  errno = 0;
  long r = aoInit();
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
  probe_case("1", "sceAudioOutInit()", r, errno, extra);
  if (r != 0) { probe_end(); return 0; }   /* no further call without a successful init */

  errno = 0; r = mTerm();  step("2", "sceAudioOutMasteringTerm() without Init", r, errno);
  state_case("3", "sceAudioOutMasteringGetState(&states) before Init");
  errno = 0; r = mInit(0); step("4", "sceAudioOutMasteringInit(0)", r, errno);
  errno = 0; r = mInit(0); step("5", "sceAudioOutMasteringInit(0) again", r, errno);
  state_case("6", "sceAudioOutMasteringGetState(&states) after Init");
  errno = 0; r = mTerm();  step("7", "sceAudioOutMasteringTerm()", r, errno);
  errno = 0; r = mTerm();  step("8", "sceAudioOutMasteringTerm() again", r, errno);
  state_case("9", "sceAudioOutMasteringGetState(&states) after Term");
  errno = 0; r = mInit(1); step("10", "sceAudioOutMasteringInit(1)", r, errno);
  if (r == 0) { errno = 0; r = mTerm(); step("11", "sceAudioOutMasteringTerm() after Init(1)", r, errno); }

  probe_end();
  return 0;
}
sceAudioOutMasteringInit raw output
PROBE	sceAudioOutMasteringInit	fw=0x11600005	build=d32e39796ef2	pid=106	utc=2026-11-07T08:36:37Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	1	sceAudioOutInit()	0	0	0x00000000
CASE	2	sceAudioOutMasteringTerm() without Init	-2144992765	0	0x80260203
CASE	3	sceAudioOutMasteringGetState(&states) before Init	-2144992764	0	0x80260204 changed_first_32=0 changed_after=0
CASE	4	sceAudioOutMasteringInit(0)	0	0	0x00000000
CASE	5	sceAudioOutMasteringInit(0) again	0	0	0x00000000
CASE	6	sceAudioOutMasteringGetState(&states) after Init	-2144992764	0	0x80260204 changed_first_32=0 changed_after=0
CASE	7	sceAudioOutMasteringTerm()	0	0	0x00000000
CASE	8	sceAudioOutMasteringTerm() again	-2144992765	0	0x80260203
CASE	9	sceAudioOutMasteringGetState(&states) after Term	-2144992764	0	0x80260204 changed_first_32=0 changed_after=0
CASE	10	sceAudioOutMasteringInit(1)	-2144992767	0	0x80260201
END	11
sceAudioOutMasteringGetState probe.c
/* Probe E: sceAudioOutMasteringGetState with the states id set, payload process, firmware 11.60 (debt
   libSceAudioOut.md:183 and 184: GetState before and after Init, and the states id). Follow-up to the run where the
   marker buffer gave 0x80260204 everywhere. The first 32-bit word of a 336-byte marker buffer is the states id (0, 1, 2
   and 0xffffffff are tried); only the return code, the number of changed bytes after that word and how many of them
   are non-zero are printed. sceAudioOutInit runs first and the probe stops if it fails; Init is called with flags 0
   and followed by Term. SetParam is not called. No NULL pointer is passed. No user ID is used. 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_init)(void);
typedef int (*fn_minit)(unsigned);
typedef int (*fn_mterm)(void);
typedef int (*fn_mstate)(void*);

static fn_mstate mState;

static void step(const char* id, const char* call, long r, int e) {
  char extra[32];
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
  probe_case(id, call, r, e, extra);
}

static void state_case(const char* id, const char* call, unsigned states_id) {
  unsigned char buf[336];
  char extra[96];
  memset(buf, 0x5a, sizeof buf);
  memcpy(buf, &states_id, 4);
  errno = 0;
  long r = mState(buf);
  int e = errno;
  int changed = 0, nonzero = 0;
  for (size_t b = 4; b < sizeof buf; ++b) {
    if (buf[b] != 0x5a) changed++;
    if (buf[b] != 0x5a && buf[b] != 0) nonzero++;
  }
  snprintf(extra, sizeof extra, "0x%08x changed_after_id=%d changed_nonzero=%d", (unsigned)r, changed, nonzero);
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  char extra[32];
  probe_header();

  errno = 0;
  void* lib = dlopen("libSceAudioOut.sprx", RTLD_LAZY);
  probe_case("0", "load libSceAudioOut.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
  if (!lib) { probe_end(); return 0; }
  fn_init aoInit = (fn_init)dlsym(lib, "sceAudioOutInit");
  fn_minit mInit = (fn_minit)dlsym(lib, "sceAudioOutMasteringInit");
  fn_mterm mTerm = (fn_mterm)dlsym(lib, "sceAudioOutMasteringTerm");
  mState = (fn_mstate)dlsym(lib, "sceAudioOutMasteringGetState");
  if (!aoInit || !mInit || !mTerm || !mState) {
    probe_case("0b", "dlsym of the mastering functions", -1, 0, "missing");
    probe_end();
    return 0;
  }

  errno = 0;
  long r = aoInit();
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
  probe_case("1", "sceAudioOutInit()", r, errno, extra);
  if (r != 0) { probe_end(); return 0; }   /* no further call without a successful init */

  state_case("2", "sceAudioOutMasteringGetState(id 1) before Init", 1);
  errno = 0; r = mInit(0); step("3", "sceAudioOutMasteringInit(0)", r, errno);
  if (r == 0) {
    state_case("4", "sceAudioOutMasteringGetState(id 1) after Init", 1);
    state_case("5", "sceAudioOutMasteringGetState(id 2) after Init", 2);
    state_case("6", "sceAudioOutMasteringGetState(id 0) after Init", 0);
    state_case("7", "sceAudioOutMasteringGetState(id 0xffffffff) after Init", 0xffffffffu);
    errno = 0; r = mTerm(); step("8", "sceAudioOutMasteringTerm()", r, errno);
    state_case("9", "sceAudioOutMasteringGetState(id 1) after Term", 1);
  }

  probe_end();
  return 0;
}
sceAudioOutMasteringGetState raw output
PROBE	sceAudioOutMasteringGetState	fw=0x11600005	build=536525ee6a35	pid=108	utc=2026-11-07T09:06:56Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	1	sceAudioOutInit()	0	0	0x00000000
CASE	2	sceAudioOutMasteringGetState(id 1) before Init	-2144992765	0	0x80260203 changed_after_id=0 changed_nonzero=0
CASE	3	sceAudioOutMasteringInit(0)	0	0	0x00000000
CASE	4	sceAudioOutMasteringGetState(id 1) after Init	0	0	0x00000000 changed_after_id=304 changed_nonzero=8
CASE	5	sceAudioOutMasteringGetState(id 2) after Init	-2144992764	0	0x80260204 changed_after_id=0 changed_nonzero=0
CASE	6	sceAudioOutMasteringGetState(id 0) after Init	-2144992764	0	0x80260204 changed_after_id=0 changed_nonzero=0
CASE	7	sceAudioOutMasteringGetState(id 0xffffffff) after Init	-2144992764	0	0x80260204 changed_after_id=0 changed_nonzero=0
CASE	8	sceAudioOutMasteringTerm()	0	0	0x00000000
CASE	9	sceAudioOutMasteringGetState(id 1) after Term	-2144992765	0	0x80260203 changed_after_id=0 changed_nonzero=0
END	10

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@JJenkx

JJenkx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 26f2741fd2, merged onto main 6c1efc7c59 (dc1c28e5b2, clean merge).

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

  • audio_out2_latency passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Progress report (c32f751 → 26f2741)

📈 System libraries: 31.57% (+0.0026%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceAudioOut sceAudioOutMasteringGetState

Changed libraries (implemented exports)

Library Before After Change
libSceAudioOut 68/219 (31.05%) 69/219 (31.51%) +0.46%

@github-actions

github-actions Bot commented Nov 7, 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 5021 docs/dev/debt/libSceAudioOut.md
PR 12863 docs/dev/debt/libSceAudioOut.md
PR 14212 docs/dev/debt/libSceAudioOut.md
PR 17691 core/libs/prx/libSceAudioOut/src/AudioOut2Mastering.cpp
core/libs/prx/libSceAudioOut/tests/AudioOut2Latency.cpp
docs/dev/debt/libSceAudioOut.md

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows run of head 26f2741fd2, merged onto main 286b14d2f7 in one tree with 47 other small open PRs that touch different files. Setup: Windows 11, WinLibs GCC 15.2 r7 (x86_64-ucrt-posix-seh, the CI toolchain), Release, BUILD_TESTING=ON.

  • audio_out2_latency with --repeat until-fail:5: 5 / 5 pass.
  • Negative control, with main's AudioOut2Mastering.cpp and this PR's test: 5 / 5 runs fail.

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.

4 participants