audio: play DualSense haptics from vibration audio ports #843
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!843
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/843/head"
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?
@Cosmo on GitHub · 2026-09-26 02:30 UTC · original
Cosmo:dualsense-audio-haptics→main· +588 −3 · 7 files · 3 commits · merged 2026-09-26 20:37 UTCSummary
PS5 games drive the DualSense's two voice-coil actuators through an audio output port of type
vibration (
sceAudioOutOpentype 10, AudioOut2 port type 6), one channel per actuator. These portshad no device, so their samples were dropped and games that rely on audio haptics instead of
scePadSetVibrationhad no vibration at all.Over USB, the DualSense is also a 4-channel USB audio device whose back channels feed the actuators.
This PR plays each vibration port's samples on those channels through SDL audio.
Changes
src/libs/padHaptics.{h,cpp}(new): finds the DualSense's audio device by name and requires 4channels, opens an SDL stream at the port's rate, converts each block (mono or stereo, s16 or float,
port volume) to
[0, 0, left, right]frames and queues them with about the same ~40 ms latency asthe regular audio path. The playback rate is nudged by up to 3% to keep that queue level when the
port is fed slightly off real time (a port without an SDL device is paced by a sleep timer, and the
controller's USB audio clock differs from the main output's). The device is looked up every 2 s
while the port plays, so the controller can be plugged in or out at any time; a device that fails
to open is skipped until it is reconnected, and the reason haptics are unavailable is logged once.
src/libs/audio.cpp: vibration ports use that stream instead of dropping their samples. It neverpaces the port, so the existing pacing of
AudioOutOutputsand AudioOut2 is unchanged. Queueingto it holds
Audio::m_mutex(it never waits for pacing), sosceAudioOutCloseon another threadcannot free the stream mid-queue.
src/libs/controller.{h,cpp}: remembers the lastscePadSetVibrationvalues. While haptic audioplays, a DualSense's rumble is held at 0 and restored 250 ms after the haptics fall silent. SDL's
PS5 driver sets the "disable audio haptics" flag whenever rumble is non-zero
(
SDL_hidapi_ps5.c), which would mute the actuators.tests/PadHapticsTests.cpp,CMakeLists.txt:pad_hapticstest for the sample conversion,device-name matching and playback-rate correction, added to
kyty_tests. The device handlingitself needs a real controller and is not covered.
Limitations and side effects
undocumented HID output report, which is not implemented. Over Bluetooth nothing changes (legacy
rumble as before).
the emulator plays nothing and logs why, since the OS would otherwise mix the actuator channels
into the controller's speaker. SDL reads the channel count when the device appears, so after
changing the setup the controller has to be reconnected.
gamepad to its audio device yet (libsdl-org/SDL#9197). With an Xbox pad active and a DualSense
plugged in by USB, the DualSense gets the haptics. Likewise, rumble is held off on the active
controller whenever it is a DualSense, even if the haptics play on a different one.
at once. A game that uses both at the same time loses the legacy rumble during haptics.
scePadSetVibrationModeis still a stub; not needed for this.counts there are untested.
Testing
pad_hapticsandaudio_out2_portpass;kyty_emulatorandlauncherbuild without warnings(clang-cl, Windows).
References
dse-haptics,
minimal WASAPI demo. Used for
the channel layout only; no code was taken from them.
3rdparty/SDL3for how rumble and audio haptics interact.dualsense-bt-haptics (MIT) were read for the
Bluetooth protocol only. Nothing from them is in this PR.
AI use
Research, implementation and tests were done with Claude Code at my direction.
I reviewed the code, and tested it as described above.
@coderabbitai[bot] on GitHub · 2026-09-26 02:38 UTC · original · edited 2026-09-26 12:43 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
The change adds DualSense audio haptics with audio-device discovery, sample conversion, playback queue management, and coordination with controller rumble. Vibration-port audio now routes through the haptics module, and controller code supplies the active controller ID and delegates supported rumble requests. A new test executable covers playback, discovery, failure handling, queue limits, rumble timing, and cleanup. CTest registers the executable and includes it in the aggregate test target.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Feature
Merge Risk: 🔵 Low · up to
275efSwitching controllers can make the previous pad vibrate again. The impact is localized, but the rumble-state fix should be made before merging.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
275efVibration audio can now reach a connected controller, but the selected audio device is not tied to the active controller. Controller shutdown also does not immediately close the haptic audio stream. Exposure appears limited to local connected devices; the behavior warrants review before relying on controller ownership to contain output.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 7.94% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 63 functions across 8 files. (1 skipped: 1 unsupported.)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-26 02:38 UTC · original
On
src/libs/padHaptics.cppline 304 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6761
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24868
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24703
Clear idle haptics when output stops.
PadHaptics::QueuechecksSTOP_MSonly whenAudioOutOutputsorAudioOutOutputsubmits another block. An open vibration port does not receive periodic queue calls, andAudioOutCloseis the only separate path that callsPadHaptics::Close. Therefore, a non-silent block can leavestream->playingset until the port closes.Controller::ApplyRumblethen keeps both rumble motors at zero whilem_audio_hapticsremains true. Add an independently synchronized idle timeout for eachStream, or an equivalent port-stop transition, that callsSetPlaying(stream, false)after 250 ms without output.@coderabbitai[bot] on GitHub · 2026-09-26 02:38 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
e08d46c0-e4ae-4e8a-8298-4ef7eaef8289📥 Commits
Reviewing files that changed from the base of the PR and between
fd2e15ee73andd007592878.📒 Files selected for processing (7)
CMakeLists.txtsrc/libs/audio.cppsrc/libs/controller.cppsrc/libs/controller.hsrc/libs/padHaptics.cppsrc/libs/padHaptics.htests/PadHapticsTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nmzik on GitHub · 2026-09-26 12:36 UTC · original
@Cosmo please retest. Implementation is simplified
@ -0,0 +48,4 @@g_large_motor = g_small_motor = 0;g_rumble_until = 0;}}@coderabbitai[bot] on GitHub · 2026-09-26 12:43 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Stop the old controller's rumble when you switch controllers.
SelectControllersetsg_haptics_until = 0and then callsApplyRumble()for the oldg_controller. It does not clearg_rumble_untilfirst. If the old pad had a rumble in progress,mutedis false, andApplyRumble()sends the oldg_large_motor/g_small_motorvalues again for the remaining time. This can be up to about 65 s.Here is how it happens:
Shutdown()does not have this problem, because it setsg_rumble_until = 0before it callsSelectController(-1).🐛 Proposed fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-09-26 12:43 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
8a3aa63f-d166-440c-95ef-259640269f27📥 Commits
Reviewing files that changed from the base of the PR and between
d007592878and275ef643fd.📒 Files selected for processing (7)
CMakeLists.txtsrc/libs/audio.cppsrc/libs/controller.cppsrc/libs/controller.hsrc/libs/dualSenseHaptics.cppsrc/libs/dualSenseHaptics.htests/PadHapticsTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Cosmo on GitHub · 2026-09-26 20:36 UTC · original
thanks and done -- works great!
@Rool-IO on GitHub · 2026-09-27 00:07 UTC · original
If I may, the Controller Speaker FX are still missing
@Cosmo on GitHub · 2026-09-27 07:32 UTC · original
Exactly! Thanks for pointing it out.
The DualSense makes sound in two ways. This PR drives the haptic actuators, which are voice coils, so you can hear them a little too (noticeable in Astro's Playroom for example).
The controller speaker is separate: Games send it their own audio stream, and it needs an extra command before it plays anything. That's not in this PR - I'm adding it in a follow-up once finished testing.
@Rool-IO on GitHub · 2026-09-27 09:01 UTC · original
Felt like mentioning it since Haptics & Speaker FX are always together in Astro (be it playroom or the full game).
Looking forward to this.