Skip to content

docs(libSceAudioOut): compare sceAudioOutGetPortState with a PS5 and three emulators - #16736

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
xXPBSXx:e/docs-audioout-portstate
Nov 11, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
xXPBSXx:e/docs-audioout-portstate

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

What

Adds a technical-debt entry for sceAudioOutGetPortState. AnyPS5 reports output 1, volume 127 and a reroute counter of 0 for a main port; a PS5 reported output 0, volume -1 and a reroute counter of 5 for a 16-bit stereo main port, with 2 channels, flag 0 and active state 0 as AnyPS5 has them. shadPS4 reports volume -1 as the console did, KytyPS5 and fpPS4 report 127, and all three report output 1 and a reroute counter of 0. Only the entry is added; no code changes.

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 04:56 UTC (the console clock was about 1 h 41 min ahead), one run: sceAudioOutGetPortState returned 0 and a 16-byte record, identical before and after one output. A title process may differ. The probe source and its raw output are in the first comment. The emulator rows were read from shadPS4 0614ce324b (audioout.cpp lines 463-524), KytyPS5 5e837a9bea (audio.cpp lines 915-928) and fpPS4 04cefd43e6 (ps4_libsceaudioout.pas lines 384-418). tools/check_conventions.py --base upstream/main passes.

Overlap: the 15 open pull requests that change docs/dev/debt/libSceAudioOut.md were checked on 2026-11-07 between 13:35 UTC and 13:44 UTC against main c32f751139; two of them (#14330 and #16542) have been merged since. Of the other 13, three already conflict with main without this change (#5021 and #14212 in that file, #12315 in other files), and none conflicts only with this change. The other ten 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 (docs change)
  • AI-assisted: yes

AI-assisted (Claude Code).

xXPBSXx and others added 2 commits November 7, 2026 12:51
…three emulators

Record the record a PS5 on firmware 11.60 (payload process) returned for a stereo main port: output 0, 2 channels, volume -1, reroute counter 5, and how shadPS4, KytyPS5 and fpPS4 fill the same fields.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e length limit

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

xXPBSXx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256, here cacbea9945d6) and its complete raw output. The utc in the PROBE line is the console's own clock, about 1 h 41 min ahead of real UTC; the run started at 04:56 UTC. This pull request uses only cases 3 and 7 (sceAudioOutGetPortState on the open port, before and after the output); the other cases belong to other changes. The source is the one that ran, unchanged; its comments were written in English.

/* Probe E: sceAudioOutGetLastOutputTime and sceAudioOutGetPortState, payload process, firmware 11.60 (debt
   libSceAudioOut.md: what the last output time is, and the answer before any output). One port is opened with
   sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1), one block of silence (1024 samples, 16-bit stereo, all zero) is output
   and the port is closed. The output time is printed raw and as the difference to sceKernelGetProcessTime() taken
   just before and just after the output call. The port state record is a 64-byte marker buffer: only the return
   code, the number of changed bytes and its first 16 bytes are printed. No user ID of a person is used (0xff is the
   system user). 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_open)(int, int, int, unsigned, unsigned, unsigned);
typedef int (*fn_close)(int);
typedef int (*fn_output)(int, const void*);
typedef int (*fn_lastout)(int, uint64_t*);
typedef int (*fn_portstate)(int, void*);
typedef uint64_t (*fn_proctime)(void);

static fn_lastout aoLast;
static fn_portstate aoState;
static fn_proctime procTime;

static uint64_t now_us(void) { return procTime ? procTime() : 0; }

static void last_case(const char* id, const char* call, int handle, uint64_t t0, uint64_t t1) {
  uint64_t v = 0xdeadbeefdeadbeefULL;
  char extra[160];
  errno = 0;
  long r = aoLast(handle, &v);
  int e = errno;
  if (v == 0xdeadbeefdeadbeefULL)
    snprintf(extra, sizeof extra, "0x%08x value=untouched", (unsigned)r);
  else
    snprintf(extra, sizeof extra, "0x%08x value=%llu delta_to_before=%lld delta_to_after=%lld", (unsigned)r,
             (unsigned long long)v, (long long)(v - t0), (long long)(v - t1));
  probe_case(id, call, r, e, extra);
}

static void state_case(const char* id, const char* call, int handle) {
  unsigned char buf[64];
  char extra[160];
  memset(buf, 0x5a, sizeof buf);
  errno = 0;
  long r = aoState(handle, buf);
  int e = errno;
  int changed = 0;
  for (size_t b = 0; b < sizeof buf; ++b)
    if (buf[b] != 0x5a) changed++;
  snprintf(extra, sizeof extra, "0x%08x changed=%d first16=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
           (unsigned)r, changed, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10],
           buf[11], buf[12], buf[13], buf[14], buf[15]);
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  char extra[64];
  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_open aoOpen = (fn_open)dlsym(lib, "sceAudioOutOpen");
  fn_close aoClose = (fn_close)dlsym(lib, "sceAudioOutClose");
  fn_output aoOutput = (fn_output)dlsym(lib, "sceAudioOutOutput");
  aoLast = (fn_lastout)dlsym(lib, "sceAudioOutGetLastOutputTime");
  aoState = (fn_portstate)dlsym(lib, "sceAudioOutGetPortState");
  procTime = (fn_proctime)dlsym(RTLD_DEFAULT, "sceKernelGetProcessTime");
  if (!aoInit || !aoOpen || !aoClose || !aoOutput || !aoLast || !aoState) {
    probe_case("0b", "dlsym of the audio out functions", -1, 0, "missing");
    probe_end();
    return 0;
  }
  probe_case("0c", "dlsym(sceKernelGetProcessTime)", procTime ? 0 : -1, 0, procTime ? "found" : "missing");

  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;
  long h = aoOpen(0xff, 0, 0, 1024, 48000, 0x1);
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)h);
  probe_case("2", "sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1)", h, errno, extra);
  if (h <= 0) { probe_end(); return 0; }

  state_case("3", "sceAudioOutGetPortState(own port, &state)", (int)h);
  last_case("4", "sceAudioOutGetLastOutputTime(own port) before any output", (int)h, 0, 0);

  static short block[2048];   /* 1024 samples, stereo, all zero */
  memset(block, 0, sizeof block);
  uint64_t t0 = now_us();
  errno = 0;
  r = aoOutput((int)h, block);
  uint64_t t1 = now_us();
  snprintf(extra, sizeof extra, "0x%08x took_us=%llu", (unsigned)r, (unsigned long long)(t1 - t0));
  probe_case("5", "sceAudioOutOutput(own port, one silent block)", r, errno, extra);

  last_case("6", "sceAudioOutGetLastOutputTime(own port) after one output", (int)h, t0, t1);
  state_case("7", "sceAudioOutGetPortState(own port) after output", (int)h);

  errno = 0;
  long c = aoClose((int)h);
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)c);
  probe_case("8", "sceAudioOutClose(own port)", c, errno, extra);

  last_case("9", "sceAudioOutGetLastOutputTime(closed handle)", (int)h, t0, t1);
  state_case("10", "sceAudioOutGetPortState(closed handle)", (int)h);
  last_case("11", "sceAudioOutGetLastOutputTime(handle -1)", -1, t0, t1);
  state_case("12", "sceAudioOutGetPortState(handle -1)", -1);

  probe_end();
  return 0;
}

