fix(libSceVoice): queue the packets sceVoiceWriteToIPort accepts #7566

Closed
slick-daddy wants to merge 2 commits from upstream-pr/7566 into main
slick-daddy commented 2026-10-18 14:30:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slick-daddy on 2026-10-18T14:30:46Z.


What

sceVoiceWriteToIPort threw NotImplemented_nid_no_patch, so no title could hand a voice packet to the library. It now checks data, size, the library state and the port like the other port calls, writes to IN_PCMAUDIO and IN_VOICE ports only (IN_DEVICE and output ports throw), and takes size as both input and output: the packet is queued in the port and the accepted byte count is written back, a write that does not fit reporting 0 so the caller retries.

A PCM write ignores frameGaps and is capped by pcmaudio.buffer_size from SceVoicePortParam (5 x 3840-byte fallback when the port declares none). An encoded write takes 1 frame plus frameGaps missing frames, a negative gap acting as a backfill offset that occupies 1 frame here, and is capped at 5 frames of 20 ms, the frame being (bitrate * 20 + 7999) / 8000 for a voice port, which is what sceVoiceGetPortInfo reports. The four-argument signature is the PS Vita one in VitaSDK voice.h. Each packet records the frames it occupies, so the queue totals are read off the packets and sceVoiceResetPort drops them. libSceVoice moves from 19/22 to 20/22; sceVoiceEnableChat and sceVoiceDisableChat stay unimplemented.

Tested

Host tests only, no title and no console: guest_voice extended with PCM buffer_size, ignored PCM gap, negative-gap backfill and IN_DEVICE rejection cases. tools/check_conventions.py --base origin/main passes. MinGW and full guest test run not available on this machine (no MinGW/Ninja in PATH).

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: #6090 (same export; this queues packets while 6090 accepts-and-ignores, needs convergence before merge)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Other things worth reading before merge:

  • sceVoiceGetPortInfo.byte_count stays 0. The queued packets belong to the console's voice engine, and libSceVoiceChat reports every session request as signed out, so sceVoiceReadFromOPort can never return them. Reporting a non-zero byte_count would advertise bytes a read cannot return, and a title looping while (byte_count) read() would spin. The reasoning is in the debt file.
  • Nothing drains the queue. A title that writes without resetting fills the cap and is then refused with *size = 0, which is the signal a full console queue gives. The packet contents, and the gap count the console uses to insert silence, have no consumer in this build.
  • Unmeasured, and recorded in docs/dev/debt/libSceVoice.md: the console's queue depth, the meaning of its frame count, and the size it reports on a refused write.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909916390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7566). Originally posted by [slick-daddy](https://github.com/slick-daddy) on 2026-10-18T14:30:46Z. --- ### What sceVoiceWriteToIPort threw NotImplemented_nid_no_patch, so no title could hand a voice packet to the library. It now checks data, size, the library state and the port like the other port calls, writes to IN_PCMAUDIO and IN_VOICE ports only (IN_DEVICE and output ports throw), and takes size as both input and output: the packet is queued in the port and the accepted byte count is written back, a write that does not fit reporting 0 so the caller retries. A PCM write ignores frameGaps and is capped by pcmaudio.buffer_size from SceVoicePortParam (5 x 3840-byte fallback when the port declares none). An encoded write takes 1 frame plus frameGaps missing frames, a negative gap acting as a backfill offset that occupies 1 frame here, and is capped at 5 frames of 20 ms, the frame being (bitrate * 20 + 7999) / 8000 for a voice port, which is what sceVoiceGetPortInfo reports. The four-argument signature is the PS Vita one in VitaSDK voice.h. Each packet records the frames it occupies, so the queue totals are read off the packets and sceVoiceResetPort drops them. libSceVoice moves from 19/22 to 20/22; sceVoiceEnableChat and sceVoiceDisableChat stay unimplemented. ### Tested Host tests only, no title and no console: guest_voice extended with PCM buffer_size, ignored PCM gap, negative-gap backfill and IN_DEVICE rejection cases. tools/check_conventions.py --base origin/main passes. MinGW and full guest test run not available on this machine (no MinGW/Ninja in PATH). ### Checklist - [x] Based on current main; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation .md files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #6090 (same export; this queues packets while 6090 accepts-and-ignores, needs convergence before merge) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Other things worth reading before merge: - sceVoiceGetPortInfo.byte_count stays 0. The queued packets belong to the console's voice engine, and libSceVoiceChat reports every session request as signed out, so sceVoiceReadFromOPort can never return them. Reporting a non-zero byte_count would advertise bytes a read cannot return, and a title looping while (byte_count) read() would spin. The reasoning is in the debt file. - Nothing drains the queue. A title that writes without resetting fills the cap and is then refused with *size = 0, which is the signal a full console queue gives. The packet contents, and the gap count the console uses to insert silence, have no consumer in this build. - Unmeasured, and recorded in docs/dev/debt/libSceVoice.md: the console's queue depth, the meaning of its frame count, and the size it reports on a refused write.
