diff options
| author | liamwhite <liamwhite@users.noreply.github.com> | 2024-02-25 14:00:59 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-25 14:00:59 -0500 |
| commit | 02b3a505649e5a60bb226f826d6dbd701b391a0c (patch) | |
| tree | 3ef0a2763194a01147b9f3e134efeaee8dc41b5b /src/hid_core/frontend/emulated_controller.cpp | |
| parent | d8ca5402b5b4a549834e6d6d5e49f802fdd59176 (diff) | |
| parent | bdd95714d5c0e9e836f7ad6bfe7f152e46a4a857 (diff) | |
Merge pull request #13154 from german77/vibration-filter
core: hid: Reintroduce vibration filter
Diffstat (limited to 'src/hid_core/frontend/emulated_controller.cpp')
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 5cd26819cc..7664341bd5 100644 --- a/src/hid_core/frontend/emulated_controller.cpp +++ b/src/hid_core/frontend/emulated_controller.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include <algorithm> +#include <chrono> #include <common/scope_exit.h> #include "common/polyfill_ranges.h" @@ -1287,6 +1288,22 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV return false; } + if (!Settings::values.enable_accurate_vibrations.GetValue()) { + using std::chrono::duration_cast; + using std::chrono::milliseconds; + using std::chrono::steady_clock; + + const auto now = steady_clock::now(); + + // Filter out non-zero vibrations that are within 15ms of each other. + if ((vibration.low_amplitude != 0.0f || vibration.high_amplitude != 0.0f) && + duration_cast<milliseconds>(now - last_vibration_timepoint[index]) < milliseconds(15)) { + return false; + } + + last_vibration_timepoint[index] = now; + } + // Exponential amplification is too strong at low amplitudes. Switch to a linear // amplification if strength is set below 0.7f const Common::Input::VibrationAmplificationType type = |
