feat(pad): stream vibration ports to a Bluetooth DualSense as haptics reports #9154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9154"
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 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.PadInput, which owns the SDL controller, decides when to stream. It streams for a PS5 controller whose HID path enumerates withinterface_number-1, which is Bluetooth; a USB DualSense has interface 3. It opens a second, shared handle withSDL_hid_open_path, sends one report 0x31 (motor power reduction 0, haptics low-pass on, onlyvalid_flag1bits), 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 withPreciseSleepUntil, 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.AudioOut2(with no pad sound card) and the legacysceAudioOutvibration port hand their two vibration channels toPadSubmitHapticFrameswhile the stream is open. Otherwise they make motor rumble, as onmain.libScePad'sPadHapticBufferaverages them down to 3 kHz 8-bit stereo in 16-frame boxes and keeps the newest 160 frames (53 ms) for the thread.SDL_hid_writelogs 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.DualSenseHaptics::ReportandPowerReportbuild the 0x32 and 0x31 reports. The newdualsense_hapticstest checks both byte for byte, including the CRC32 over0xA2plus the report, computed independently with Python'szlib.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 the0xA2seed removed it fails:report byte 138 is 0xca, expected 0xe2.scePadSetVibrationrumble 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).ANYPS5_RUMBLE(#12686) scales the streamed samples the same way it scales the pad sound card's, so0keeps a Bluetooth DualSense silent.docs/dev/debt/libSceVideoOut.mdrecords 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
main409fe64199, head64a2841b83.dualsense_hapticsnow 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, includingpad_rumble_intensityandaudio_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, onmain3d2b7c0673.End to end over Bluetooth, this head. A harness outside the tree links this build's
libSceVideoOut,libSceAudioOutandlibScePad. It creates aPadInput, opens a legacy vibration port (sceAudioOutOpentype 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:
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.PreciseSleepUntilfromlibc/include/PreciseWait.hpp, already used inVideoOutDriver.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:PadHapticStreamOpenstayed true, and the largestaudioVibrationLarge/audioVibrationSmallthatPadFetchOutputForPort(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
scePadSetVibrationon a pad opened withscePadOpenand drivingPadInput::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:This is felt, not measured with an instrument.
ctest -V -R '^(audio_out|pad_|dualsense)'withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1: 51/51 on this head, 50/50 onmain3d2b7c0673(dualsense_hapticsis new). With the DualSense switched on,pad_sdlaborts 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 withSDL_GAMECONTROLLER_IGNORE_DEVICES=0x054c/0x0ce6. NoVUID-lines and nowas not found but was requested by env var VK_INSTANCE_LAYERSin either log.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pyfinds #10112, which adds the DualSense trigger-state read and overlaps inPadInput,PadInput.hpp, the VideoOut test registration and the VideoOut debt file. The agreed order on #10112 is this PR first.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)main)