github-actions[bot] commented 2026-10-18 14:31:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:31:32Z.


Progress report (7a36de6 → c2423e4)

📈 System libraries: 82.53% (+0.02%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceVoice sceVoiceWriteToIPort
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251112526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7566#issuecomment-6251112526). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:31:32Z. --- <!-- progress-report --> ### Progress report (7a36de6 → c2423e4) 📈 **System libraries**: 82.53% (+0.02%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceVoice | `sceVoiceWriteToIPort` | </details>
github-actions[bot] commented 2026-10-18 14:59:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:59:04Z.


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 6044 core/libs/tests/GuestVoice.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251385882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7566#issuecomment-6251385882). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:59:04Z. --- <!-- pr-overlap --> 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 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestVoice.cpp` |
wachi35676 commented 2026-10-19 01:10:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T01:10:01Z.


This implements the same export as #6090, which was opened on 2026-10-14 and tested on Linux there. The overlap isn't mentioned in this PR.

The queue model conflicts with the PS Vita sceVoiceWriteToIPort documentation in the VitaSDK header that this debt file already cites, voice.h#L446-L467. It has the same four-argument signature, so the PS3 Ex2 assumption isn't needed. The header says:

  • PCM writes ignore frame_gap;
  • for encoded input, a gap inserts missing frames, and a negative value is a valid backfill offset;
  • only IN_PCMAUDIO and IN_VOICE ports are written;
  • a PCM port's capacity is buffer_size from SceVoicePortParam (#L141-L145).

RPCS3's cellVoiceWriteToIPortEx2 (#L836-L853) only checks the port, and leaves size alone.

Reproduced with a probe on Windows 11 (GCC 15.2.0) and on Linux (GCC 13.3), base a373e85e5 with this PR:

voice port: accepted 5 of 5, write after 500 ms accepted 0 bytes, ReadFromOPort returned 0 bytes
pcm port buffer_size=64000: write of 64000 accepted 0 bytes; GetPortInfo byte_count=0 frame_size=0
pcm port: frame_gap=4 write accepted 3840, next write accepted 0
IN_DEVICE port write rc=0 accepted 40
  1. Nothing ever drains the queue, so after 100 ms of audio every later write reports 0 bytes until sceVoiceResetPort. A title that retries on 0 never gets through.
  2. A PCM port's pcmaudio.buffer_size is ignored; the cap is a fixed 5 × 3840 bytes.
  3. frame_gap on a PCM port takes queue space.
  4. A negative frame_gap throws.
  5. An IN_DEVICE port accepts writes.

guest_voice itself passes on both hosts, and aborts with Export.cpp reverted.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257516220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7566#issuecomment-6257516220). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-19T01:10:01Z. --- This implements the same export as #6090, which was opened on 2026-10-14 and tested on Linux there. The overlap isn't mentioned in this PR. The queue model conflicts with the PS Vita `sceVoiceWriteToIPort` documentation in the VitaSDK header that this debt file already cites, [`voice.h#L446-L467`](https://github.com/vitasdk/vita-headers/blob/ae5808f3105c42fa3373ba4ab64ab54e2e3ca848/include/psp2/voice.h#L446-L467). It has the same four-argument signature, so the PS3 `Ex2` assumption isn't needed. The header says: - PCM writes ignore `frame_gap`; - for encoded input, a gap inserts missing frames, and a negative value is a valid backfill offset; - only `IN_PCMAUDIO` and `IN_VOICE` ports are written; - a PCM port's capacity is `buffer_size` from `SceVoicePortParam` (`#L141-L145`). RPCS3's `cellVoiceWriteToIPortEx2` ([`#L836-L853`](https://github.com/RPCS3/rpcs3/blob/be69c054eeac57e2e671697a463473d37fe5a7b2/rpcs3/Emu/Cell/Modules/cellVoice.cpp#L836-L853)) only checks the port, and leaves `size` alone. Reproduced with a probe on Windows 11 (GCC 15.2.0) and on Linux (GCC 13.3), base `a373e85e5` with this PR: ``` voice port: accepted 5 of 5, write after 500 ms accepted 0 bytes, ReadFromOPort returned 0 bytes pcm port buffer_size=64000: write of 64000 accepted 0 bytes; GetPortInfo byte_count=0 frame_size=0 pcm port: frame_gap=4 write accepted 3840, next write accepted 0 IN_DEVICE port write rc=0 accepted 40 ``` 1. Nothing ever drains the queue, so after 100 ms of audio every later write reports 0 bytes until `sceVoiceResetPort`. A title that retries on 0 never gets through. 2. A PCM port's `pcmaudio.buffer_size` is ignored; the cap is a fixed 5 × 3840 bytes. 3. `frame_gap` on a PCM port takes queue space. 4. A negative `frame_gap` throws. 5. An `IN_DEVICE` port accepts writes. `guest_voice` itself passes on both hosts, and aborts with `Export.cpp` reverted. AI-assisted: yes (Claude Code); results above were run on this machine.
slick-daddy commented 2026-10-19 11:36:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slick-daddy on 2026-10-19T11:36:27Z.


Verified each point against the codebase and reworked the branch. Depends on 6090 is now declared in the PR body since both implement sceVoiceWriteToIPort and need convergence before merge. PCM buffer_size, PCM gap ignore, negative-gap backfill, IN_DEVICE rejection, and Vita signature source are addressed. Queue drain stays documented debt: libSceVoiceChat reports signed out so no packet can reach an output port, and a full queue reports 0 bytes as the full-queue signal.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6266282958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7566#issuecomment-6266282958). Originally posted by [slick-daddy](https://github.com/slick-daddy) on 2026-10-19T11:36:27Z. --- Verified each point against the codebase and reworked the branch. Depends on 6090 is now declared in the PR body since both implement sceVoiceWriteToIPort and need convergence before merge. PCM buffer_size, PCM gap ignore, negative-gap backfill, IN_DEVICE rejection, and Vita signature source are addressed. Queue drain stays documented debt: libSceVoiceChat reports signed out so no packet can reach an output port, and a full queue reports 0 bytes as the full-queue signal.
adriadam10 commented 2026-10-19 16:28:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:28:45Z.


Closing as a duplicate of #6090, which implements the same export (sceVoiceWriteToIPort), was opened first, has review feedback and a Linux run from another contributor. The overlap is the whole PR (same function, same GuestVoice.cpp test), so it can't be trimmed, and the checklist line "no other open PR implements the same functions" doesn't hold.

Separately, the queue model rests on values with no source: 5 frames, the 3840-byte fallback, a negative gap occupying 1 frame, and *size = 0 on a full queue. None of KytyPS5, shadPS4 or prosper has a body for this call, nothing reads or drains the queue (byte_count stays 0 and sceVoiceReadFromOPort returns nothing), and none of it is measured, so it adds state with no consumer.

If you want the Vita semantics (PCM ignoring frame_gap, encoded gap handling) in, please propose them on #6090 so there is a single change for this export. Welcome to reopen once that is settled.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272018508 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7566#issuecomment-6272018508). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T16:28:45Z. --- Closing as a duplicate of #6090, which implements the same export (`sceVoiceWriteToIPort`), was opened first, has review feedback and a Linux run from another contributor. The overlap is the whole PR (same function, same `GuestVoice.cpp` test), so it can't be trimmed, and the checklist line "no other open PR implements the same functions" doesn't hold. Separately, the queue model rests on values with no source: 5 frames, the 3840-byte fallback, a negative gap occupying 1 frame, and `*size = 0` on a full queue. None of KytyPS5, shadPS4 or prosper has a body for this call, nothing reads or drains the queue (`byte_count` stays 0 and `sceVoiceReadFromOPort` returns nothing), and none of it is measured, so it adds state with no consumer. If you want the Vita semantics (PCM ignoring `frame_gap`, encoded gap handling) in, please propose them on #6090 so there is a single change for this export. Welcome to reopen once that is settled.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7566
No description provided.