feat(pad): stream vibration ports to a Bluetooth DualSense as haptics reports #9154

Merged
LeandroLP23 merged 5 commits from upstream-pr/9154 into main 2026-11-05 03:59:19 +00:00
LeandroLP23 commented 2026-10-21 13:55:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-21T13:55:08Z.


What

#2056: over Bluetooth a DualSense has no sound card, so vibration ports reach it only as motor rumble (#7633). The DualSense takes haptics audio in HID output report 0x32. This PR streams the vibration ports there when the controller is connected over Bluetooth. The report layout, CRC and configuration report follow beecrepaldi-afk's P5M implementation (gui/src/macDualSenseBluetooth.mm), offered under GPL-2.0 on #2056, and the commit carries their authorship. The structure is the one MarcZX10 and oneandonlydean described there.

  • Owner. PadInput, which owns the SDL controller, decides when to stream. It streams for a PS5 controller whose HID path enumerates with interface_number -1, which is Bluetooth; a USB DualSense has interface 3. It opens a second, shared handle with SDL_hid_open_path, sends one report 0x31 (motor power reduction 0, haptics low-pass on, only valid_flag1 bits), then runs its own pacing thread. It sends one 32-frame block as a report 0x32 once two blocks are buffered, at most one report per 10.67 ms (one block at 3 kHz). It waits on a deadline with PreciseSleepUntil, so a backlog drains one report per interval rather than back to back, and a report after a pause goes out at once without a catch-up burst. During silence nothing is sent: blocks of all-zero samples are skipped.
  • Audio side. AudioOut2 (with no pad sound card) and the legacy sceAudioOut vibration port hand their two vibration channels to PadSubmitHapticFrames while the stream is open. Otherwise they make motor rumble, as on main. libScePad's PadHapticBuffer averages them down to 3 kHz 8-bit stereo in 16-frame boxes and keeps the newest 160 frames (53 ms) for the thread.
  • Failure. There is no environment switch. A failed SDL_hid_write logs once and stops the stream until the controller reconnects. The stream-open flag stays set until then, so both audio paths keep handing the vibration ports to the stopped stream (whose buffer keeps only its newest 160 frames) and never turn them into motor rumble. When slot 0's controller closes, the flag clears, and a reconnect opens a new stream.
  • Reports. DualSenseHaptics::Report and PowerReport build the 0x32 and 0x31 reports. The new dualsense_haptics test checks both byte for byte, including the CRC32 over 0xA2 plus the report, computed independently with Python's zlib.crc32. It also checks the buffer's 48 kHz and 44.1 kHz downsampling, block taking and overflow, and the report deadlines (DualSenseHaptics::NextReport): the 10.67 ms interval, the spacing of buffered reports and no burst after a pause. With the 0xA2 seed removed it fails: report byte 138 is 0xca, expected 0xe2.
  • Rumble. A title's scePadSetVibration rumble still goes out through SDL's report 0x31, which sets the bit that turns audio haptics off. Once slot 0's rumble stops, the stream thread sends its own configuration report 0x31 again after 100 ms, giving SDL's asynchronous rumble-off report time to go first. Without it the haptics came back at a different strength after a rumble (third commit; measured below).
  • Strength. ANYPS5_RUMBLE (#12686) scales the streamed samples the same way it scales the pad sound card's, so 0 keeps a Bluetooth DualSense silent.
  • Debt. docs/dev/debt/libSceVideoOut.md records the box filter, the paced sending rate, the rumble interplay on a title, and the stop on a failed write.

Ports (after #7881). The stream follows port 0, like the vibration ports' motor rumble on main. It opens when a controller takes slot 0 and closes when slot 0's controller closes. The haptic buffer stays process-wide, next to the per-port pad slots.

Tested

  • Rebased onto main 409fe64199, head 64a2841b83. dualsense_haptics now also checks the stream at 100, 50 and 0 percent. It passes, as do the pad, haptics and audio-out tests built for this head (71 of them, including pad_rumble_intensity and audio_out2_pad_haptic_intensity), on Windows 11 26300, WinLibs GCC 15.2.0, Release.

Windows 11 26300, WinLibs GCC 15.2.0, Release. DualSense over Bluetooth; feature report 0x20 gives firmware 0x010d0002, update version 0x0633, hardware 0x00000917, build Sep 18 2025.

Head f0da5c4877, on main 3d2b7c0673.

  • End to end over Bluetooth, this head. A harness outside the tree links this build's libSceVideoOut, libSceAudioOut and libScePad. It creates a PadInput, opens a legacy vibration port (sceAudioOutOpen type 10, 48 kHz, s16 stereo) and outputs a 150 Hz sine at 0.8, 3 s on channel 0 only, then 3 s on channel 1 only. It was run with 256-, 1024- and 2048-frame ports; before this revision the larger two sent their blocks back to back. In all three the haptics were felt continuous, left then right, and no write failed.

  • Pacing, measured. A local, uncommitted timing log in the stream thread (not part of this PR) recorded each report's deadline, write start and write end, about 560 reports per run:

    Port Gap between write starts Start after its deadline (max) Write time (mean / max)
    256 frames 9.92–11.30 ms 0.75 ms 0.11 / 0.27 ms
    1024 frames 7.81–13.45 ms 2.91 ms 0.11 / 0.50 ms
    2048 frames 9.12–12.21 ms 1.55 ms 0.12 / 0.48 ms

    The first attempt waited with std::this_thread::sleep_until. On this host it overslept by up to 13 ms, so a third of the gaps were above 13 ms and another third below 9.5 ms, down to 0.1 ms, where the next late report went straight out. PreciseSleepUntil from libc/include/PreciseWait.hpp, already used in VideoOutDriver.cpp, fixed that; the table is with it.

  • Write failure, this head. The same harness played channel 0 for 120 s and the controller was switched off during it. The write failed after about 1400 reports and logged once: Pad: a Bluetooth DualSense haptics report failed (…); haptics stop until the controller reconnects. Writes up to then were 9.66–11.67 ms apart. The port kept playing to the end: PadHapticStreamOpen stayed true, and the largest audioVibrationLarge/audioVibrationSmall that PadFetchOutputForPort(0) returned during the whole run was 0, so the vibration audio did not turn into motor rumble.

  • Earlier rounds, by @seradavid on an RX 9070 XT host with a Bluetooth DualSense (comment). The 16-frame controller queue ran dry about once a second; the 64-frame queue and sending once two blocks are buffered fixed it. A 16-frame queue and a starved half-rate stream stuttered in their harness, so it detects dropouts. With the 64-frame queue, 1024- and 2048-frame ports felt continuous across a 60–400 Hz sweep and in 0.5 s pulses, while they still sent in bursts.

  • No title. I don't have a title known to use vibration ports (e.g. PPSA21564), so this hasn't been heard on one. A run on such a title over Bluetooth would be welcome.

  • Rumble, this head. The harness played a 150 Hz haptic tone in four 3 s phases while calling scePadSetVibration on a pad opened with scePadOpen and driving PadInput::Update: haptics alone, haptics with rumble at 128/128, haptics alone again, rumble alone. Felt strength of phase 3 against phase 1, one person holding the controller:

    Build Phase 3 against phase 1
    second commit (no configuration resend), two runs weaker; changed
    same build, rumble value 0 throughout (control) same
    configuration report resent 100 ms after the rumble stops: local experiment, one run; this head, one run same

    This is felt, not measured with an instrument.

  • ctest -V -R '^(audio_out|pad_|dualsense)' with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1: 51/51 on this head, 50/50 on main 3d2b7c0673 (dualsense_haptics is new). With the DualSense switched on, pad_sdl aborts on this head because the real controller takes slot 0 ahead of the test's virtual controllers; the test is unchanged by this PR, and it passes with SDL_GAMECONTROLLER_IGNORE_DEVICES=0x054c/0x0ce6. No VUID- lines and no was not found but was requested by env var VK_INSTANCE_LAYERS in either log.

  • tools/check_conventions.py --base origin/main passes.

  • tools/pr_overlap.py finds #10112, which adds the DualSense trigger-state read and overlaps in PadInput, PadInput.hpp, the VideoOut test registration and the VideoOut debt file. The agreed order on #10112 is this PR first.

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 (#2032, which drops vibration ports from the main mix over Bluetooth, is on main)
  • Fixes: #2056
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4952765162 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9154). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-21T13:55:08Z. --- ### What #2056: over Bluetooth a DualSense has no sound card, so vibration ports reach it only as motor rumble (#7633). The DualSense takes haptics audio in HID output report 0x32. This PR streams the vibration ports there when the controller is connected over Bluetooth. The report layout, CRC and configuration report follow beecrepaldi-afk's P5M implementation (`gui/src/macDualSenseBluetooth.mm`), offered under GPL-2.0 on #2056, and the commit carries their authorship. The structure is the one MarcZX10 and oneandonlydean described there. - **Owner.** `PadInput`, which owns the SDL controller, decides when to stream. It streams for a PS5 controller whose HID path enumerates with `interface_number` -1, which is Bluetooth; a USB DualSense has interface 3. It opens a second, shared handle with `SDL_hid_open_path`, sends one report 0x31 (motor power reduction 0, haptics low-pass on, only `valid_flag1` bits), then runs its own pacing thread. It sends one 32-frame block as a report 0x32 once two blocks are buffered, at most one report per 10.67 ms (one block at 3 kHz). It waits on a deadline with `PreciseSleepUntil`, so a backlog drains one report per interval rather than back to back, and a report after a pause goes out at once without a catch-up burst. During silence nothing is sent: blocks of all-zero samples are skipped. - **Audio side.** `AudioOut2` (with no pad sound card) and the legacy `sceAudioOut` vibration port hand their two vibration channels to `PadSubmitHapticFrames` while the stream is open. Otherwise they make motor rumble, as on `main`. `libScePad`'s `PadHapticBuffer` averages them down to 3 kHz 8-bit stereo in 16-frame boxes and keeps the newest 160 frames (53 ms) for the thread. - **Failure.** There is no environment switch. A failed `SDL_hid_write` logs once and stops the stream until the controller reconnects. The stream-open flag stays set until then, so both audio paths keep handing the vibration ports to the stopped stream (whose buffer keeps only its newest 160 frames) and never turn them into motor rumble. When slot 0's controller closes, the flag clears, and a reconnect opens a new stream. - **Reports.** `DualSenseHaptics::Report` and `PowerReport` build the 0x32 and 0x31 reports. The new `dualsense_haptics` test checks both byte for byte, including the CRC32 over `0xA2` plus the report, computed independently with Python's `zlib.crc32`. It also checks the buffer's 48 kHz and 44.1 kHz downsampling, block taking and overflow, and the report deadlines (`DualSenseHaptics::NextReport`): the 10.67 ms interval, the spacing of buffered reports and no burst after a pause. With the `0xA2` seed removed it fails: `report byte 138 is 0xca, expected 0xe2`. - **Rumble.** A title's `scePadSetVibration` rumble still goes out through SDL's report 0x31, which sets the bit that turns audio haptics off. Once slot 0's rumble stops, the stream thread sends its own configuration report 0x31 again after 100 ms, giving SDL's asynchronous rumble-off report time to go first. Without it the haptics came back at a different strength after a rumble (third commit; measured below). - **Strength.** `ANYPS5_RUMBLE` (#12686) scales the streamed samples the same way it scales the pad sound card's, so `0` keeps a Bluetooth DualSense silent. - **Debt.** `docs/dev/debt/libSceVideoOut.md` records the box filter, the paced sending rate, the rumble interplay on a title, and the stop on a failed write. **Ports (after #7881).** The stream follows port 0, like the vibration ports' motor rumble on `main`. It opens when a controller takes slot 0 and closes when slot 0's controller closes. The haptic buffer stays process-wide, next to the per-port pad slots. ### Tested - **Rebased onto `main` `409fe64199`, head `64a2841b83`.** `dualsense_haptics` now also checks the stream at 100, 50 and 0 percent. It passes, as do the pad, haptics and audio-out tests built for this head (71 of them, including `pad_rumble_intensity` and `audio_out2_pad_haptic_intensity`), on Windows 11 26300, WinLibs GCC 15.2.0, Release. Windows 11 26300, WinLibs GCC 15.2.0, Release. DualSense over Bluetooth; feature report 0x20 gives firmware 0x010d0002, update version 0x0633, hardware 0x00000917, build Sep 18 2025. Head `f0da5c4877`, on `main` `3d2b7c0673`. - **End to end over Bluetooth, this head.** A harness outside the tree links this build's `libSceVideoOut`, `libSceAudioOut` and `libScePad`. It creates a `PadInput`, opens a legacy vibration port (`sceAudioOutOpen` type 10, 48 kHz, s16 stereo) and outputs a 150 Hz sine at 0.8, 3 s on channel 0 only, then 3 s on channel 1 only. It was run with 256-, 1024- and 2048-frame ports; before this revision the larger two sent their blocks back to back. In all three the haptics were felt continuous, left then right, and no write failed. - **Pacing, measured.** A local, uncommitted timing log in the stream thread (not part of this PR) recorded each report's deadline, write start and write end, about 560 reports per run: | Port | Gap between write starts | Start after its deadline (max) | Write time (mean / max) | |---|---|---|---| | 256 frames | 9.92–11.30 ms | 0.75 ms | 0.11 / 0.27 ms | | 1024 frames | 7.81–13.45 ms | 2.91 ms | 0.11 / 0.50 ms | | 2048 frames | 9.12–12.21 ms | 1.55 ms | 0.12 / 0.48 ms | The first attempt waited with `std::this_thread::sleep_until`. On this host it overslept by up to 13 ms, so a third of the gaps were above 13 ms and another third below 9.5 ms, down to 0.1 ms, where the next late report went straight out. `PreciseSleepUntil` from `libc/include/PreciseWait.hpp`, already used in `VideoOutDriver.cpp`, fixed that; the table is with it. - **Write failure, this head.** The same harness played channel 0 for 120 s and the controller was switched off during it. The write failed after about 1400 reports and logged once: `Pad: a Bluetooth DualSense haptics report failed (…); haptics stop until the controller reconnects`. Writes up to then were 9.66–11.67 ms apart. The port kept playing to the end: `PadHapticStreamOpen` stayed true, and the largest `audioVibrationLarge`/`audioVibrationSmall` that `PadFetchOutputForPort(0)` returned during the whole run was 0, so the vibration audio did not turn into motor rumble. - **Earlier rounds, by @seradavid** on an RX 9070 XT host with a Bluetooth DualSense ([comment](https://github.com/boykopovar/AnyPS5/pull/9154#issuecomment-6360283262)). The 16-frame controller queue ran dry about once a second; the 64-frame queue and sending once two blocks are buffered fixed it. A 16-frame queue and a starved half-rate stream stuttered in their harness, so it detects dropouts. With the 64-frame queue, 1024- and 2048-frame ports felt continuous across a 60–400 Hz sweep and in 0.5 s pulses, while they still sent in bursts. - **No title.** I don't have a title known to use vibration ports (e.g. PPSA21564), so this hasn't been heard on one. A run on such a title over Bluetooth would be welcome. - **Rumble, this head.** The harness played a 150 Hz haptic tone in four 3 s phases while calling `scePadSetVibration` on a pad opened with `scePadOpen` and driving `PadInput::Update`: haptics alone, haptics with rumble at 128/128, haptics alone again, rumble alone. Felt strength of phase 3 against phase 1, one person holding the controller: | Build | Phase 3 against phase 1 | |---|---| | second commit (no configuration resend), two runs | weaker; changed | | same build, rumble value 0 throughout (control) | same | | configuration report resent 100 ms after the rumble stops: local experiment, one run; this head, one run | same | This is felt, not measured with an instrument. - `ctest -V -R '^(audio_out|pad_|dualsense)'` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`: 51/51 on this head, 50/50 on `main` `3d2b7c0673` (`dualsense_haptics` is new). With the DualSense switched on, `pad_sdl` aborts on this head because the real controller takes slot 0 ahead of the test's virtual controllers; the test is unchanged by this PR, and it passes with `SDL_GAMECONTROLLER_IGNORE_DEVICES=0x054c/0x0ce6`. No `VUID-` lines and no `was not found but was requested by env var VK_INSTANCE_LAYERS` in either log. - `tools/check_conventions.py --base origin/main` passes. - `tools/pr_overlap.py` finds #10112, which adds the DualSense trigger-state read and overlaps in `PadInput`, `PadInput.hpp`, the VideoOut test registration and the VideoOut debt file. The agreed order on #10112 is this PR first. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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: none (#2032, which drops vibration ports from the main mix over Bluetooth, is on `main`) - [x] Fixes: #2056 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
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!9154
No description provided.