Raw output:

PROBE	sceAudioOutGetLastOutputTime	fw=0x11600005	build=cacbea9945d6	pid=99	utc=2026-11-07T06:37:51Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	0c	dlsym(sceKernelGetProcessTime)	0	0	found
CASE	1	sceAudioOutInit()	0	0	0x00000000
CASE	2	sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1)	536870912	0	0x20000000
CASE	3	sceAudioOutGetPortState(own port, &state)	0	0	0x00000000 changed=15 first16=0000025affff05000000000000000000
CASE	4	sceAudioOutGetLastOutputTime(own port) before any output	0	0	0x00000000 value=0 delta_to_before=0 delta_to_after=0
CASE	5	sceAudioOutOutput(own port, one silent block)	1024	0	0x00000400 took_us=12
CASE	6	sceAudioOutGetLastOutputTime(own port) after one output	0	0	0x00000000 value=228641 delta_to_before=2 delta_to_after=-10
CASE	7	sceAudioOutGetPortState(own port) after output	0	0	0x00000000 changed=15 first16=0000025affff05000000000000000000
CASE	8	sceAudioOutClose(own port)	0	0	0x00000000
CASE	9	sceAudioOutGetLastOutputTime(closed handle)	-2144993279	0	0x80260001 value=untouched
CASE	10	sceAudioOutGetPortState(closed handle)	-2144993279	0	0x80260001 changed=0 first16=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
CASE	11	sceAudioOutGetLastOutputTime(handle -1)	-2144993277	0	0x80260003 value=untouched
CASE	12	sceAudioOutGetPortState(handle -1)	-2144993277	0	0x80260003 changed=0 first16=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
END	14

@github-actions github-actions Bot added the docs label Nov 7, 2026
@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 14212 docs/dev/debt/libSceAudioOut.md
PR 18044 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.

Docs check of head c152826a44 against main 0bae53facd: I compared what the entry says about the code with the code, and checked the links and counts. I can't check the console measurements themselves.

The description of the code matches sceAudioOutGetPortState (AudioOut.cpp:609-628): reroute counter 0, volume 127, flag 0, active state 0, output 1 for a main port, and channels capped at 2.

@adriadam10 adriadam10 self-assigned this Nov 11, 2026
@adriadam10
adriadam10 merged commit a99761e into boykopovar:main Nov 11, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the entry against sceAudioOutGetPortState in AudioOut.cpp (reroute counter 0, volume 127, flag 0, active state 0, output 1, channels capped at 2) and conventions; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants