Skip to content

About

Real-time haptic feedback for Windows audio using Xbox controllers.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

HapticSync

HapticSync is a small Windows Python script that turns audio volume into vibration on an XInput-compatible controller. It measures the audio's root mean square (RMS) level and sends the same vibration strength to both controller motors.

Requirements

  • Windows with xinput1_4.dll or xinput1_3.dll available.
  • Python 3 with pip.
  • An XInput-compatible controller with vibration support, connected as controller index 0.
  • An audio input accessible through SoundCard, ideally a loopback input for your playback device.
  • The Python packages soundcard and numpy.

The script uses Windows XInput through ctypes.windll, so it does not run unchanged on macOS or Linux.

Setup

Clone this repository, or download and extract it from GitHub. If you use Git:

git clone https://github.com/aaka3h/HapticSync.git
cd HapticSync

In PowerShell, from the project folder, create a virtual environment and install the dependencies:

py -m venv .venv
.\.venv\Scripts\python.exe -m pip install soundcard numpy

If the py launcher is unavailable, use python -m venv .venv instead.

Run

  1. Connect your controller and choose the Windows playback device you want to monitor.

  2. Start the script:

    .\.venv\Scripts\python.exe HapticSync.py
  3. Check the printed Targeting Speaker and Listening to device names, then play audio.

  4. Press Ctrl+C to stop. The script sends a zero-vibration command when interrupted inside its recording loop.

Audio input selection

The script searches for a loopback input whose name contains the default speaker's name. If it cannot find a match, it uses the first input returned by SoundCard. That fallback may be a microphone rather than a loopback input, so check the Listening to line before relying on the result.

Adjust vibration

The current settings are in HapticSync.py; there are no command-line options.

Setting Current value Effect
Sample rate 44100 Hz Requested recording rate
Frames per read 512 Number of audio frames processed per iteration
multiplier 600000 Scales RMS audio level into motor strength
Noise cutoff 3000 Scaled motor values below this become zero
Maximum motor value 65535 Caps the vibration command
Controller index 0 Chooses the first XInput controller slot

Increase multiplier for stronger vibration or decrease it for weaker vibration. This responds to overall audio level; it does not isolate bass, detect beats, or control the two motors independently.

Troubleshooting

  • No vibration: Confirm the controller supports XInput vibration and occupies index 0. The script does not check XInput return codes, so a missing controller may produce no error.
  • Wrong sound triggers vibration: Check the selected input name. The fallback can select a microphone; review get_loopback() if you need a specific input.
  • No input found: Check that Windows exposes your playback device and an appropriate recording or loopback input.
  • XInput DLL error: The script tries xinput1_4 first and then xinput1_3; one must be available on your Windows installation.
  • Recording error: Check the selected audio device and whether it accepts the requested sample rate.

About

Real-time haptic feedback for Windows audio using Xbox controllers.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages