feat(libSceAudioIn): capture from the host's recording device #243
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/243"
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 adriadam10 on 2026-10-01T18:10:54Z.
What
Implements four
libSceAudioInexports with real capture through SDL (already bundled;libSceAudioOutuses it for playback).sceAudioInOpenvalidates type (0/1), index, grain (128/256), rate (16000/48000) and format (1 / 2 = S16 mono / stereo, 0x11 / 0x12 = float mono / stereo; 0x10 throws, see below), opens the default SDL recording device in that exact format and returns a handle. 8 ports, thenPORT_FULL.sceAudioInInputreturns one grain: it waits until the device has queued a full grain (up to four grains), copies it and pads any shortfall with silence. If more than four grains are queued, the oldest are dropped, so latency stays bounded when the title reads late. A null buffer flushes the queue.sceAudioInClosereleases the port and closes its host device.InputandCloseon a port that is still capturing returnBUSY.sceAudioInGetSilentStatereturns 0 with a recording device, andDEVICE_NONE(1) without one. Without a device a port still opens and delivers silence paced at the grain rate, as a console with no microphone would; titles that need the microphone (blowing into the DualSense, voice) get the real input when the host has one.--exclude-libs,ALL, as for FFmpeg).Sources (behaviour and constants only, no code copied):
Interop/Audio/AudioIn.cs). KytyPS5's currentsrc/libs/audio.cpp(OpenPort) uses the same validation.audioin.h) has S16 mono = 0, S16 stereo = 2 and accepts type 5. That is the PS4 library, so it is not followed here: 0 is refused as on the PS5 sources.NotImplementedinstead of guessing.BUSY0x8026010A) match KytyPS5 and shadPS4.With SDL linked in,
nid_patcheroverflowed this library's.dynstrby a few bytes; #242 (merged) fixed the patcher.Tested
Linux (CachyOS, GCC). New
guest_audio_intest (core/libs/tests/GuestAudioIn.cpp), run in two processes so each picks its SDL driver:capture: SDL'sdiskdriver reads a known S16 stereo recording from a file as the microphone; four grains come back sample-exact, then silence at end of file; silent state 0.no_device: no audio driver; silent state 1, five grains of silence paced at 16 ms, buffer bounds respected,PORT_FULLafter 8 ports,Closefrees a port (a second close and input on it areINVALID_HANDLE, and the next open reuses it), plus all validation errors, including format 0.It fails on each of three injected bugs (capture ignored, no pacing without a device, silent state ignoring the device). Full suite passes. Windows only through CI. Not tested with a physical microphone or a title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T18:11:19Z.
Progress report (
cd61f15→7e5ce94)📈 System libraries: 77.35% (+0.1%, +3 implemented functions)
✅ 3 implemented
sceAudioInClosesceAudioInGetSilentStatesceAudioInInputImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:39:18Z.
Thanks for taking this on. A few things don't match the references I could check. The format codes: shadPS4 (
audioin.h,OrbisAudioInParamFormat) and Kyty (Audio.cpp, AudioInOpen) both have S16 mono as 0 and S16 stereo as 2; this branch rejects 0 and maps 1 to mono, and the float codes 0x10 to 0x12 have no source I could find. shadPS4 also accepts type 5 (voice recognition) and other grain sizes, while Kyty doesn't validate size or rate at all, so the "follows KytyPS5" line in the description doesn't hold for the validation. AndsceAudioInClosestill throws while Open now takes a port and an SDL device, so a title that closes its port aborts; could Close be implemented in the same PR? With the codes fixed (or the unverified ones throwing) and Close in, I'd be glad to look again. #242 has landed in the meantime, so a rebase would leave only your commit here.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:39:58Z.
Thanks for checking the references. I dug into it, and I think the difference is which Kyty you looked at:
src/SharpProspero/Interop/Audio/AudioIn.cs) have S16Mono = 1, S16Stereo = 2, FloatMono = 0x11, FloatStereo = 0x12, and types VoiceChat = 0 and General = 1. Current KytyPS5 (src/libs/audio.cpp,OpenPort) has the same codes and the same type, grain and rate checks. The old InoriRus/Kyty and shadPS4 (audioin.h) are PS4, where mono is 0 and type 5 exists. So I kept the PS5 codes and now refuse 0 explicitly in the test.NotImplemented.sceAudioInClose: implemented. It releases the port and closes its SDL device, and Input/Close on a port that is mid-capture returnBUSY(0x8026010A), as in KytyPS5. The test covers close, a second close, input on a closed handle, and reuse of the freed port.guest_audio_in_captureandguest_audio_in_no_devicepass on Linux.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T06:55:13Z.
You're right, and thanks for digging into it: those were PS4 references. SharpProspero's PS5 bindings and current KytyPS5's
OpenPortboth use 1/2/0x11/0x12 with types 0 and 1, and your validation matches KytyPS5's synchronous open.Closeand the 0x10 throw look good, and it builds and passes here on current main. Merging.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:43:50Z.
Heads-up:
guest_audio_in_no_devicecrashes intermittently on Windows. It first hit the Windows job of an unrelated PR (#489), and I reproduced it on current main with four fork CI runs: 1 crash in 11 attempts on Windows, 0 on Linux, alwaysExit code 0xc0000409, which is what the UCRT reports forabortorstd::terminate. So the no-device path sometimes ends in an uncaught exception or an abort on Windows; maybe the SDL device open or close racing the capture thread? Could you take a look?Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T15:28:11Z.
Thanks for tracking it down. Fix in #532. The abort is the test's
elapsed >= 64 mscheck: on the CI toolchain,sleep_untilon a steady clock makes a singlesleep_for, and winpthreadsnanosleeptruncates it to whole milliseconds, so the no-devicesceAudioInInputcould return up to ~1 ms before its deadline. It now waits until the clock reaches the deadline.